For almost 3 decades, Flash animators have struggled their way through shape-driven animations using the built-in “Shape Tweens.” But in 2012, two developers here at Intersect decided enough is enough: a new approach must be created to improve the capabilities of Flash. This is their story.
It started with a common request we get: do the impossible. At Intersect, being told to attempt some crazy concepts is just something we’ve become accustomed to. Plus, we just enjoy the challenge of pulling off the “impossible”. With this project, the concept was actually not beyond reason, but the constraints set by traffickers and the media plan weighed heavily on the possibility of success. The unit was to be a typical 40k banner served through MediaMind, with some not so typical (for 40k) shape morphing, 3D rotations, and particle effects. This combination of characteristics stacked up against the limited size of the banner. The MediaMind API in its simplest form adds 6k. Since the media specs required a Flash Player 9 build, 3D capabilities were not native and required the addition of 3rd-Party APIs to achieve the 3D rotations. Particle systems require heavy coding. But worst of all, the creative required the use of shape tweens for morphing animations.
The banner started the same as any other unit would. We went through the motions of creating what the client asked for and optimized it with all tricks we had up our sleeves. The result was a hefty 70k SWF that looked good, but clearly not ready for delivery. We knew that we needed a new approach, and it wasn’t gonna be simple.
The biggest obstacle was those massive shape tweens. They were contributing a majority of the file size. Our best option was to not use them at all, which meant creating a code-driven approach to animating shapes and a more efficient structure for storing that animation data. It was a pretty big undertaking, but we accomplished it and in three parts.
The Animation Platform
In order to begin creating a new type of animation, we needed an interface that would help us create them. We immediately got to work on a desktop application, and after a couple days (and nights) of heavy coding, we had a functional prototype that could draw and animate shapes on a vertex level, independent of framerate. We then polished up the interface and added tools for object instancing, shape rotation, and keyframe easing. Lastly, we added a background guide that synced the snap shots of the original banner animation within our new environment so we could match the old shape tweens with our new system.
With the tool ready to build the animation, we set out to create a way to get the animation from the development environment to the final Flash banner. We chose to store all the whole animation as JSON. Initially our JSON data was just too big to fit in our banner. So we decided that the only way to get file size down was to simplifying all our JSON into multidimensional Arrays rather than Objects. The structure resulted in 6-arrays-deep of values. To further optimize the data, we rounded values to even numbers and removed any redundant information. Finally, when completed, the data was added directly into an FLA so we could take advantage Flash’s SWF compression.
At Intersect, we’re huge fans of Greensock’s TweenLite and TweenNano. So it only made sense that our animation renderer would make use of it’s awesome features. The only problem was that one of Greensock’s classes, TimeLineLite, was just a bit too heavy for our 40k banner. So we gutted the features we didn’t need and made our own, very limited, TimeLineNano. Then we parsed our heavily optimized animation data, and turned that into timeline tweens that would play alongside all the other animations that took place in the banner.
So after a long battle with K-size, we packed up our animation data, our tiny 3d API, our particle system and the rest of the assets. We finally ran the banner and there it was, a unit that was 70k just days earlier in a petite package of 40k.
To showcase just how crazy default Flash shape tweens look, we made 2 similar animations of a rounded square widening and rotating. So here are 2 GIFs. On the top is how our animation system handles the animation. On the bottom is how Flash handles that same animation.