Macromedia Logo

ActionScript 2.0 Language Reference

Global Functions

This section contains a set of built-in functions that are available in any part of a SWF file where ActionScript is used. These global functions cover a wide variety of common programming tasks such as working with data types (Boolean(), int(), and so on), producing debugging information (trace()), and communicating with Flash Player or the browser (fscommand()).


Functions
       Array([numElements:Number], [elementN:Object]) : Array
Creates a new, empty array or converts specified elements to an array.
       asfunction
A special protocol for URLs in HTML text fields that allows an HREF link to call an ActionScript function.
       Boolean(expression:Object) : Boolean
Converts the parameter expression to a Boolean value and returns true or false.
       call(frame:Object) : Void
Deprecated as of Flash Player 5 — This action was deprecated in favor of the function statement.
       chr(number:Number) : String
Deprecated as of Flash Player 5 — This function was deprecated in favor of String.fromCharCode().
       clearInterval(intervalID:Number) : Void
Stops the setInterval() call.
       clearTimeout(id:Number) : Void
Cancels a specified setTimeout() call.
       duplicateMovieClip(target:Object, newname:String, depth:Number) : Void
Creates an instance of a movie clip while the SWF file is playing.
       escape(expression:String) : String
Converts the parameter to a string and encodes it in a URL-encoded format, where all nonalphanumeric characters are replaced with % hexadecimal sequences.
       eval(expression:Object) : Object
Accesses variables, properties, objects, or movie clips by name.
       fscommand(command:String, parameters:String) : Void
Lets the SWF file communicate with either Flash Player or the program hosting Flash Player, such as a web browser.
       getProperty(my_mc:Object, property) : Object
Returns the value of the specified property for the movie clip my_mc.
       getTimer() : Number
Returns the number of milliseconds that have elapsed since the SWF file started playing.
       getURL(url:String, [window:String], [method:String]) : Void
Loads a document from a specific URL into a window or passes variables to another application at a defined URL.
       getVersion() : String
Returns a string containing Flash Player version and platform information.
       gotoAndPlay([scene:String], frame:Object) : Void
Sends the playhead to the specified frame in a scene and plays from that frame.
       gotoAndStop([scene:String], frame:Object) : Void
Sends the playhead to the specified frame in a scene and stops it.
       ifFrameLoaded([scene:String], frame:Object) : Void
Deprecated as of Flash Player 5 — This function has been deprecated. Macromedia recommends that you use the MovieClip._framesloaded property.
       int(value:Number) : Number
Deprecated as of Flash Player 5 — This function was deprecated in favor of Math.round().
       isFinite(expression:Object) : Boolean
Evaluates expression and returns true if it is a finite number or false if it is infinity or negative infinity.
       isNaN(expression:Object) : Boolean
Evaluates the parameter and returns true if the value is NaN (not a number).
       length(expression:String, variable:Object) : Number
Deprecated as of Flash Player 5 — This function, along with all the string functions, has been deprecated. Macromedia recommends that you use the methods of the String class and the String.length property to perform the same operations.
       loadMovie(url:String, target:Object, [method:String]) : Void
Loads a SWF or JPEG file into Flash Player while the original SWF file plays.
       loadMovieNum(url:String, level:Number, [method:String]) : Void
Loads a SWF or JPEG file into a level in Flash Player while the originally loaded SWF file plays.
       loadVariables(url:String, target:Object, [method:String]) : Void
Reads data from an external file, such as a text file or text generated by ColdFusion, a CGI script, Active Server Pages (ASP), PHP, or Perl script, and sets the values for variables in a target movie clip.
       loadVariablesNum(url:String, level:Number, [method:String]) : Void
Reads data from an external file, such as a text file or text generated by a ColdFusion, CGI script, ASP, PHP, or Perl script, and sets the values for variables in a Flash Player level.
       mbchr(number:Number) : Void
Deprecated as of Flash Player 5 — This function was deprecated in favor of the String.fromCharCode() method.
       mblength(string:String) : Number
Deprecated as of Flash Player 5 — This function was deprecated in favor of the methods and properties of the String class.
       mbord(character:String) : Number
Deprecated as of Flash Player 5 — This function was deprecated in favor of String.charCodeAt().
       mbsubstring(value:String, index:Number, count:Number) : String
Deprecated as of Flash Player 5 — This function was deprecated in favor of String.substr().
       MMExecute(command:String) : String
Lets you issue Flash JavaScript API (JSAPI) commands from ActionScript.
       nextFrame() : Void
Sends the playhead to the next frame.
       nextScene() : Void
Sends the playhead to Frame 1 of the next scene.
       Number(expression:Object) : Number
Converts the parameter expression to a number.
       Object([value:Object]) : Object
Creates a new empty object or converts the specified number, string, or Boolean value to an object.
       on(mouseEvent:Object) : Void
Specifies the mouse event or keypress that triggers an action.
       onClipEvent(movieEvent:Object) : Void
Triggers actions defined for a specific instance of a movie clip.
       ord(character:String) : Number
Deprecated as of Flash Player 5 — This function was deprecated in favor of the methods and properties of the String class.
       parseFloat(string:String) : Number
Converts a string to a floating-point number.
       parseInt(expression:String, [radix:Number]) : Number
Converts a string to an integer.
       play() : Void
Moves the playhead forward in the Timeline.
       prevFrame() : Void
Sends the playhead to the previous frame.
       prevScene() : Void
Sends the playhead to Frame 1 of the previous scene.
       print(target:Object, boundingBox:String) : Void
Prints the target movie clip according to the boundaries specified in the parameter (bmovie, bmax, or bframe).
       printAsBitmap(target:Object, boundingBox:String) : Void
Prints the target movie clip as a bitmap according to the boundaries specified in the parameter (bmovie, bmax, or bframe).
       printAsBitmapNum(level:Number, boundingBox:String) : Void
