Flash Animation StarTrix
Flash 6 (or Mx) has made available a lot of programming tricks for Flash developers so that they can quickly create quite diverse animations. Twinkle is an example. It allows users to scatter a movieclip all over the stage semi-randomly. We say "semi-randomly" because the position and size of the duplicate copies of the starting clip are completely randomly generated; the alpha or transparency value of each duplicate depends on its relative size to the original. The ruke is simple: the smaller the duplicate the dimmer or more transparent; the larger the duplicate, the brighter and higher its alpha value.
This is a frequent animation trick. Have some property of the animation determined by random generator or user input but then use those properties to determine the rest of the behaviour of the animation. What makes that even easier to do in Flash Mx is of course ActionScript.
So a designer can spend extra time on the form/styling of objects knowing that when it comes to animating them there will be many options available. Not just the shape and motion tweens but programmatic animations that can be extensively customized. Its this latter, programmed approach on demo here.
The coding is quite simple. A routine called randupe() will receive a movieclip
and randomely generate a copy of the clip of random size and position on the
stage - but not random brightness. The brightness or transparency of the copied
clip will be relative to its size. randupe() will be triggered to do this
400 times, once every 35 milliseconds, and on 120 levels of the stage by the
setInterval() routine. The trick is to turn off the duplication after 800
times. The code is below.
There are three tricks in this code worth underlining. First, in the statement
blob.count=0; we are taking advantage of the fact that movieclips
are predefined objects in ActionScript. ActionScript also allows us to add
a property to an object by simply making an assignment. This is in turn allows
a current count of the number of duplicates made, the count property,
to be passed along into the function randupe() - two birds with one parameter.
But also, a scalar parameter which normally is passed by value (and therefore
cannot be changed in the function); now is passed by reference and therefore
can be changed inside the function randupe(). Nifty.
Think of setInterval() as being a onEnterFrame event in which you can control the time between events.The whole trick is to turn off the infinite loop of function calls. And ActionScript provides a complimentary function, clearInterval(), to do that. The following code triggers and then immediately turns off the setInterval() trigger:
intervalId=setInterval(trace, 100, "This message will never be seen");
mclip.duplicateMovieClip("mcd"+i, (i % maxlev) + 2, mcdupe)
The first leger de main is in the new clipname, "mcd"+i
. ActionScript has no problem putting the string and integre to form the name
"mcd1", etc. Next, (i % maxlev) + 2 , starts the levels
at 3 and cycles up to maxlev+ 2 - if times is still not done then
the modulo math starts everything over at level 3 - causing the the existing
clip on that level to wink out as it is overwritten by the newly duplicated
clip. Finally all the parmeters set for mcdupe are passed onto "mcd1"...
by the duplicateMovieClip function.
Top of Page Tutorials Home Flash References
© Imagenation 2001-2004