I managed to get round to updating the Leaves animation I did last summer with a few bits and pieces. The Actionscript is not particularly pretty, as it was, like these little forays into the unknown are, akin to reaching around in a pitch black room for correct-coloured pieces of lego.
I’m very new to Actionscript, my knowledge consisting of some lynda.com videos (which I would highly recommend) and a bit of curiosity of the animation class library.
The way the lynda videos are structured means that you can use them as a sequential series of videos that help you understand from the ground up, or you can dip in and out using them as a reference. Very useful.
The key problem with the first version of this animation was the stalling of motion, which occurred at any time, but particularly when there are lots of instances of the animated figure on stage. The solution was actually found in the comments at the bottom of the Tween class descriptor .
The issue was caused by Flash trying to tidy up midway through the animation, and stopping the tween function midway through. This was defeated by putting all elements into a garbage collection array(of type dictionary) when they’re created, which is declared prior to the animation function. This system then transfers control to the developer. Each Tween function has an appended listener to check if the Tween has finished, and calls a function that clears out that Tween from the array.
Sweet. You can now add upwards of 100 leaves to the stage(though your CPU might not thank you) at once without it throwing any kind of wobbly.
Leaves with amount selector
I’ve structured the first version so that the user can define how many leaves they want to dynamically add to the stage. Enter a number and click add.
The second version uses the flash timer class, in particular the utils.Timer and events.TimerEvent classes, to add a small amount of leaves(1-5) to the stage every 2 seconds.
Let me know if you want the source code. simon “at” robertsportfolio.com