Prints a level in Flash Player as a bitmap according to the boundaries specified in the parameter (bmovie, bmax, or bframe).
       printNum(level:Number, boundingBox:String) : Void
Prints the level in Flash Player according to the boundaries specified in the boundingBox parameter (bmovie, bmax, bframe).
       random(value:Number) : Number
Deprecated as of Flash Player 5 — This function was deprecated in favor of Math.random().
       removeMovieClip(target:Object) : Void
Deletes the specified movie clip.
       setInterval(functionReference:Function, interval:Number, [param:Object], objectReference:Object, methodName:String) : Number
Calls a function or a method of an object at periodic intervals while a SWF file plays.
       setProperty(target:Object, property:Object, expression:Object) : Void
Changes a property value of a movie clip as the movie clip plays.
       setTimeout(functionReference:Object, delay:Number, args:Object) : Number
Runs a specified function after a specified delay (in milliseconds).
       showRedrawRegions(enable:Boolean, [color:Number]) : Void
Provides the ability for the debugger player to outline the regions of the screen that are being redrawn.
       startDrag(target:Object, [lock:Boolean], [left,top,right,bottom:Number]) : Void
Makes the target movie clip draggable while the movie plays.
       stop() : Void
Stops the SWF file that is currently playing.
       stopAllSounds() : Void
Stops all sounds currently playing in a SWF file without stopping the playhead.
       stopDrag() : Void
Stops the current drag operation.
       String(expression:Object) : String
Returns a string representation of the specified parameter.
       substring(string:String, index:Number, count:Number) : String
Deprecated as of Flash Player 5 — This function was deprecated in favor of String.substr().
       targetPath(targetObject:Object) : String
Returns a string containing the target path of movieClipObject.
       tellTarget(target:String, statement(s)) : Void
Deprecated as of Flash Player 5 — Macromedia recommends that you use dot (.) notation and the with statement.
       toggleHighQuality() : Void
Deprecated as of Flash Player 5 — This function was deprecated in favor of _quality.
       trace(expression:Object) : Void
Evaluates the expression and outputs the result.
       unescape(string:String) : String
Evaluates the parameter x as a string, decodes the string from URL-encoded format (converting all hexadecimal sequences to ASCII characters), and returns the string.
       unloadMovie(target:Object) : Void
Removes a movie clip that was loaded by means of loadMovie() from Flash Player.
       unloadMovieNum(level:Number) : Void
Removes a SWF or image that was loaded by means of loadMovieNum() from Flash Player.
       updateAfterEvent() : Void
Updates the display when you call it within an handler or using setInterval().


Function detail

Array Function

Array() : Array
Array(numElements:Number) : Array
Array(element0:Object, [element1, element2, ...elementN]) : Array

Player version:  Flash Player 6

Creates a new array of length 0 or more, or an array populated by a list of specified elements, possibly of different data types.

Use Array() to create one of the following:

Using this function is similar to creating an array with the Array constructor (see "Constructor for the Array class").

You can pass a number (numElements) or a list of elements containing one or more different types (element0, element1, ... elementN).

Parameters that can accept more than one data type are listed in the signature as type Object.

Parameters
numElements:Number [optional] — A positive integer that specifies the number of elements in the array. You can specify either numElements or the list of elements, but not both.
elementN:Object [optional] — One or more parameters, element0, element1, ... , elementN, the values of which can be of any type. Parameters that can accept more than one data type are listed as type Object. You can specify either numElements or the list of elements, but not both.

Returns
     Array — An array.

Example
var myArray:Array = Array();
myArray.push(12);
trace(myArray); //traces 12
myArray[4] = 7;
trace(myArray); //traces 12,undefined,undefined,undefined,7

Usage 2: The following example creates an array of length 4 but with no elements defined:

var myArray:Array = Array(4);
trace(myArray.length);  // traces 4
trace(myArray); // traces undefined,undefined,undefined,undefined

Usage 3: The following example creates an array with three defined elements:

var myArray:Array = Array("firstElement", "secondElement", "thirdElement");
trace (myArray); // traces firstElement,secondElement,thirdElement
Unlike the Array class constructor, the Array() function does not use the keyword new .

See also
    Array class


asfunction Protocol

asfunction:function:Function, parameter:String

Player version:  Flash Player 5

A special protocol for URLs in HTML text fields that allows an HREF link to call an ActionScript function. In HTML text fields, you can create links using the HTML A tag. The HREF attribute of the A tag contains a URL that uses a standard protocol such as HTTP, HTTPS, or FTP. The asfunction protocol is an additional protocol that is specific to Flash, which causes the link to invoke an ActionScript function.

Parameters
function:String — An identifier for a function.
parameter:String — A string that is passed to the function named in the function parameter.

Example
In the following example, the playMP3() function is defined. The TextField object list_txt is created and set so HTML text can be rendered. The text Track 1 and Track 2 are links inside the text field. The playMP3() function is called when the user clicks either link and plays the MP3 that is passed as a parameter of the asfunction call.
var myMP3:Sound = new Sound();
function playMP3(mp3:String) {
  myMP3.loadSound(mp3, true);
  myMP3.onLoad = function(success) {
    if (!success) {
      // code to handle errors here
    }
  };
}
this.createTextField("list_txt", this.getNextHighestDepth(), 0, 0, 200, 100);
list_txt.autoSize = true;
list_txt.html = true;
list_txt.multiline = true;
list_txt.htmlText = "<a href=\"asfunction:playMP3, track1.mp3\">Track 1</a><br>";
list_txt.htmlText += "<a href=\"asfunction:playMP3, track2.mp3\">Track 2</a><br>";
When you click a link, the MP3 sound file streams in Flash Player.

See also
    TextField.htmlText


Boolean Function

Boolean(expression:Object) : Boolean

Player version:  Flash Player 5 — Behavior changed in Flash Player 7.

