Detailed instructions for use are in the User's Guide.
[. . . ] ActionScript Language Reference
Trademarks Add Life to the Web, Afterburner, Aftershock, Andromedia, Allaire, Animation PowerPack, Aria, Attain, Authorware, Authorware Star, Backstage, Bright Tiger, Clustercats, ColdFusion, Contribute, Design In Motion, Director, Dream Templates, Dreamweaver, Drumbeat 2000, EDJE, EJIPT, Extreme 3D, Fireworks, Flash, Flash Lite, Flex, Fontographer, FreeHand, Generator, HomeSite, JFusion, JRun, Kawa, Know Your Site, Knowledge Objects, Knowledge Stream, Knowledge Track, LikeMinds, Lingo, Live Effects, MacRecorder Logo and Design, Macromedia, Macromedia Action!, Macromedia Breeze, Macromedia Flash, Macromedia M Logo and Design, Macromedia Spectra, Macromedia xRes Logo and Design, MacroModel, Made with Macromedia, Made with Macromedia Logo and Design, MAGIC Logo and Design, Mediamaker, Movie Critic, Open Sesame!, Roundtrip, Roundtrip HTML, Shockwave, Sitespring, SoundEdit, Titlemaker, UltraDev, Web Design 101, what the web can be, and Xtra are either registered trademarks or trademarks of Macromedia, Inc. and may be registered in the United States or in other jurisdictions including internationally. Other product names, logos, designs, titles, words, or phrases mentioned within this publication may be trademarks, service marks, or trade names of Macromedia, Inc. or other entities and may be registered in certain jurisdictions including internationally. [. . . ] If it is loaded into another FLA document, _root will always refer to the scope of lockroot. swf, which helps prevent conflicts. Place the following ActionScript on the main Timeline of lockroot. fla.
this. _lockroot = true; _root. myVar = 1; _root. myOtherVar = 2; trace("from lockroot. swf"); for (i in _root) { trace(" "+i+" -> "+_root[i]); } trace("");
Which traces the following information:
from lockroot. swf myOtherVar -> 2 myVar -> 1
MovieClip. _lockroot
543
_lockroot -> true $version -> WIN 7, 0, 19, 0
The following example loads two SWF files, lockroot. swf and nolockroot. swf. The lockroot. fla document contains the previous ActionScript. The nolockroot FLA file has the following code placed on Frame 1 of the Timeline:
_root. myVar = 1; _root. myOtherVar = 2; trace("from nolockroot. swf"); for (i in _root) { trace(" "+i+" -> "+_root[i]); } trace("");
The lockroot. swf file has _lockroot applied to it, and nolockroot. swf does not. After the files are loaded, each file dumps variables from their _root scopes. Place the following ActionScript on the main Timeline of a FLA document:
this. createEmptyMovieClip("lockroot_mc", this. getNextHighestDepth()); lockroot_mc. loadMovie("lockroot. swf"); this. createEmptyMovieClip("nolockroot_mc", this. getNextHighestDepth()); nolockroot_mc. loadMovie("nolockroot. swf"); function dumpRoot() { trace("from current SWF file"); for (i in _root) { trace(" "+i+" -> "+_root[i]); } trace(""); } dumpRoot();
which traces the following information:
from current SWF file dumpRoot -> [type Function] $version -> WIN 7, 0, 19, 0 nolockroot_mc -> _level0. nolockroot_mc lockroot_mc -> _level0. lockroot_mc from nolockroot. swf myVar -> 1 i -> lockroot_mc dumpRoot -> [type Function] $version -> WIN 7, 0, 19, 0 nolockroot_mc -> _level0. nolockroot_mc lockroot_mc -> _level0. lockroot_mc from lockroot. swf myOtherVar -> 2 myVar -> 1
The file with no _lockroot applied contains all of the other variables contained in the root SWF as well. If you don't have access to the nolockroot. fla, then you can change the _lockroot in the main FLA document above using the following ActionScript added to the main Timeline:
this. createEmptyMovieClip("nolockroot_mc", this. getNextHighestDepth());
544
Chapter 2: ActionScript Language Reference
nolockroot_mc. _lockroot = true; nolockroot_mc. loadMovie("nolockroot. swf");
which would then trace the following:
from current SWF file dumpRoot -> [type Function] $version -> WIN 7, 0, 19, 0 nolockroot_mc -> _level0. nolockroot_mc lockroot_mc -> _level0. lockroot_mc from nolockroot. swf myOtherVar -> 2 myVar -> 1 from lockroot. swf myOtherVar -> 2 myVar -> 1 See also MovieClip. attachMovie(), MovieClip. loadMovie(), MovieClipLoader. onLoadInit, _root,
and "About loading components" in Using Components.
MovieClip. _lockroot
545
MovieClip. menu
Availability
Flash Player 7.
Usage my_mc. menu:ContextMenu = contextMenu Parameters contextMenu Description
A ContextMenu object.
Property; associates the specified ContextMenu object with the movie clip my_mc. The ContextMenu class lets you modify the context menu that appears when the user right-clicks (Windows) or Control-clicks (Macintosh) in Flash Player.
Example
The following example assigns the ContextMenu object menu_cm to the movie clip image_mc. The ContextMenu object contains a custom menu item labeled "View Image in Browser. . . " that has an associated function named viewImage().
var menu_cm:ContextMenu = new ContextMenu(); menu_cm. customItems. push(new ContextMenuItem("View Image in Browser. . . ", viewImage)); this. createEmptyMovieClip("image_mc", this. getNextHighestDepth()); var mclListener:Object = new Object(); mclListener. onLoadInit = function(target_mc:MovieClip) { target_mc. menu = menu_cm; }; var image_mcl:MovieClipLoader = new MovieClipLoader(); image_mcl. addListener(mclListener); image_mcl. loadClip("photo1. jpg", image_mc); function viewImage(target_mc:MovieClip, obj:Object) { getURL(target_mc. _url, "_blank"); }
When you right-click or Control-click the image at runtime, select View Image in Browser from the context menu to open the image in a browser window.
See also Button. menu, ContextMenu class, ContextMenuItem class, TextField. menu
546
Chapter 2: ActionScript Language Reference
MovieClip. moveTo()
Availability
Flash Player 6.
Usage my_mc. moveTo(x:Number, y:Number) : Void Parameters x
An integer indicating the horizontal position relative to the registration point of the parent movie clip. An integer indicating the vertical position relative to the registration point of the parent movie clip.
y
Returns
Nothing.
Description
Method; moves the current drawing position to (x, y). If any of the parameters are missing, this method fails and the current drawing position is not changed. You can extend the methods and event handlers of the MovieClip class by creating a subclass. For more information, see "Assigning a class to a movie clip symbol" in Using ActionScript in Flash.
Example
The following example draws a triangle with a 5-pixel, solid magenta line and a partially transparent blue fill:
this. createEmptyMovieClip("triangle_mc", 1); triangle_mc. beginFill(0x0000FF, 30); triangle_mc. lineStyle(5, 0xFF00FF, 100); triangle_mc. moveTo(200, 200); triangle_mc. lineTo(300, 300); triangle_mc. lineTo(100, 300); triangle_mc. lineTo(200, 200); triangle_mc. endFill(); See also MovieClip. createEmptyMovieClip(), MovieClip. lineStyle(), MovieClip. lineTo()
MovieClip. moveTo()
547
MovieClip. _name
Availability
Flash Player 4.
Usage my_mc. _name:String Description
Property; the instance name of the movie clip specified by my_mc.
Example
The following example lets you right-click or Control-click a movie clip on the Stage and select "Info. . . " from the context menu to view information about that instance. Add several movie clips with instance names, and then add the following ActionScript to your AS or FLA file:
var menu_cm:ContextMenu = new ContextMenu(); menu_cm. customItems. push(new ContextMenuItem("Info. . . ", getMCInfo)); function getMCInfo(target_mc:MovieClip, obj:Object) { trace("You clicked on the movie clip '"+target_mc. _name+"'. "); trace("\t width:"+target_mc. _width+", height:"+target_mc. _height); trace(""); } for (var i in this) { if (typeof (this[i]) == 'movieclip') { this[i]. menu = menu_cm; } } See Also Button. _name
548
Chapter 2: ActionScript Language Reference
MovieClip. nextFrame()
Availability
Flash Player 5.
Usage my_mc. nextFrame() : Void Parameters
None.
Returns
Nothing.
Description
Method; sends the playhead to the next frame and stops it. You can extend the methods and event handlers of the MovieClip class by creating a subclass. For more information, see "Assigning a class to a movie clip symbol" in Using ActionScript in Flash.
Example
The following example loads content into a SWF file using _framesloaded and nextFrame(). Do not add any code to Frame 1, but add the following ActionScript to Frame 2 of the Timeline:
if (this. _framesloaded >= 3) { this. nextFrame(); } else { this. gotoAndPlay(1); }
Then, add the following code (and the content you want to load) on Frame 3:
stop(); See also nextFrame(), MovieClip. prevFrame(), prevFrame()
MovieClip. nextFrame()
549
MovieClip. onData
Availability
Flash Player 6.
Usage my_mc. onData = function() { // your statements here } Parameters
None.
Returns
Nothing.
Description
Event handler; invoked when a movie clip receives data from a MovieClip. loadVariables() or MovieClip. loadMovie() call. You must define a function that executes when the event handler is invoked. You can define the function on the Timeline or in a class file that extends the MovieClip class or is linked to a symbol in the library. For more information, see "Assigning a class to a movie clip symbol" in Using ActionScript in Flash. This handler can be used only with movie clips for which you have a symbol in the library that is associated with a class. If you want an event handler to be invoked when a specific movie clip receives data, you must use onClipEvent() instead of this handler. [. . . ] The scroll property is useful for directing users to a specific paragraph in a long passage or creating scrolling text fields. This property can be retrieved and modified.
Example
The following code is attached to an Up button that scrolls the text field named myText:
on (release) { myText. scroll = myText. scroll + 1; } See also TextField. maxscroll, TextField. scroll
1098
Appendix: Deprecated Language Elements
substring
Availability
Flash Player 4. This function was deprecated in favor of String. substr().
Usage substring("string", index, count) Parameters string index
The string from which to extract the new string. The number of the first character to extract.
count The number of characters to include in the extracted string, not including the index character. [. . . ]