Some Comments on the Container class

1. If you're not familiar with the native MovieClip class method attachmovie(), you should take a few minutes now to read through the Flash documentation.

2. I'm using a somewhat complicated call to attachmovie() to give you an example of it's many features, such as:

1st) Passing values to the constructor of a "Ring" class instance: The Ring class (as you'll see in a moment) has a constructor that expects values for 4 of its native MovieClip properties, i.e., its size: (_xscale, _yscale), and its position within the "Container clip" on the stage: (_x, & _y). I've created an object, "ringConstructorParameters" to hold these values. It is passed to a "Ring" class instance's constructor by making it the 4th argument in the call to attachmovie(). (Note: that this forth argument is optional).
This way of setting (initial) "Ring clip" properties looks a bit weird: you need to specify both the name of the native MovieClip property (e.g., _xscale) and its value.

2nd) Three VERY important things happen during the run-time execution of the call to attachmovie():

1) A "Ring clip" instance is created within the "Container clip" that is on the stage.

2) When a "Ring clip" instance is created, an 'instance' of the "Ring" class is also created
(this is known as 'class instantiation'), i.e., the "Ring" class constructor is called and
accepts the property:value list in the generic object specified as 4th argument in the call to
to attachmovie().

3) When the "Ring clip" instance is created, attachmovie() returns a reference to the
"Ring" class instance. That reference is used to call an init() method of the "Ring"
class instance. This call to init() simply passes values for other animation parameters
in the "Ring" class

So let's sum up: An 'instance' of the "Container clip" library object is on the stage. When the movie starts, an 'instance' of its class ("Container") is automatically created. The constructor of the "Container" class automatically runs and it calls a run() method that starts the entire system. The "Container clip" instance does this by creating and then attaching instances of the "Ring clip" movie clip to itself. Each time the run() method creates a "Ring clip" instance, a corresponding instance of the "Ring" class is created that is used to extend the functionality of that "Ring clip" instance.

Now let's take a look at the constructor for the "Ring" class:

//  Method Desciption: MovieClip properties set through this constructor
// (see calling instantiation code in first frame of main movie).
//  Arguments:
//  (_xscale,_yscale) - initial scaling factors
//  (_x,_y) - initial movie clip position on main stage
//
//   NOTE: the constructor seems to only accept movieClip variables,
//   BUT only implicitly, i.e, there's no argument signature
//    in the function parameter list . . . ? Attempts to
//    insert a parameter list screws everything up.
public function Ring(){
 startRadius = _xscale;
 xPosition0 = _x;
 yPosition0 = _y;
 mathToolKit = new MathToolKit(); // objects must be instanciated in constructors
}

The only thing to note here is how the constructor accepts the MovieClip property:value list from the "ringConstructorParameters"object defined in the "Container" class.

So how does the "Ring" class instance animate the properties of its associated "Ring clip" instance? A "Ring clip" instance will increase or decrease to a final size before it completely (or almost completely) fades out. Once the "Ring clip" instances reaches its final size, it "dies" (i.e., the MovieClip instance property _visible is set to 'false'). The "Ring" class will change the _xscale, _yscale, & _alpha properties of the "Ring clip" instance in discrete steps. This is controlled by the native MovieClip method onEnterFrame():

// Method Description: This method overwrites the native MovieClip method. It is
// called at the frame rate of the main movie timeline. Will each call,
// it will change the properties of an instance of the Ring class.
// Arguments: none.
//
private function onEnterFrame():Void {
        if ( render ) {
                setSize(); // step increase or decrease
                setAlpha();
        }
        else { // the ring is dead, so just wait the required number of
                // frames before bringing it back to life
                cntFrames++;
                if ( cntFrames == waitFrames ){ render = true;
                        // start rendering cntFrames = 0;
                        // reset counter _visible = true;
                        // make ring visible
                }
        }
}

At this point, I'll simply describe the functions of the "Ring" class ? for details, please consult the source code.

At the frame rate of the main movie, onEnterFrame() calls setSize() to change the size of the ring. The onEnterFrame() method then calls setAlpha() to increase the level of transparency of the ring. The level of transparency at any point during the life of the ring is a function of the percentage difference between the final ring size and whatever the size the ring happens to have at that point.

The method setSize() detects when the ring has reached it's final size. It then calls a method, resetParameters(), that randomly assigns a new set of starting animation values for the "Ring clip" instance. It also assigns a random number of frames to the class variable "waitFrames," where "waitFrames" is the number of frames to wait before bringing the ring back to life (with it's new starting animation values).

In sum then, an instance of the "Ring" class makes dynamic the scale and alpha properties of its associated "Ring clip" instance. It does this by calling the (over-ridden) native MovieClip method onEnterFrame(). When the "Ring clip" instance reaches its final size, resetParameters() makes it invisible (i.e., _visible = false) and assigns new starting values to its animation parameters, i.e., _xscale, _yscale, & _alpha. The "Ring" class then waits a random number of frames before making the "Ring clip" instance visible.

One final note about "stochastic behavior" & the MathToolKit class: introducing random variables into models and animations is an advanced topic, so I won't go into any details here. However, if you build your animations with a certain amount of stochastic (i.e., random) behavior, you can make the animation more 'nuanced' by drawing your random variables from other known probability distributions rather than the usual, boring 'uniformed' distribution that Math.random() gives you. In this application, I generated the step sizes and wait times from simple normal distributions that differed only in terms of their means and standard deviations.