Converts the expression parameter to a Boolean value and returns a value as described in the following list: If expression is a string, the return value is as follows: If expression is a string, the result is true if the string has a length greater than 0; the value is false for an empty string.

Unlike the Boolean class constructor, the Boolean() function does not use the keyword new. Moreover, the Boolean class constructor initializes a Boolean object to false if no parameter is specified, while the Boolean() function returns undefined if no parameter is specified.

Parameters
expression:Object — An expression to convert to a Boolean value.

Returns
     Boolean — A Boolean value.

Example
trace(Boolean(-1)); // output: true
trace(Boolean(0)); // output: false
trace(Boolean(1)); // output: true


trace(Boolean(true)); // output: true
trace(Boolean(false)); // output: false


trace(Boolean("true")); // output: true
trace(Boolean("false")); // output: true

trace(Boolean("Craiggers")); // output: true
trace(Boolean("")); // output: false

If files are published for Flash Player 6 and earlier, the results differ for three of the preceding examples:

trace(Boolean("true")); // output: false
trace(Boolean("false")); // output: false
trace(Boolean("Craiggers")); // output: false

This example shows a significant difference between use of the Boolean() function and the Boolean class. The Boolean() function creates a Boolean value, and the Boolean class creates a Boolean object. Boolean values are compared by value, and Boolean objects are compared by reference.

// Variables representing Boolean values are compared by value
var a:Boolean = Boolean("a"); // a is true
var b:Boolean = Boolean(1); // b is true
trace(a==b); // true

// Variables representing Boolean objects are compared by reference
var a:Boolean = new Boolean("a"); // a is true
var b:Boolean = new Boolean(1); // b is true
trace(a == b); // false 

See also
    Boolean class


call Function

call(frame)

Deprecated as of Flash Player 5 — This action was deprecated in favor of the function statement.

Player version:  Flash Player 4

Executes the script in the called frame without moving the playhead to that frame. Local variables do not exist after the script executes.

Parameters
frame:Object — The label or number of a frame in the Timeline.

See also
    function statement, Function.call()


chr Function

chr(number:Number) : String

Deprecated as of Flash Player 5 — This function was deprecated in favor of String.fromCharCode().

Player version:  Flash Player 4

Converts ASCII code numbers to characters.

Parameters
number:Number — An ASCII code number.

Returns
     String — The character value of the specified ASCII code.

Example
The following example converts the number 65 to the letter A and assigns it to the variable myVar:
myVar = chr(65);

See also
    String.fromCharCode()


clearInterval Function

clearInterval(intervalID:Number) : Void

Player version:  Flash Player 6

Stops the setInterval() call.

Parameters
intervalID:Number — A numeric (integer) identifier returned from a call to setInterval().

Example
The following example first sets and then clears an interval call:

function callback() {
    trace("interval called: "+getTimer()+" ms.");
}

var intervalID:Number = setInterval(callback, 1000);

You must clear the interval when you have finished using the function. Create a button called clearInt_btn and use the following ActionScript to clear setInterval():

clearInt_btn.onRelease = function(){
    clearInterval( intervalID );
    trace("cleared interval");
};

See also
    setInterval()


clearTimeout Function

clearTimeout(id:Number) : Void

Player version:  Flash Player 8

Cancels a specified setTimeout() call.

Parameters
id:Number — The identification number of the setTimeout() call to cancel.

Example
Please see the example for the setTimeout() function.

See also
    setTimeout(), setInterval()


duplicateMovieClip Function

duplicateMovieClip(target:String, newname:String, depth:Number) : Void
duplicateMovieClip(target:MovieClip, newname:String, depth:Number) : Void

Player version:  Flash Player 4

Creates an instance of a movie clip while the SWF file is playing. The playhead in duplicate movie clips always starts at Frame 1, regardless of where the playhead is in the original movie clip. Variables in the original movie clip are not copied into the duplicate movie clip. Use the removeMovieClip() function or method to delete a movie clip instance created with duplicateMovieClip().

Parameters
target:Object — The target path of the movie clip to duplicate. This parameter can be either a String (e.g. "my_mc") or a direct reference to the movie clip instance (e.g. my_mc). Parameters that can accept more than one data type are listed as type Object.
newname:String — A unique identifier for the duplicated movie clip.
depth:Number — A unique depth level for the duplicated movie clip. The depth level is a stacking order for duplicated movie clips. This stacking order is similar to the stacking order of layers in the Timeline; movie clips with a lower depth level are hidden under clips with a higher stacking order. You must assign each duplicated movie clip a unique depth level to prevent it from replacing SWF files on occupied depths.

Example
In the following example, a new movie clip instance is created called img_mc. An image is loaded into the movie clip, and then the img_mc clip is duplicated. The duplicated clip is called newImg_mc, and this new clip is moved on the Stage so it does not overlap the original clip, and the same image is loaded into the second clip.
this.createEmptyMovieClip("img_mc", this.getNextHighestDepth());
img_mc.loadMovie("http://www.helpexamples.com/flash/images/image1.jpg");
duplicateMovieClip(img_mc, "newImg_mc", this.getNextHighestDepth());
newImg_mc._x = 200;
newImg_mc.loadMovie("http://www.helpexamples.com/flash/images/image1.jpg");
To remove the duplicate movie clip, you could add this code for a button called myButton_btn.
this.myButton_btn.onRelease = function(){
    removeMovieClip(newImg_mc);
};

See also
    removeMovieClip(), MovieClip.duplicateMovieClip(), MovieClip.removeMovieClip()


escape Function

escape(expression:String) : String

Player version:  Flash Player 5

Converts the parameter to a string and encodes it in a URL-encoded format, where all nonalphanumeric characters are replaced with % hexadecimal sequences. When used in a URL-encoded string, the percentage symbol (%) is used to introduce escape characters, and is not equivalent to the modulo operator (%).

Parameters
expression:String — The expression to convert into a string and encode in a URL-encoded format.

