Movie Clips: The Object Overview


Since Flash 5, the implementation of ActionScript has resembled that of true object-oriented programming languages. Much like JavaScript, each element in a Flash movie has a data type. A data type is simply a category to which an element belongs. In the current version of ActionScript (including ActionScript 2.0), there are several data types available — boolean, number, string, object, function, and movieclip, among others.

Tip 

If you want to see a list of all data types in ActionScript, open the Actions panel (make sure code hints are turned on), and type var a:. After you type the colon (:), you'll see a list of supported data types.

For our purposes, a Movie Clip instance is an object, and we'll refer to it as such throughout Part VII of this book. An object is any element in Flash that has changeable and accessible characteristics through ActionScript. Objects can be user-defined (you create and name them) or predefined by the programming language. The MovieClip object is a predefined object, meaning that all of its characteristics are already described in the ActionScript language.

A MovieClip object is the same Movie Clip instance you've seen in previous chapters. Any instance of a Movie Clip is a unique object in ActionScript. However, you haven't treated it like an object in your scripting. Before we can proceed with a discussion of Movie Clips as Flash movie assets, you need to understand what predefined characteristics are available in the MovieClip object. See Figure 25-1 for more information.

image from book
Figure 25-1: An overview of the MovieClip object

Movie Clip Properties

Each Movie Clip instance has definable properties, or attributes, that control its appearance, size, and position. For example, you can move a Movie Clip instance to a new position on the stage by changing the value of its X or Y coordinate. This property in ActionScript is denoted as _x or _y, respectively. Some properties have read-only values, meaning these values can't be altered. One read-only property is _url, the value of which indicates the download location of the Movie Clip (or .swf file) such as http://www.yourserver.com/swf/background.swf. Figure 25-2 is a summary of the properties of the MovieClip object. For more information on each property, please refer to Table 25-1, "Flash Movie and Movie Clip Properties."

Table 25-1: Flash Movie and Movie Clip Properties
Open table as spreadsheet

Category

Property

Timeline

Flash 4

Flash 5+

Flash 8

Definition

Position

_x

MC

Movie

RW

RW

RW

RW

RW

RW

The horizontal distance between a Movie Clip’s center point and the top-left corner of the stage upon which it resides. It increases as the clip moves to the right, and is measured in pixels.

_y

MC

Movie

RW

RW

RW

RW

RW

RW

The vertical distance between a Movie Clip’s center point and the top-left corner of the stage upon which it resides. It increases as the clip moves downward, and is measured in pixels.

_xmouse

MC

Movie

N/A

R

R

R

R

The horizontal distance (in pixels) between the zero point of a Movie Clip (or the Movie) and the current position of the mouse pointer.

_ymouse

MC

Movie

N/A

R

R

R

R

The vertical distance (in pixels) between the zero point of a Movie Clip (or the Movie) and the current position of the mouse pointer.

_rotation

MC

Movie

RW

RW

RW

RW

RW

RW

The amount (in degrees) that a Movie Clip is rotated off plumb. It returns values set both by the Transform panel (or Transform tool) and by ActionScript.

_xscale

MC

Movie

RW

RW

RW

RW

RW

RW

The width of a Movie Clip instance (or Movie) as a percentage of the parent symbol’s actual size.

Size

_yscale

MC

Movie

RW

RW

RW

RW

RW

RW

The height of a Movie Clip instance (or Movie) as a percentage of the parent symbol’s actual size.

_width

MC

Movie

R

R

RW

R

RW

R

The width (in pixels) of a Movie Clip or the main Movie Stage. It is determined not by the width of the canvas but by the width of the space occupied by elements on the Stage (meaning it can be less than or greater than the canvas width set in Movie Properties).

_height

MC

Movie

R

R

RW

R

RW

R

The height (in pixels) of a movie clip or the main movie Stage. It is determined not by the height of the canvas but by the height of the space occupied by elements on the Stage.

Appearance

_alpha

MC

Movie

RW

RW

RW

RW

RW

RW

The amount of transparency of a Movie Clip or Movie. It is measured as a percentage: 100 percent is completely opaque; 0 percent is completely transparent.

_visible

MC

Movie

RW

RW

RW

RW

RW

RW

