Contents /
Previous /
Next
Connecting Movie Clips in _root to AS Classes
AS classes, derived from the
movieClip class,
can be used to govern the behavior and
appearance of movie clips on the stage.
The AS class can:
-
define method handlers for movie clip events,
-
manipulate
movie clip properties, such as _alpha.
Instances of a AS movieClip class are per default
not connected to any clip on the stage.
Also instantiating a movieClip subclass
does not create a clip on stage (in the _root hierarchy).
There are two ways to create a movieClip on stage
and connect it to an AS class.
1) Connect a Symbol from the Library to an AS Class
A movie clip template existing as
symbol in the library
can be connected to an AS class
with its linked identifier.
This is called "registering":
Afterwards the AS class
and its event handlers are automatically associated with every
instance of the movie clip.
When a symbol is placed on the stage an
instance of the movie clip
is created as well as an
instance of the connected AS class.
2) Load the Movie Clip from an SWF File and Connect "by hand"
A movie clip subclass (derived from the MovieClip class)
can be associated with a movie clip on the stage
via the _prototype attribute:
class Ball extends MovieClip
{
function Ball()
{
_root.createEmptyMovieClip( "ball", 100 );
this.prototype = _root["ball"];
}
}
The "ball" can be loaded directly in the AS class from an SWF file:
var mcl:MovieClipLoader = new MovieClipLoader();
mcl.loadClip( "ball.swf", _root["ball"] );