Animating Dynamic MovieClips - Page 4
       by kirupa  |  30 August 2006

In the previous page, we started to take a look at the code. There is more code that needs explaining, so let's continue from where we left off!


var scale:Number = 50+Math.random()*100;

The scale value stores a number by which our circles will be scaled by. I am using Math.random() to generate a random number between 50 and 150. Given the range of numbers that could be generated, it means our circles might be smaller (down to 50%) or larger (up to 150%) than their default size.


count++;

The count variable we declared earlier is incremented by one. Nothing tricky to look at with this particular line.


this.attachMovie("blueCircle", "blue"+count, 10000+count, {_x:xPos, _y:yPos, _alpha:10+Math.random()*40, _xscale:scale, _yscale:scale});

This is the important line that takes the blueCircle movie clip from our library and places it on our stage. Let's look at it in greater detail. The attachMovie function takes the following four arguments:

  • ID Value
    The ID Value is the Linkage Identifier of the movie clip you have declared in your Library. For our case, the linkage identifier of our movie clip is blueCircle.
  • New Name
    When attaching many movie clips to the stage, giving each movie clip a unique name makes it easier to refer to them. In this argument, you can specify a string - or an expression that evaluates to a string - that will be set as the new movie clip's name.
  • Depth
    All objects placed on the stage have a depth value associated with them, and you can not have two objects occupying the same depth. Your goal is to try to specify a unique depth for each movie clip, and as I will explain later, you can use your own method at ensuring a unique depth or use one of Macromedia's built-in get-depth functions.
  • Initial Object Properties (Optional)
    Designated by the curly braces { and },  you manually assign the various properties that the movie clip class allows to be altered. While outside the scope of this tutorial, if your movie clip has nested variables, you can alter their values from this argument also. You are not limited to changing the default properties found in the MovieClip class.

You should have a basic idea of how attachMovie works. Let's see how it works in our code in the next page!

Onwards to the next page!

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8




SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple.