MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 380

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

For example, the following class named MoveRightDistance is a variation of the MoveRight
class (see
"Assigning a class to a movie clip symbol" on page
property named
distance
time it is clicked.
To pass arguments to a custom class:
1.
Create a new ActionScript document and save it as MoveRightDistance.as.
2.
Type the following ActionScript into the Script window:
// MoveRightDistance class -- moves clip to the right 5 pixels every
frame.
class MoveRightDistance extends MovieClip {
// Distance property determines how many
// pixels to move clip for each mouse press.
var distance:Number;
function onPress() {
this._x += this.distance;
}
}
3.
Save your progress.
4.
Create a new Flash document, and save it as MoveRightDistance.fla in the same directory
as the class file.
5.
Create a movie clip symbol that contains a vector shape, such as an oval, and then delete
any content from the Stage.
You only need a movie clip symbol in the library for this example.
6.
In the Library panel, right-click (Windows) or Control-click (Macintosh) the symbol and
select Linkage from the context menu.
7.
Assign the linkage identifier Ball to the symbol.
8.
Type MoveRightDistance into the AS 2.0 Class text box.
9.
Add the following code to Frame 1 of the Timeline:
this.attachMovie("Ball", "ball50_mc", 10, {distance:50});
this.attachMovie("Ball", "ball125_mc", 20, {distance:125});
This code creates two new instances of the symbol on the root timeline of the SWF file.
The first instance, named
named
ball125_mc
10.
Select Control > Test Movie to test the SWF file.
380
Working with Movie Clips
, whose value determines how many pixels a movie clip moves each
, moves 50 pixels each time it is clicked; the second,
ball50_mc
, moves 125 pixels each time it is clicked.
378). The difference is a new

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

This manual is also suitable for:

Flash 8

Table of Contents