Returns
     String — URL-encoded string.

Example
The following code produces the result someuser%40somedomain%2Ecom:
var email:String = "someuser@somedomain.com";
trace(escape(email));
In this example, the at symbol (@) was replaced with %40 and the dot symbol (.) was replaced with %2E. This is useful if you're trying to pass information to a remote server and the data has special characters in it (for example, & or ?), as shown in the following code:
var redirectUrl:String = "http://www.somedomain.com?loggedin=true&username=Gus";
getURL("http://www.myothersite.com?returnurl="+ escape(redirectUrl));

See also
    unescape()


eval Function

eval(expression:Object) : Object
eval(expression:String) : Object

Player version:  Flash Player 5 — Flash Player 5 or later for full functionality. You can use the eval() function when exporting to Flash Player 4, but you must use slash notation and can access only variables, not properties or objects.

Accesses variables, properties, objects, or movie clips by name. If expression is a variable or a property, the value of the variable or property is returned. If expression is an object or movie clip, a reference to the object or movie clip is returned. If the element named in expression cannot be found, undefined is returned.

In Flash 4, eval() was used to simulate arrays; in Flash 5 or later, you should use the Array class to simulate arrays.

In Flash 4, you can also use eval() to dynamically set and retrieve the value of a variable or instance name. However, you can also do this with the array access operator ([]).

In Flash 5 or later, you cannot use eval() to dynamically set and retrieve the value of a variable or instance name, because you cannot useeval() on the left side of an equation. For example, replace the code

eval ("var" + i) = "first";

with this:

this["var"+i] = "first"

or this:

set ("var" + i, "first");

Parameters
expression:Object — The name of a variable, property, object, or movie clip to retrieve. This parameter can be either a String or a direct reference to the object instance (i.e use of quotation marks (" ") is optional.)

Returns
     Object — A value, reference to an object or movie clip, or undefined .

Example
The following example uses eval() to set properties for dynamically named movie clips. This ActionScript sets the _rotation property for three movie clips, called square1_mc, square2_mc, and square3_mc.
for (var i = 1; i <= 3; i++) {
    setProperty(eval("square"+i+"_mc"), _rotation, 5);
}
You can also use the following ActionScript:
for (var i = 1; i <= 3; i++) {
    this["square"+i+"_mc"]._rotation = -5;
}

See also
    Array class, set variable


fscommand Function

fscommand(command:String, parameters:String) : Void

Player version:  Flash Player 3

Lets the SWF file communicate with either Flash Player or the program that is hosting Flash Player, such as a web browser. You can also use the fscommand() function to pass messages to Macromedia Director, or to Visual Basic (VB), Visual C++, and other programs that can host ActiveX controls.

The fscommand() function lets a SWF file communicate with a script in a web page. However, script access is controlled by the web page's allowScriptAccess setting. (You set this attribute in the HTML code that embeds the SWF file—for example, in the PARAM tag for Internet Explorer or the EMBED tag for Netscape. When allowScriptAccess is set to "never", a SWF file cannot access web page scripts. With Flash Player 7 and later, when allowScriptAccess is set to "always", a SWF file can always access web page scripts. When allowScriptAccess is set to "sameDomain", scripting is allowed only from SWF files that are in the same domain as the web page; scripting is always allowed with previous versions of Flash Player. If allowScriptAccess is not specified in an HTML page, the attribute is set by default to "sameDomain" for SWF files of version 8 and later, and to "always" for SWF files of version 7 and earlier.

Usage 1: To use fscommand() to send a message to Flash Player, you must use predefined commands and parameters. The following table shows the values that you can specify for the fscommand() function's command and parameters parameters. These values control SWF files that are playing in Flash Player, including projectors. (A projector is a SWF file saved in a format that can run as a stand-alone application—that is, without Flash Player.)

Command Parameter Purpose
quit None Closes the projector.
fullscreen true or false Specifying true sets Flash Player to full-screen mode. Specifying false returns the player to normal menu view.
allowscale true or false Specifying false sets the player so that the SWF file is always drawn at its original size and never scaled. Specifying true forces the SWF file to scale to 100% of the player.
showmenu true or false Specifying true enables the full set of context menu items. Specifying false hides all of the context menu items except About Flash Player and Settings.
exec Path to application Executes an application from within the projector.
trapallkeys true or false Specifying true sends all key events, including accelerator keys, to the onClipEvent(keyDown/keyUp) handler in Flash Player.

Availability:

The exec command can contain only the characters A-Z, a-z, 0-9, period (.), and underscore (_). The exec command runs in the subdirectory fscommand only. In other words, if you use the exec command to call an application, the application must reside in a subdirectory named fscommand. The exec command works only from within a Flash projector file.

Usage 2: To use fscommand() to send a message to a scripting language such as JavaScript in a web browser, you can pass any two parameters in the command and parameters parameters. These parameters can be strings or expressions, and they are used in a JavaScript function that handles, or catches, the fscommand() function.

In a web browser, fscommand() calls the JavaScript function moviename_DoFScommand, which resides in the web page that contains the SWF file. For moviename, supply the name of the Flash object that you used for the NAMEattribute of the EMBED tag or the ID property of the OBJECT tag. If you assign the SWF file the name myMovie, the JavaScript function myMovie_DoFScommand is called.

In the web page that contains the SWF file, set the allowScriptAccess attribute to allow or deny the SWF file's ability to access the web page. (You set this attribute in the HTML code that embeds the SWF file—for example, in the PARAM tag for Internet Explorer or the EMBED tag for Netscape.) When allowScriptAccess is set to "never", outbound scripting always fails. When allowScriptAccess is set to "always", outbound scripting always succeeds. When it is set to "sameDomain", scripting is allowed only from SWF files that are in the same domain as the web page. If allowScriptAccess is not specified in a web page, it defaults to "sameDomain" for Flash Player 8, and to "always" for previous versions of Flash Player.

