Initializing class properties
379
3.
Enter the following code in your script file:
// MoveRight class -- moves clip to the right 20 pixels when clicked
class MoveRight extends MovieClip {
public function onPress() {
this._x += 20;
}
}
4.
Save the document as MoveRight.as in the BallTest directory.
To assign the class to a movie clip symbol:
1.
In Flash, select File > New, select Flash Document from the list of file types, and click OK.
2.
Using the Oval tool, draw a circle on the Stage.
3.
Select the circle, and select Modify > Convert to Symbol.
4.
In the Convert to Symbol dialog box, select Movie Clip as the symbol’s behavior, and enter
ball_mc
in the Name text box.
5.
Select Advanced to show the options for Linkage, if they aren’t already showing.
6.
Select the Export for ActionScript option, and type
MoveRight
in the Class text box. Click
OK.
7.
Save the file as ball.fla in the BallTest directory (the same directory that contains the
MoveRight.as file).
8.
Test the Flash document(Control > Test Movie).
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.
Initializing class properties
In the example presented in the second procedure under
“Assigning a class to a movie clip
symbol”
, you added the instance of the Ball symbol to the Stage while authoring. As discussed
in
“Adding parameters to dynamically created movie clips” on page 364
, you can assign
parameters to clips you create at runtime by using the
initObject
parameter of
attachMovie()
and
duplicateMovie()
. You can use this feature to initialize properties of
the class you’re assigning to a movie clip.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...