A Boolean value that indicates whether a Movie Clip instance is shown or hidden. It is set to 1 (or true) to show; 0 (or false) to hide. Buttons in "hidden" movies are not active.

 

filters

MC

Movie

N/A

N/A

N/A

N/A

RW

RW

This new property in Flash Player 8 enables you to add visual effects to MovieClip objects. The filters property uses an array to describe which filters have been applied to the clip.

transform

MC

Movie

N/A

N/A

RW

N/A

RW

RW

This new property in Flash Player 8 enables you to control physical characteristics of a MovieClip object via transformation object. In Chapter 27, “Interacting with Movie Clips,” we discuss the ColorTransform class, which can control the color properties of a MovieClip object.

Internal Path

_name

MC

Movie

RW

R

RW

R

RW

R

This property returns or reassigns the Movie Clip instance’s name (as listed in the Property inspector).

_target

MC

Movie

R

R

R

R

R

R

This property returns the exact string in Slash notation that you'd use to refer to the Movie Clip instance. To retrieve the dot syntax path, use eval(_target).

_droptarget

MC

Movie

R

R

R

R

R

R

This property returns the name (in Slash notation) of the last Movie Clip upon which a draggable Movie Clip was dropped. To retrieve the dots syntax path, use eval(_droptarget). For usage, see “Creating Draggable Movie Clips” in this chapter.

_lockroot

MC

Movie

RW

RW

RW

RW

RW

RW

This property, only available to Flash Player 7 or higher-compatible movies, enables you to control how a _root reference is interpreted. If the _lockroot property of a MovieClip object is set to true, then any child assets (nested MovieClip objects) will see the parent MovieClip object as _root. For example, if you load an .swf file into a MovieClip object, any _root target in the loaded .swf will point to the MovieClip object.

_parent

MC

Movie

N/A

N/A

R

R

R

R

This property returns a reference to the parent timeline of the current MovieClip object. For example, if an instance named bird_1 exists within another instance named flock_mc, then bird_1._parent refers to the flock_mc instance.

* _parent will return only a valid reference from the Main Timeline if the Flash movie is loaded into a MovieClip instance of another Flash movie.

External Path

_url

MC

Movie

R

R

R

R

R

R

This property returns the complete path to the Flash movie (.swf) in which the action is executed, including the name of the Flash movie file (.swf) itself. It can be used to prevent a movie from being viewed if it is not on a particular server.

Timeline

_currentframe

MC

Movie

R

R

R

R

R

R

This property returns the number of the current frame (for example, the frame on which the Playhead currently resides) of the Movie or a Movie Clip instance.

_totalframes

MC

Movie

R

R

R

R

R

R

This property returns the number of total frames in a Movie or Movie Clip instance’s timeline.

_framesloaded

MC

Movie

R

R

R

R

R

R

This property returns the number of frames that have downloaded over the network.

Global

_quality

Movie

N/A

RW

RW

The visual quality of the Movie. The value is a string equal to: “LOW” (no anti-aliasing, no bitmap smoothing), “MEDIUM” (anti-aliasing on a 2 x 2 grid, no bitmap smoothing), “HIGH” (anti-aliasing on a 4 x 4 grid, bitmap smoothing on static frames), “BEST” (anti-aliasing on a 4 x 4 grid, bitmap smoothing on all frames).

_focusrect

Movie

RW

RW

RW

A Boolean value that indicates whether a yellow rectangle is shown around buttons when accessed via the Tab key. The default is to show. When set to 0, the Up state of the button is shown instead of the yellow rectangle.

_soundbuftime

Movie

RW

RW

RW

The number of seconds a sound should preload before it begins playing. The default is five seconds.

MC = Movie Clip; R = Read property (cannot be modified); W = Write property (can be modified)

image from book
Figure 25-2: Properties of the MovieClip object

All properties are preceded by the underscore (_) character. In Table 25-1, each property has an "R" (as in "read") and/or "W" (as in "write") designation. All properties can be read, which means that you can retrieve that property's current value. The values of some properties can also be changed through ActionScript. The table represents these properties with the "W" designation.

Note 

In Flash Player 4 ActionScript, these properties were retrieved using the getProperty() action. Properties are altered using the setProperty() action. For Flash Player 5 or higher movies, you should avoid using these actions. Many free online Flash tutorials or samples at sites such as FlashKit.com will often be riddled with these deprecated actions.