When using this function, consider the Flash Player security model. For Flash Player 8, the fscommand() function is not allowed if the calling SWF file is in the local-with-file-system or local-with-network sandbox and the containing HTML page is in an untrusted sandbox. For more information, see the following:

Usage 3: The fscommand() function can send messages to Macromedia Director. These messages are interpreted by Lingo (the Director scripting language) as strings, events, or executable Lingo code. If a message is a string or an event, you must write the Lingo code to receive the message from the fscommand() function and carry out an action in Director. For more information, see the Director Support Center at www.macromedia.com/support/director.

Usage 4: In VisualBasic, Visual C++, and other programs that can host ActiveX controls, fscommand() sends a VB event with two strings that can be handled in the environment's programming language. For more information, use the keywords "Flash method" to search the Flash Support Center at www.macromedia.com/support/flash.

Note: If you are publishing for Flash Player 8 or later, the ExternalInterface class provides better functionality for communication between JavaScript and ActionScript (Usage 2) and between ActionScript and VisualBasic, Visual C++, or other programs that can host ActiveX controls (Usage 4). You should continue to use fscommand() for sending messages to Flash Player (Usage 1) and Macromedia Director (Usage 3).

Parameters
command:String — A string passed to the host application for any use, or a command passed to Flash Player.
parameters:String — A string passed to the host application for any use, or a value passed to Flash Player.

Example
In the following example, fscommand() sets Flash Player to scale the SWF file to the full monitor screen size when the fullscreen_btn or unfullscreen_btn button is released:
this.fullscreen_btn.onRelease = function() {
    fscommand("fullscreen", true);
};

this.unfullscreen_btn.onRelease = function() {
    fscommand("fullscreen", false);
};

The following example applies fscommand() to a button in Flash for the purpose of opening a JavaScript message box in an HTML page. The message itself is sent to JavaScript as the fscommand parameter.

You must add a function to the web page that contains the SWF file. This function, myDocument_DoFSCommand(), waits for an fscommand() call. When fscommand() is triggered in Flash (for example, when a user clicks the button), the command and parameter strings are passed to the myDocument_DoFSCommand()function. You can use the passed strings in your JavaScript or VBScript code in any way you like. In this example, the function contains a conditional if statement that checks to see if the command string is "messagebox". If it is, a JavaScript alert box displays the contents of the fscommand() function's parameters string.

function myDocument_DoFSCommand(command, args) {
    if (command == "messagebox") {
        alert(args);
    }
}
In the Flash document, add fscommand() to a button:
fscommand("messagebox", "This is a message box called from within Flash.")

You can use expressions for the parameters of the fscommand() function, as shown in the following example:

fscommand("messagebox", "Hello, " + name + ", welcome to our website!")

To test the SWF file, select File > Publish Preview > HTML. If you publish your SWF file using the Flash with FSCommand template (in the Publish Settings dialog box, select the HTML tag), Flash inserts the myDocument_DoFSCommand() function automatically. The SWF file's NAME and ID attributes will be the filename. For example, for the file myDocument.fla, the attributes would be set to myDocument.

See also
    ExternalInterface Class


getProperty Function

getProperty(my_mc:Object, property:Object) : Object

Player version:  Flash Player 4

Returns the value of the specified property for the movie clip my_mc.

Parameters
my_mc:Object — The instance name of a movie clip for which the property is being retrieved or a reference to a movie clip for which the property is being retrieved.
property — A property of a movie clip.

Returns
     Object — The value of the specified property.

Example
The following example creates a new movie clip someClip_mc and shows the alpha value (_alpha) for the movie clip someClip_mc in the Output panel:
this.createEmptyMovieClip("someClip_mc", 999);
trace("The alpha of "+getProperty(someClip_mc, _name)+" is: "+getProperty(someClip_mc, _alpha));


getTimer Function

getTimer() : Number

Player version:  Flash Player 4

Returns the number of milliseconds that have elapsed since the SWF file started playing.

Returns
     Number — The number of milliseconds that have elapsed since the SWF file started playing.

Example
In the following example, the getTimer() and setInterval() functions are used to create a simple timer:
this.createTextField("timer_txt", this.getNextHighestDepth(), 0, 0, 100, 22);
function updateTimer():Void {
    timer_txt.text = getTimer();
}

var intervalID:Number = setInterval(updateTimer, 100);


getURL Function

getURL(url:String, [window:String, [method:String]]) : Void

Player version:  Flash Player 4 — The GET and POST options are available only in and later versions.

