Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Working with Movie Clips > Assigning a class to a movie clip symbol | |||
Using ActionScript 2.0, you can create a class that extends the behavior of the built-in MovieClip class and then use the Linkage Properties dialog box to assign that class to a movie clip library symbol. Whenever you create an instance of the movie clip to which the class is assigned, it assumes the properties and behaviors defined by the class assigned to it. (For more information about ActionScript 2.0, see Example: Writing custom classes.)
In a subclass of the MovieClip class, you can provide method definitions for the built-in MovieClip methods and event handlers, such as onEnterFrame and onRelease. In the following procedure, you'll create a class called MoveRight that extends the MovieClip class; MoveRight defines an onPress handler that moves the clip 20 pixels to the right whenever the user clicks the movie clip. In the second procedure, you'll create a movie clip symbol in a new Flash (FLA) document and assign the MoveRight class to that symbol.
To create a movie clip subclass:
// MoveRight class -- moves clip to the right when clicked
class MoveRight extends MovieClip {
public function onPress() {
this._x += 20;
}
}
To assign the class to a movie clip symbol:Each time you click the ball movie clip, it moves 20 pixels to the right.
If you create component properties for a class and want a movie clip to inherit those component properties, you need to take an additional step: with the movie clip symbol selected in the Library panel, select Component Definition from the Library pop-up menu and enter the new class name in the Class box.
|
|
|
|