EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 380

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
380 Working with Movie Clips
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 378). The difference is a new
property named
distance, whose value determines how many pixels a movie clip moves each
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
ball50_mc, moves 50 pixels each time it is clicked; the second,
named
ball125_mc, moves 125 pixels each time it is clicked.
10. Select Control > Test Movie to test the SWF file.

Table of Contents

Related product manuals