Cross-Reference 

We don't review the more advanced properties of the MovieClip object in this chapter. Cross For the most comprehensive coverage, refer to the MovieClip class coverage in the Flash ActionScript Bible series by Robert Reinhardt and Joey Lott (Wiley).

On the CD-ROM 

Use the propInspector Movie Clip in the Library of the property_inspector.fla file, located in the ch25 folder of this book's CD-ROM, to see the values of Movie Clip or Movie properties.

Movie Clip Methods

Although the name might sound intimidating, don't be scared. Methods are simply actions that are attached to objects. As you now know, Movie Clips qualify as objects in ActionScript. A method looks like a regular action, except it doesn't (and, in most cases, can't) operate without a dot syntax reference to a target or an object:

  • Action: gotoAndPlay("start");

becomes

  • Method: myMovieClip.gotoAndPlay("start");

As actions, interactive commands are executed from the timeline on which they are written. As methods, interactive commands are tied to specific (or dynamic) targets. Figure 25-3 lists many of the methods and Table 25-2 reviews them in more detail. Some methods can be used with Movie Clip instances and with the entire Flash movie (_root, _level0, and so on), while others can only be used with Movie Clip instances. The "Flash 4" column in Table 25-2 indicates if the method (when used as an action) is compatible in Flash Player 4. Some commands need to be written in dot syntax, as a method (designated as "M" in the table) of a timeline or MovieClip object. Other commands can be used as actions (designated as "A" in the table), meaning that the MovieClip object name need not precede the command.

Table 25-2: Common Movie and Movie Clip Methods
Open table as spreadsheet

Category

Method

Flash 4

Definition

Usage

Position

hitTest

M

No

Determines if a MovieClip object overlaps with the boundaries of another MovieClip object, or if an X-Y coordinate intersects with a MovieClip instance. For more information on this method, see Chapter 27, “Interacting with Movie Clips.”

timeline.hitTest(MovieClip object);

OR

timeline.hitTest(x coordinate, y coordinate, shapeFlag);

myMC.hitTest(myOther_mc);

myMC.hitTest(_root._xmouse,

_root._ymouse,true);

startDrag

M, A

Yes

Enables the user to move a Movie Clip instance on the Stage. The Movie Clip moves (or drags) in tandem with the movements of the mouse. You can specify whether the mouse pointer locks to the center of the Movie Clip instance and if the drag area is constrained to a range of X and Y coordinates (in the parent symbol or timeline space). Constraining the drag area is useful for slider controls.

timeline.startDrag(lock, min X, min Y, max X, max Y);

myMC.startDrag(false,200,0,200,200);

stopDrag

M, A

Yes

Stops any startDrag action currently in progress. No target needs to be specified with this action.

timeline.stopDrag();

myMC.stopDrag();

Playback

play

M, A

Yes

Starts playback from the current position of the Playhead on a specified timeline.

timeline.play();

_root.play(); // plays the Main Timeline

_root.myMC.play(); // plays myMC

stop

M, A

Yes

Stops playback on a specified timeline.

timeline.stop();

_root.stop(); // stops the Main Timeline

_root.myMC.stop(); // stops myMC

gotoAndPlay

M, A

Yes

Jumps the Playhead of a specified timeline to a label, frame number, or expression, and starts playing from there.

timeline.gotoAndPlay(position);

_root.myMC.gotoAndPlay(“start”);

// plays from the “start” label of the myMC

timeline

gotoAndStop

M, A

Yes

Jumps the Playhead of a specified timeline to a label, frame number, or expression, and stops playback.

timeline.gotoAndStop(position);

_root.myMC.gotoAndStop(“mute”);

// stops playback on the “mute” label of myMC

nextFrame

M, A

Yes

Moves the Playhead of the specified timeline to the next frame.

timeline.nextFrame();

_root.myMC.nextFrame();

prevFrame

M, A

Yes

Moves the Playhead of the specified timeline to the previous frame.

timeline.prevFrame();

_root.myMC.prevFrame();

Internal

Assets

createEmptyMovieClip

M

No

Makes a blank (empty) Movie Clip instance on the Stage (or nested in another Movie Clip instance). The new instance is placed directly above the parent instance, at a specified depth. Higher depth numbers appear above lower depth numbers (for example, a Movie Clip at depth 2 is stacked above a Movie Clip at depth 1).

This method works only in Flash 6 or higher movies played in Flash Player 6 or higher.

timeline.createEmptyMovieClip(new name*, depth);

_root.createEmptyMovieClip(“myMC”, 1);

myMC._x = 50;

*You should only specify an instance name for the new MovieClip object — not a new path. You can only create new instances relative to the instance invoking the method.

duplicateMovieClip

M, A

Yes

Makes a copy of an existing Movie Clip instance on the Stage (or nested in another Movie Clip). The new copy is placed directly above the parent instance, at a specified depth. Higher depth numbers appear above lower depth numbers (for example, a Movie Clip at depth 2 is stacked above a Movie Clip at depth 1).

timeline.duplicateMovieClip(new name*, depth);

myMC.duplicateMovieClip(“myMC_2”, 20);

myMC_2._x = 200;

*See note for the createEmptyMovieClip() method.

 

remove MovieClip

M, A

Yes

Deletes a previously duplicated Movie Clipinstance. When used as a method, you do not need to specify a target. You cannot remove a Movie Clip instance that is manually inserted on any timeline frame from the Library.

timeline.removeMovieClip();

myMC_2.removeMovieClip();

 

attachMovie

M

No

Places an instance of from the Library into the specified timeline. Each attached instance requires a unique name and depth. Attached Movie Clip instances can be deleted with removeMovieClip.

timeline.attachMovie(ID*, new name, depth);

_root.attachMovie(“eye”, “eye_1”, 1);

*You need to specify a unique identifier to linked Movie Clip symbols in the Library, using the Linkage Properties.

 

getDepth

M

No

Returns the current depth of a duplicated (or attached) MovieClip object.

This method only works in Flash 6 movies played in Flash Player 6.

timeline.getDepth();

_root.attachMovie(“eye”, “eye_1”, 1); trace(eye_1.getDepth());

*If you attempt to retrieve the depth of a Movie Clip instance that you manually placed on the Stage, then ActionScript will return -16383 as the value of getDepth().

 

swapDepths

M

No

Switches the depth placement of two duplicated or attached Movie Clips. This method is useful for placing one Movie Clip instance in front of (or behind) another instance.

timeline.swapDepths(depth);

timeline.swapDepths(target);

eye_1.swapDepths(10); // depth

eye_1.swapDepths(eye_2); // target

 

getNextHighestDepth

M

No

Determines if any objects currently exist within depth slots of the current MovieClip object, and returns a depth number one higher than an occupied slot. For example, if you duplicated a MovieClip object to a depth count of 2, this method would return 3. You can use this method in conjunction with any of the Movie Clip methods that require a depth parameter.

This method works only when issued from a Flash Player 7 or higher movie.

timeline.getNextHighestDepth();

var nextSlot =

myMC.getNextHighestDepth();

getInstanceAtDepth

M

No

Returns the name of an object occupying the specified depth slot. If no object exists at the slot, undefined is returned

This method works only when issued from a Flash Player 7 or higher movie.

timeline.getInstanceAtDepth(depthSlot);

var isOccupied = myMC.getInstanceAtDepth(1);

createTextField

M

No

Adds a new TextField object (that is, a dynamic or input text field) to the MovieClip object. This method enables you to add new text fields to your movie at run time.

This method works only when issued from a Flash Player 6 or higher movie.

timeline.createTextField (name, depth, x position, y position, width, height);

myMC.createTextField(“display_txt”, 1, 10, 10, 300, 50);

 

setMask

M

No

Assigns a MovieClip object to be used as the mask for another MovieClip object.

This method works only when issued from a Flash Player 6 or higher movie.

timeline.setMask(instanceName);

myMC.setMask(clip_mc);

External Assets

loadMovie

M, A

Yes

Loads an external movie file (.swf) or image file into the main movie. As one of the most powerful features of Flash, this method enables you to break up your Flash movie into several smaller components, and load them as needed. This method can load movie files (.swf) or standard JPEG image files (.jpg) into Flash Player 6 or higher movies. Flash Player 8 movies can also load GIF, PNG, and progressive JPEG images into Movie Clip targets.

timeline.loadMovie(path, send variables*);

myMC.loadMovie(“menu.swf”);

OR

myMC.loadMovie(“image.jpg”);

*You can also send Flash variables to the newly loaded .swf file with an optional "GET" or "POST" parameter. We discuss this in Chapter 24, “Knowing the Nuts and Bolts of Code.”

unloadMovie

M, A

Yes

Removes an externally loaded movie file (.swf) or image file from the main movie. This method enables you to dump movieassets when they are no longer needed. Use this method for assets loaded into Movie Clip targets.

timeline.unloadMovie();

myMC.unloadMovie();

 

loadVariables

M, A

Yes

Loads external text-based data into the movie. This method enables you to access data (in the form of variable name/value pairs) from server-side scripts or text files, and place it in a Movie Clip target.

timeline.loadVariables(path, send variables*);

myMC.loadVariables(“info.txt”);

*See note in loadMovie. We discuss load Variables() and the LoadVars object in Chapter 29, “Sending Data In and Out of Flash.”

getBytesLoaded

M

No

Returns the number of bytes that have streamed into the Flash Player for a specified Movie Clip (or movie).

timeline.getBytesLoaded();

loadBytes = myMC.getBytesLoaded();

getBytesTotal

M

No

Returns the total file size (in bytes) for a loading movie or Movie Clip. Combined with getBytesLoaded(), you can use this method to calculate the movie’s loaded percentage.

timeline.getBytesTotal();

totalBytes = myMC.getBytesTotal();

loadBytes = myMC.getBytesLoaded();

newPercent = (loadBytes/totalBytes)*100;

getSWFVersion

No

Returns the version of the Flash movie as a number. For example, if you create a Flash movie (.swf) to be Flash Player 4-compatible, you can check the version number of that .swf from a Flash Player 7-compatible movie file (.swf).

timeline.getSWFVersion();

This method can only be invoked from Flash movies created for Flash Player 7 or higher.

myMC.getSWFVersion();

M = Method; A = Action

image from book
Figure 25-3: Common methods of the MovieClip object

Cross-Reference 

Figure 25-3 and Table 25-2 do not contain all methods of the MovieClip class. For comprehensive descriptions and usage of the methods, refer to the Flash ActionScript Bible series by Robert Reinhardt and Joey Lott (Wiley).

Here's how you create a simple example of onClipEvent() in action:

  1. Open a new Flash document (File New).

  2. Draw any artwork you wish, and make the artwork a Movie Clip symbol.

  3. Select the Movie Clip instance on the Stage. In the Property inspector, name the instance mcTracker.

  4. With the mcTracker instance selected on the Stage, open the Actions panel (F9). Type the following code into the Script pane:

     onClipEvent (mouseMove){   this._x = _root._xmouse;   this._y = _root._ymouse;   updateAfterEvent(); } 

    This code uses onClipEvent() to track the position of the user's mouse, and apply that position to the MovieClip object — effectively moving the MovieClip object with the mouse pointer. The code is executed every time the user's mouse moves. The updateAfterEvent() action will tell the Flash Player to refresh the video display each time a mouse move is detected, resulting in a smoother movement of the object.

  5. Save your Flash document as tracker_oce.fla, and test it (Ctrl+Enter or z+Enter). As you move the mouse, the artwork will follow the mouse.

On the CD-ROM 

You can find a completed version of the file tracker_oce.fla in the ch25 folder of this book's CD-ROM.

Event Methods: The More Flexible Movie Clip Handler

In Flash Player 6 and higher, event handlers for MovieClip objects can be written and executed from any other event handler. This means that you can code the same event handlers used for onClipEvent() in keyframe or Button instance actions. While this may not seem like a monumental leap forward, this new event model enables you to create event handlers that are not directly attached to physical instances of a Movie Clip on the Stage. For a summary of common event methods, see Table 25-3.

Table 25-3: Common Flash Player 5 and Higher Event Handlers
Open table as spreadsheet

Category

onClipEvent (FP5+)

Event Handler (FP6+)

Definition

Usage

Playback

load

onLoad

This event is triggered when (A) a Movie Clip instance first appears on the Stage; (B) a new instance is added with attachMovie or duplicateMovieClip; or (C) an external Flash movie file (.swf) is loaded into a Movie Clip target.

onClipEvent(load){

trace( _name + “ has loaded.”);

}

OR

Note: The onLoad method does not function properly on individual instances. When a Flash movie file (.swf) loads into a level or a Movie Clip target, any existing methods will be overwritten, including onLoad. See the Usage example to see how onLoad can be used. The onLoad method, however, is useful for setting parameters for components that are added via ActionScript.

MovieClip.prototype.onLoad = function(){

trace(“A movie or Movie Clip has loaded.”);

};

unload

onUnload

This event occurs when (A) a Movie Clip instance exits the Stage (just after the last frame has played on the Main Timeline), or (B) an external Flash movie file (.swf) is unloaded from a Movie Clip target. Actions within this handler type will be executed before any actions in the keyframe immediately after the Movie Clip’s departure keyframe.

onClipEvent(unload){

trace( _name + “ has unloaded.”);

}

OR

mcHolder.onUnload = function(){

trace(this._name + “ has unloaded.”);

};

 

enterFrame

onEnterFrame

This event executes when each frame on a Movie Clip instance’s timeline is played. The actions within this event handler will be processed after any actions that exist on the keyframes of the Movie Clip Timeline. Note that enterFrame events will execute repeatedly (at the same rate as the movie’s frame rate), regardless of whether any timelines within the movie are actually playing frames.

onClipEvent(enterFrame){

trace( _name+ “ is playing.”);

}

OR

mcHolder.onEnterFrame = function(){

trace(_name + “ is playing.”);

};

User Input

mouseMove

onMouseMove

This event is triggered each time the mouse moves anywhere on the Stage. All Movie Clip instances with this event handler defined receive this event. Combined with the hitTest() method, this event can be used to detect mouse movements over Movie Clip instances.

onClipEvent(mouseMove){

var myX = _root._xmouse;

var myY = _root._ymouse;

if(this.hitTest(myX, myY, true) == true){

trace(“Mouse move over MC.”);

}

}

OR

mcHolder.onMouseMove = function(){

var myX:Number = _root._xmouse;

var myY:Number = _root._ymouse;

if(this.hitTest(myX, myY, true)){

trace(“Mouse move over “ + this._name);

}

updateAfterEvent();

};

 

mouseDown

onMouseDown

This event occurs each time the left mouse button is pressed (or down) anywhere on the Stage. All Movie Clip instances with this event handler receive this event.

onClipEvent(mouseDown){

myX = _root._xmouse;

myY = _root._ymouse;

if(this.hitTest(myX, myY, true)){

trace(“Mouse press on MC.”);

}

}

OR

mcHolder.onMouseDown = function(){

var myX:Number = _root._xmouse;

var myY:Number = _root._ymouse;

if(this.hitTest(myX, myY, true)){

trace(“Mouse press on “ + this._name);

}

};

 

mouseUp

onMouseUp

This event is triggered each time the left mouse button is released (when the user lets up on the mouse button). All Movie Clip instances with this handler receive this event.

onClipEvent(mouseUp){

myX = _root._xmouse;

myY = _root._ymouse;

if(this.hitTest(myX, myY, true)){

trace(“Mouse release on MC.”);

}

}

OR

mcHolder.onMouseUp = function(){

var myX:Number = _root._xmouse;

var myY:Number = _root._ymouse;

if(this.hitTest(myX, myY, true)){

trace(“Mouse release on “ + this._name);

}

};

 

keyDown

onKeyDown

This event occurs when the user presses a key. Combined with the Key.getCode method, you can use this event handler to detect unique key presses.

Note: It’s better to use Key.addListener() with a listener object to detect key down events.

onClipEvent(keyDown){

newKey = Key.getCode();

myKey = Key.UP;

if(newKey == myKey){

trace(“UP arrow is pressed.”);

}

}

 

keyUp

onKeyUp

This event happens when the user releases a key (when the finger leaves the key). It provides the same functionality as the keyDown event.

Note: It’s preferable to use Key.addListener() with a listener object to detect key down events. We discuss this advanced use of the Key class in the Flash ActionScript Bible series by Robert Reinhardt and Joey Lott (Wiley).

onClipEvent(keyUp){

newKey = Key.getCode();

myKey = Key.LEFT;

if(newKey == myKey){

trace(“LEFT arrow released.”);

}

}

External Input

data

onData

This event is triggered when (A) the loadMovie action retrieves an external Flash movie file (.swf) and puts it in a Movie Clip target, or (B) the data from a file or script with the loadVariables action (targeted at a Movie Clip instance) is finished loading.

Note: If you’re building Flash Player 6 or higher movies, use the LoadVars class to load URL-encoded variables into a Flash movie. Learn more about the LoadVars class in Chapter 29, “Sending Data In and Out of Flash.”

onClipEvent(data){

trace(“New data received.”);

}

OR

mcHolder.onData = function(){

trace(“New data received.”);

}

Cross-Reference 

It is beyond the scope of this book to discuss all of the event methods available in ActionScript 1.0 and 2.0. Please refer to the Flash ActionScript Bible series by Robert Reinhardt and Joey Lott (Wiley) for more information.

To get a better idea of how this event model works, create this simple example:

  1. Create a new Flash document.

  2. Draw some artwork, and make it a Movie Clip symbol.

  3. Select the new instance on the Stage. Name the instance mcTracker in the Property inspector.

  4. Create a new layer on the Main Timeline (that is, Scene 1). Name the layer actions.

  5. Select frame 1 of the actions layer, and open the Actions panel (F9). Type the following code into the Script pane:

     var mcTracker:MovieClip; mcTracker.onMouseMove = function (){    this._x = _root._xmouse;    this._y = _root._ymouse;    updateAfterEvent(); }; 

    This code adds an onMouseMove() method to the tracker instance. Each time the user's mouse moves, the function written for the method will execute. We discuss functions in the next chapter.

  6. Save your Flash document as tracker_eventmodel.fla, and test it (Ctrl+Enter or z+Enter). The artwork will follow your mouse pointer as you move it on the Stage.

On the CD-ROM 

You can find the completed document, tracker_eventmodel.fla, in the ch25 folder of this book's CD-ROM. You will also find another document, tracker_eventmodel_adv.fla, which uses multiple event handlers.

You can continue to add more event methods to the tracker instance, in order for the instance to respond to mouse clicks, time elapsing, and so on.

Caution 

The new event model for Flash movies only works in Flash Player 6 or higher. If you need to use events with Movie Clips that are compatible with Flash Player 5, then use onClipEvent() handlers.

Other Classes and Functions that Use the MovieClip Object

You can use Movie Clips with other ActionScript classes to control appearances and sounds, and to manipulate data.

ColorTransform Class

This class can control the color effects of the targeted Movie Clip.

New Feature 

Flash Player 8 introduces a new MovieClip class property, transform. The transform property controls color transformations applied to a MovieClip instance. For more information about this new feature, read Chapter 27, "Interacting with Movie Clips."

Sound Class

With this class, you can create virtual sound instances on a Movie Clip Timeline and target them for later use.

Mouse Class

This class controls the appearance of the mouse pointer within the Flash movie. After the Mouse object is hidden, you can attach a MovieClip object to the X and Y coordinates of the mouse pointer.

PrintJob API

Flash MX 2004 and Flash Player 7 introduced the ActionScript class, PrintJob. PrintJob objects enable you to send MovieClip instances — as pages to a user's printer. The PrintJob class offers you more control over printing than previous versions of the Flash Player. You learn more about the PrintJob API in Chapter 27, "Interacting with Movie Clips."

Note 

You can still use the print() function for Flash Player 6 or earlier movies. This function prints a frame (or series of frames) in the targeted timeline. Each frame prints to one piece of paper. Use this function to print high-quality artwork. Note that alpha and color effects applied to MovieClip objects do not print reliably with this method — use the printAsBitmap() function instead.

With() Action

This action enables you to avoid needless replication of object references and paths. By specifying a target for the with() action, you can omit the path from nested actions. We demonstrate the with() action in the next section.

TellTarget() Action

This Flash Player 4-compatible action can direct actions to a specific Movie Clip Timeline. To be compatible with Flash Player 4, you need to use slash syntax for the target path. We strongly discourage you from using tellTarget() actions if you are designing Flash Player 5 or higher movies.




Macromedia Flash 8 Bible
Macromedia Flash8 Bible
ISBN: 0471746762
EAN: 2147483647
Year: 2006
Pages: 395

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net