Initializing Class Properties - MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual

Actionscript reference guide
Hide thumbs Also See for FLASH MX 2004 - ACTIONSCRIPT:
Table of Contents

Advertisement

Initializing class properties

In the example presented earlier, you added the instance of the Ball symbol to the Stage
manually—that is, while authoring. As discussed previously (see
dynamically created movie clips" on page
runtime using the
use this feature to initialize properties of the class you're assigning to a movie clip.
For example, the following class named MoveRightDistance is a variation of the MoveRight class
discussed earlier (see
new property named
each time it is clicked.
// MoveRightDistance class -- moves clip to the right 5 pixels every frame
class MoveRightDistance extends MovieClip {
// distance property determines how many
// pixels to move clip each mouse press
var distance:Number;
function onPress() {
this._x += distance;
}
}
Assuming this class is assigned to a symbol with a linkage identifier of Ball, the following code
creates two new instances of the symbol on the root Timeline of the SWF file. The first instance,
named
, moves 50 pixels each time it is clicked; the second, named
ball_50
pixels each time its clicked.
_root.attachMovie("Ball", "ball_50", 10, {distance:50});
_root.attachMovie("Ball", "ball_125", 20, {distance:125});
134
Chapter 7: Working with Movie Clips
parameter of
initObject
"Assigning a class to a movie clip symbol" on page
, whose value determines how many pixels a movie clip moves
distance
128), you can assign parameters to clips you create at
and
attachMovie()
"Adding parameters to
. You can
duplicateMovie()
133). The difference is a
, moves 125
ball_125

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?

Questions and answers

Table of Contents