Loads a document from a specific URL into a window or passes variables to another application at a defined URL. To test this function, make sure the file to be loaded is at the specified location. To use an absolute URL (for example, http://www.myserver.com), you need a network connection.

Parameters
url:String — The URL from which to obtain the document.
window:String [optional] — Specifies the window or HTML frame into which the document should load. You can enter the name of a specific window or select from the following reserved target names:
  • _self specifies the current frame in the current window.
  • _blank specifies a new window.
  • _parent specifies the parent of the current frame.
  • _top specifies the top-level frame in the current window.
method:String [optional] — A GET or POST method for sending variables. If there are no variables, omit this parameter. The GET method appends the variables to the end of the URL, and is used for small numbers of variables. The POST method sends the variables in a separate HTTP header and is used for sending long strings of variables.

Example
This example loads an image into a movie clip. When the image is clicked, a new URL is loaded in a new browser window.
var listenerObject:Object = new Object();
listenerObject.onLoadInit = function(target_mc:MovieClip) {
    target_mc.onRelease = function() {
        getURL("http://www.macromedia.com/software/flash/flashpro/", "_blank");
    };
};
var logo:MovieClipLoader = new MovieClipLoader();
logo.addListener(listenerObject);
logo.loadClip("http://www.helpexamples.com/flash/images/image1.jpg",
    this.createEmptyMovieClip("macromedia_mc", this.getNextHighestDepth()));
In the following example, getURL() is used to send an e-mail message:
myBtn_btn.onRelease = function(){
    getURL("mailto:you@somedomain.com");
};
In the following ActionScript, JavaScript is used to open an alert window when the SWF file is embedded in a browser window (please note that when calling JavaScript with getURL(), the url parameter is limited to 508 characters):
myBtn_btn.onRelease = function(){
    getURL("javascript:alert('you clicked me')");
};
You can also use GET or POST for sending variables. The following example uses GET to append variables to a URL:
var firstName:String = "Gus";
var lastName:String = "Richardson";
var age:Number = 92;
myBtn_btn.onRelease = function() {
    getURL("http://www.macromedia.com", "_blank", "GET");
};
The following ActionScript uses POST to send variables in the HTTP header. Make sure you test your documents in a browser window, because otherwise your variables are sent using GET:
var firstName:String = "Gus";
var lastName:String = "Richardson";
var age:Number = 92;
getURL("http://www.macromedia.com", "_blank", "POST");

See also
    loadVariables(), XML.send(), XML.sendAndLoad()


getVersion Function

getVersion() : String

Player version:  Flash Player 5

Returns a string containing Flash Player version and platform information. The getVersion function returns information only for Flash Player 5 or later versions of Flash Player.

Returns
     String — A string containing Flash Player version and platform information.

Example
The following examples trace the version number of the Flash Player playing the SWF file:
var flashVersion:String = getVersion();
trace(flashVersion);  // output: WIN 8,0,1,0
trace($version);  // output: WIN 8,0,1,0
trace(System.capabilities.version);  // output: WIN 8,0,1,0

The following string is returned by the getVersion function:

WIN 8,0,1,0

This returned string indicates that the platform is Microsoft Windows, and the version number of Flash Player is major version 8, minor version 1 (8.1).

See also
    System.capabilities.os, System.capabilities.version


gotoAndPlay Function

gotoAndPlay([scene:String], frame:Object) : Void

Player version:  Flash Player 2

Sends the playhead to the specified frame in a scene and plays from that frame. If no scene is specified, the playhead goes to the specified frame in the current scene. You can use the scene parameter only on the root Timeline, not within Timelines for movie clips or other objects in the document.

Parameters
scene:String [optional] — A string specifying the name of the scene to which the playhead is sent.
frame:Object — A number representing the frame number, or a string representing the label of the frame, to which the playhead is sent.

Example
In the following example, a document has two scenes: sceneOne and sceneTwo. Scene one contains a frame label on Frame 10 called newFrame and two buttons, myBtn_btn and myOtherBtn_btn. This ActionScript is placed on Frame 1, Scene 1 of the main Timeline.
stop();
myBtn_btn.onRelease = function(){
    gotoAndPlay("newFrame");
};

myOtherBtn_btn.onRelease = function(){
    gotoAndPlay("sceneTwo", 1);
};
When the user clicks the buttons, the playhead moves to the specified location and continues playing.

See also
    MovieClip.goToAndPlay(), nextFrame(), play(), prevFrame()


gotoAndStop Function

gotoAndStop([scene:String], frame:Object) : Void

Player version:  Flash Player 2

Sends the playhead to the specified frame in a scene and stops it. If no scene is specified, the playhead is sent to the frame in the current scene. You can use the scene parameter only on the root Timeline, not within Timelines for movie clips or other objects in the document.

Parameters
scene:String [optional] — A string specifying the name of the scene to which the playhead is sent.
frame:Object — A number representing the frame number, or a string representing the label of the frame, to which the playhead is sent.

Example
In the following example, a document has two scenes: sceneOne and sceneTwo. Scene one contains a frame label on Frame 10 called newFrame, and two buttons, myBtn_btn and myOtherBtn_btn. This ActionScript is placed on Frame 1, Scene 1 of the main Timeline:

stop();

myBtn_btn.onRelease = function(){
    gotoAndStop("newFrame");
};

myOtherBtn_btn.onRelease = function(){
    gotoAndStop("sceneTwo", 1);
};
When the user clicks the buttons, the playhead moves to the specified location and stops.

See also
    MovieClip.gotoAndStop(), stop(), play(), gotoAndPlay()


ifFrameLoaded Function

ifFrameLoaded([scene:String], frame) { 
    statement(s); 
}

Deprecated as of Flash Player 5 — This function has been deprecated. Macromedia recommends that you use the MovieClip._framesloaded property.

Player version:  Flash Player 4

Checks whether the contents of a specific frame are available locally. Use ifFrameLoaded to start playing a simple animation while the rest of the SWF file downloads to the local computer. The difference between using _framesloaded and ifFrameLoaded is that _framesloaded lets you add custom if or else statements.

Parameters
scene:String [optional] — A string that specifies the name of the scene that must be loaded.
frame:Object — The frame number or frame label that must be loaded before the next statement is executed.

See also
    MovieClip._framesloaded, MovieClipLoader.addListener()


int Function

int(value:Number) : Number

Deprecated as of Flash Player 5 — This function was deprecated in favor of Math.round().

Player version:  Flash Player 4

Converts a decimal number to an integer value by truncating the decimal value. This function is equivalent to Math.floor() if the value parameter is positive and Math.ceil() if the value parameter is negative.

Parameters
value:Number — A number to be rounded to an integer.

Returns
     Number — The truncated integer value.

See also
    Math.round(), Math.floor(), Math.ceil()


isFinite Function

isFinite(expression:Object) : Boolean

Player version:  Flash Player 5

Evaluates expression and returns true if it is a finite number or false if it is infinity or negative infinity. The presence of infinity or negative infinity indicates a mathematical error condition such as division by 0.

Parameters
expression:Object — A Boolean value, variable, or other expression to be evaluated.

Returns
     Boolean — A Boolean value.

Example
The following example shows return values for isFinite:
isFinite(56)
// returns true

isFinite(Number.POSITIVE_INFINITY)
//returns false


isNaN Function

isNaN(expression:Object) : Boolean

Player version:  Flash Player 5

Evaluates the parameter and returns true if the value is NaN(not a number). This function is useful for checking whether a mathematical expression evaluates successfully to a number.

Parameters
expression:Object — A Boolean, variable, or other expression to be evaluated.

Returns
     Boolean — A Boolean value.

Example
The following code illustrates return values for the isNaN() function:
trace( isNaN("Tree") );
// returns true

trace( isNaN(56) );
// returns false

trace( isNaN(Number.POSITIVE_INFINITY) )
// returns false
The following example shows how you can use isNAN() to check whether a mathematical expression contains an error:
var dividend:Number;
var divisor:Number;
divisor = 1;
trace( isNaN(dividend/divisor) );
// output: true 
// The output is true because the variable dividend is undefined. 
// Do not use isNAN() to check for division by 0 because it will return false.
// A positive number divided by 0 equals Infinity (Number.POSITIVE_INFINITY).
// A negative number divided by 0 equals -Infinity (Number.NEGATIVE_INFINITY).

See also
    NaN, Number.Nan


length Function

length(expression:String)
length(variable)

Deprecated as of Flash Player 5 — This function, along with all the string functions, has been deprecated. Macromedia recommends that you use the methods of the String class and the String.length property to perform the same operations.

Player version:  Flash Player 4

Returns the length of the specified string or variable.

Parameters
expression:String — A string.
variable:Object — The name of a variable.

Returns
     Number — The length of the specified string or variable.

Example
The following example returns the length of the string "Hello":
length("Hello");
The result is 5.

See also
    " " (string delimiter), String class, String.length


loadMovie Function

loadMovie(url:String, target:Object, [method:String]) : Void
loadMovie(url:String, target:String, [method:String]) : Void

Player version:  Flash Player 3 — The ability to load JPEG files is available as of Flash Player 6. The ability to load unanimated GIF files, PNG files, or progressive JPEG files is available as of Flash Player 8.

Loads a SWF, JPEG, GIF, or PNG file into a movie clip in Flash Player while the original SWF file is playing. Support for unanimated GIF files, PNG files, and progressive JPEG files is added in Flash Player 8. If you load an animated GIF, only the first frame is displayed.

Tip: If you want to monitor the progress of the download, use MovieClipLoader.loadClip() instead of this function.

The loadMovie() function lets you display several SWF files at once and switch among SWF files without loading another HTML document. Without the loadMovie() function, Flash Player displays a single SWF file.

If you want to load a SWF or JPEG file into a specific level, use loadMovieNum() instead of loadMovie().

When a SWF file is loaded into a target movie clip, you can use the target path of that movie clip to target the loaded SWF file. A SWF file or image loaded into a target inherits the position, rotation, and scale properties of the targeted movie clip. The upper left corner of the loaded image or SWF file aligns with the registration point of the targeted movie clip. Alternatively, if the target is the root Timeline, the upper left corner of the image or SWF file aligns with the upper left corner of the Stage.

Use unloadMovie() to remove SWF files that were loaded with loadMovie().

When using this function, consider the Flash Player security model.

For Flash Player 8:

For Flash Player 7 and later:

For more information, see the following:

Parameters
url:String — The absolute or relative URL of the SWF or JPEG file to be loaded. A relative path must be relative to the SWF file at level 0. Absolute URLs must include the protocol reference, such as http:// or file:///.
target:Object — A reference to a movie clip object or a string representing the path to a target movie clip. The target movie clip is replaced by the loaded SWF file or image.
method:String [optional] — Specifies an HTTP method for sending variables. The parameter must be the string GET or POST . If there are no variables to be sent, omit this parameter. The GET method appends the variables to the end of the URL and is used for small numbers of variables. The POST method sends the variables in a separate HTTP header and is used for long strings of variables.

Example
Usage 1: The following example loads the SWF file circle.swf from the same directory and replaces a movie clip called mySquare that already exists on the Stage:
loadMovie("circle.swf", mySquare);
// equivalent statement (Usage 1): loadMovie("circle.swf", _level0.mySquare);
// equivalent statement (Usage 2): loadMovie("circle.swf", "mySquare");
The following example loads the SWF file circle.swf from the same directory, but replaces the main movie clip instead of the mySquare movie clip:
loadMovie("circle.swf", this);
// Note that using "this" as a string for the target parameter will not work
// equivalent statement (Usage 2): loadMovie("circle.swf", "_level0");
The following loadMovie() statement loads the SWF file sub.swf from the same directory into a new movie clip called logo_mc that's created using createEmptyMovieClip():
this.createEmptyMovieClip("logo_mc", 999);
loadMovie("sub.swf", logo_mc);
You could add the following code to load a JPEG image called image1.jpg from the same directory as the SWF file loading sub.swf. The JPEG is loaded when you click a button called myBtn_btn. This code loads the JPEG into logo_mc. Therefore, it will replace sub.swf with the JPEG image.
myBtn_btn.onRelease = function(){
    loadMovie("image1.jpg", logo_mc);
};
Usage 2: The following example loads the SWF file circle.swf from the same directory and replaces a movie clip called mySquare that already exists on the Stage:
loadMovie("circle.swf", "mySquare");

See also
    _level, loadMovieNum(), MovieClip.loadMovie(), MovieClipLoader.loadClip(), unloadMovie()


loadMovieNum Function

loadMovieNum(url:String, level:Number, [method:String]) : Void

Player version:  Flash Player 4 — Flash 4 files opened in Flash 5 or later are converted to use the correct syntax. The ability to load JPEG files is available as of Flash Player 6. The ability to load unanimated GIF files, PNG files, or progressive JPEG files is available as of Flash Player 8.

Loads a SWF, JPEG, GIF, or PNG file into a level while the original SWF file is playing. Support for unanimated GIF files, PNG files, and progressive JPEG files is added in Flash Player 8. If you load an animated GIF, only the first frame is displayed.

Tip: If you want to monitor the progress of the download, use MovieClipLoader.loadClip() instead of this function.

Normally, Flash Player displays a single SWF file and then closes. The loadMovieNum() action lets you display several SWF files at once and switch among SWF files without loading another HTML document.

If you want to specify a target instead of a level, use loadMovie() instead of loadMovieNum().

Flash Player has a stacking order of levels starting with level 0. These levels are like layers of acetate; they are transparent except for the objects on each level. When you use loadMovieNum(), you must specify a level in Flash Player into which the SWF file will load. When a SWF file is loaded into a level, you can use the syntax, _levelN, where N is the level number, to target the SWF file.

When you load a SWF file, you can specify any level number and you can load SWF files into a level that already has a SWF file loaded into it. If you do, the new SWF file will replace the existing SWF file. If you load a SWF file into level 0, every level in Flash Player is unloaded, and level 0 is replaced with the new file. The SWF file in level 0 sets the frame rate, background color, and frame size for all other loaded SWF files.

The loadMovieNum() action also lets you load JPEG files into a SWF file while it plays. For images and SWF files, the upper left corner of the image aligns with the upper left corner of the Stage when the file loads. Also in both cases, the loaded file inherits rotation and scaling, and the original content is overwritten in the specified level.

Note: JPEG files saved in progressive format are not supported.

Use unloadMovieNum() to remove SWF files or images that were loaded with loadMovieNum().

When using this method, consider the Flash Player security model.

For Flash Player 8:

For Flash Player 7 and later:

For more information, see the following:

Parameters
url:String — The absolute or relative URL of the SWF or JPEG file to be loaded. A relative path must be relative to the SWF file at level 0. For use in the stand-alone Flash Player or for testing in test mode in the Flash authoring application, all SWF files must be stored in the same folder and the filenames cannot include folder or disk drive specifications.
level:Number — An integer specifying the level in Flash Player into which the SWF file will load.
method:String [optional] — Specifies an HTTP method for sending variables. The parameter must be the string GET or POST . If there are no variables to be sent, omit this parameter. The GET method appends the variables to the end of the URL and is used for small numbers of variables. The POST method sends the variables in a separate HTTP header and is used for long strings of variables.

Example
The following example loads the JPEG image tim.jpg into level 2 of Flash Player:

loadMovieNum("http://www.helpexamples.com/flash/images/image1.jpg", 2);

See also
    unloadMovieNum(), loadMovie(), MovieClipLoader.loadClip(), _level


loadVariables Function

loadVariables(url:String, target:Object, [method:String]) : Void

Player version:  Flash Player 4 — Behavior changed in Flash Player 7.

Reads data from an external file, such as a text file or text generated by ColdFusion, a CGI script, Active Server Pages (ASP), PHP, or Perl script, and sets the values for variables in a target movie clip. This action can also be used to update variables in the active SWF file with new values.

The text at the specified URL must be in the standard MIME format application/x-www-form-urlencoded (a standard format used by CGI scripts). Any number of variables can be specified. For example, the following phrase defines several variables:

company=Macromedia&address=600+Townsend&city=San+Francisco&zip=94103

In SWF files running in a version earlier than Flash Player 7, url must be in the same superdomain as the SWF file that is issuing this call. A superdomain is derived by removing the leftmost component of a file's URL. For example, a SWF file at www.someDomain.com can load data from a source at store.someDomain.com because both files are in the same superdomain of someDomain.com.

In SWF files of any version running in Flash Player 7 or later, url must be in exactly the same domain as the SWF file that is issuing this call (see "Flash Player security features" in Using ActionScript in Flash). For example, a SWF file at www.someDomain.com can load data only from sources that are also at www.someDomain.com. If you want to load data from a different domain, you can place a cross-domain policy file on the server hosting the SWF file that is being accessed. For more information, see "About allowing cross-domain data loading" in Using ActionScript in Flash.

If you want to load variables into a specific level, use loadVariablesNum() instead of loadVariables().

Parameters
url:String — An absolute or relative URL where the variables are located. If the SWF file issuing this call is running in a web browser, url must be in the same domain as the SWF file; for details, see the Description section.
target:Object — The target path to a movie clip that receives the loaded variables.
method:String [optional] — Specifies an HTTP method for sending variables. The parameter must be the string GET or POST . If there are no variables to be sent, omit this parameter. The GET method appends the variables to the end of the URL and is used for small numbers of variables. The POST method sends the variables in a separate HTTP header and is used for long strings of variables.

Example
The following example loads information from a text file called params.txt into the target_mc movie clip that is created using createEmptyMovieClip(). The setInterval() function is used to check the loading progress. The script checks for a variable in the params.txt file named done.
this.createEmptyMovieClip("target_mc", this.getNextHighestDepth());
loadVariables("params.txt", target_mc);
function checkParamsLoaded() {
    if (target_mc.done == undefined) {
        trace("not yet.");
    } else {
        trace("finished loading. killing interval.");
        trace("-------------");
        for (i in target_mc) {
            trace(i+": "+target_mc[i]);
        }
        trace("-------------");
        clearInterval(param_interval);
    }
}
var param_interval:Number = setInterval(checkParamsLoaded, 100);

The external file, params.txt, includes the following text:

var1="hello"&var2="goodbye"&done="done"

See also
    loadVariablesNum(), loadMovie(), loadMovieNum(), getURL(), MovieClip.loadMovie(), MovieClip.loadVariables(), LoadVars.load()


loadVariablesNum Function

loadVariablesNum(url:String, level:Number, [method:String]) : Void

Player version:  Flash Player 4 — Behavior changed in Flash Player 7. Flash 4 files opened in Flash 5 or later are converted to use the correct syntax.

Reads data from an external file, such as a text file or text gener