1. Home
  2. Computing & Technology
  3. Animation

Dynamic Animation in Flash: Controlling the Drawing API with Equations

By Adrien-Luc Sanders, About.com

5 of 6

So how does that code become that tangle of lines? Let’s take a look at the two separate onClipEvent handlers. First, the onClipEvent(load):
onClipEvent(load) {
xstart=Math.random()*300;
ystart=Math.random()*300;
_root.createEmptyMovieClip ("twisty", 1);
_root.twisty.lineStyle (1, 0x5566FF, 40);
_root.twisty.moveTo (xstart, ystart);

Once the movie loads (and the movie clip with it), this creates two variables (xstart and ystart) with random numbers assigned to them using Math.random to generate a random number between 0.0 and 1.0, then multiplying it times 300 (both the width and height of my clip). These variables represent the starting coordinates of my dynamic drawing.

Then createEmptyMovieClip is used to create an empty movie clip to act as a container for the drawing, with an instance name of “twisty” and a depth of 1 (one layer above the base depth of 0).

Lastly, lineStyle is used to define the drawing style of the dynamic drawing as a one pixel line, medium blue (hex code 5566FF), 40% opacity. moveTo is then used to move the starting point of the drawing to the values defined by xstart and ytart.

Explore Animation
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Animation

©2009 About.com, a part of The New York Times Company.

All rights reserved.