![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
Using ActionScript 2.0, you can create your own class that extends the behavior of the built-in MovieClip class, and then assign that class to a movie clip library symbol using the Linkage Properties dialog box. 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 Creating Classes with ActionScript 2.0.)
In a subclass of the MovieClip class, you can provide method definitions for the built-in MovieClip methods and event handlers, like 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.
// MoveRight class -- moves clip to the right 5 pixels every frame class MoveRight extends MovieClip { function onPress() { this._x += 20; } }
Ball
in the Name text box.MoveRight
in the AS 2.0 Class text box. Click OK.Each time you click the ball movie clip, it moves 20 pixels to the right.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |