View comments | RSS feed

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()).

Global Functions summary

Modifiers

Signature

Description

 

Array([numElements:Number], [elementN:Object])

Creates a new, empty array or converts specified elements to an array.

 

asfunction(function:String, parameter:String)

A special protocol for URLs in HTML text fields that allows an HREF link to call an ActionScript function.

 

Boolean(expression:Object)

Converts the parameter expression to a Boolean value and returns true or false.

 

call(frame:Object)

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

Executes the script in the called frame without moving the playhead to that frame.

 

chr(number:Number)

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

Converts ASCII code numbers to characters.

 

clearInterval(intervalID:Number)

Stops the setInterval() call.

 

duplicateMovieClip(target:Object, newname:String, depth:Number)

Creates an instance of a movie clip while the SWF file is playing.

 

escape(expression: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)

Accesses variables, properties, objects, or movie clips by name.

 

fscommand(command:String, parameters:String)

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)

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

 

getTimer()

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

 

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

Loads a document from a specific URL into a window or passes variables to another application at a defined URL.

 

getVersion()

Returns a string containing Flash Player version and platform information.

 

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

Sends the playhead to the specified frame in a scene and plays from that frame.

 

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

Sends the playhead to the specified frame in a scene and stops it.

 

ifFrameLoaded([scene:String], frame:Object)

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

Checks whether the contents of a specific frame are available locally.

 

int(value:Number)

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

Converts a decimal number to an integer value by truncating the decimal value.

 

isFinite(expression:Object)

Evaluates expression and returns true if it is a finite number or false if it is infinity or negative infinity.

 

isNaN(expression:Object)

Evaluates the parameter and returns true if the value is NaN (not a number).

 

length(expression:String, variable:Object)

Deprecated since 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.

Returns the length of the specified string or variable.

 

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

Loads a SWF or JPEG file into Flash Player while the original SWF file plays.

 

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

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])

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])

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)

Deprecated since Flash Player 5. This function was deprecated in favor of the String.fromCharCode() method.

Converts an ASCII code number to a multibyte character.

 

mblength(string:String)

Deprecated since Flash Player 5. This function was deprecated in favor of the methods and properties of the String class.

Returns the length of the multibyte character string.

 

mbord(character:String)

Deprecated since Flash Player 5. This function was deprecated in favor of String.charCodeAt().

Converts the specified character to a multibyte number.

 

mbsubstring(value:String, index:Number, count:Number)

Deprecated since Flash Player 5. This function was deprecated in favor of String.substr().

Extracts a new multibyte character string from a multibyte character string.

 

MMExecute(command:String)

Lets you issue Flash JavaScript API (JSAPI) commands from ActionScript.

 

nextFrame()

Sends the playhead to the next frame.

 

nextScene()

Sends the playhead to Frame 1 of the next scene.

 

Number(expression:Object)

Converts the parameter expression to a number.

 

Object([value:Object])

Creates a new empty object or converts the specified number, string, or Boolean value to an object.

 

on(mouseEvent:Object)

Specifies the mouse event or keypress that triggers an action.

 

onClipEvent(movieEvent:Object)

Triggers actions defined for a specific instance of a movie clip.

 

ord(character:String)

Deprecated since Flash Player 5. This function was deprecated in favor of the methods and properties of the String class.

Converts characters to ASCII code numbers.

 

parseFloat(string:String)

Converts a string to a floating-point number.

 

parseInt(expression:String, [radix:Number])

Converts a string to an integer.

 

play()

Moves the playhead forward in the Timeline.

 

prevFrame()

Sends the playhead to the previous frame.

 

prevScene()

Sends the playhead to Frame 1 of the previous scene.

 

print(target:Object, boundingBox:String)

Prints the target movie clip according to the boundaries specified in the parameter (bmovie, bmax, or bframe).

 

printAsBitmap(target:Object, boundingBox:String)

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)

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)

Prints the level in Flash Player according to the boundaries specified in the boundingBox parameter (bmovie, bmax, bframe).

 

random(value:Number)

Deprecated since Flash Player 5. This function was deprecated in favor of Math.random().

Returns a random integer between 0 and one less than the integer specified in the <code><em>value</em></code>&#160;parameter.

 

removeMovieClip(target:Object)

Deletes the specified movie clip.

 

setInterval(functionReference:Function, interval:Number, [param:Object], objectReference:Object, methodName:String)

Calls a function or a method of an object at periodic intervals while a SWF file plays.

 

setProperty(target:Object, property:Object, expression:Object)

Changes a property value of a movie clip as the movie clip plays.

 

showRedrawRegions(enable:Boolean, [color:Number])

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])

Makes the target movie clip draggable while the movie plays.

 

stop()

Stops the SWF file that is currently playing.

 

stopAllSounds()

Stops all sounds currently playing in a SWF file without stopping the playhead.

 

stopDrag()

Stops the current drag operation.

 

String(expression:Object)

Returns a string representation of the specified parameter.

 

substring(string:String, index:Number, count:Number)

Deprecated since Flash Player 5. This function was deprecated in favor of String.substr().

Extracts part of a string.

 

targetPath(targetObject:Object)

Returns a string containing the target path of movieClipObject.

 

tellTarget(target:String, statement(s))

Deprecated since Flash Player 5. Macromedia recommends that you use dot (.) notation and the with statement.

Applies the instructions specified in the statements parameter to the Timeline specified in the target parameter.

 

toggleHighQuality()

Deprecated since Flash Player 5. This function was deprecated in favor of _quality.

Turns anti-aliasing on and off in Flash Player.

 

trace(expression:Object)

Evaluates the expression and outputs the result.

 

unescape(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)

Removes a movie clip that was loaded by means of loadMovie() from Flash Player.

 

unloadMovieNum(level:Number)

Removes a SWF or image that was loaded by means of loadMovieNum() from Flash Player.

 

updateAfterEvent()

Updates the display when you call it within an handler or using setInterval().


Version 8

Comments


Francis Cheng said on Sep 13, 2005 at 11:57 AM :
The setTimeout() and clearTimeout() global functions were inadvertently omitted from the documentation. The setTimeout() function allows you to create a one-time only timer. It is similar to the setInterval() function, except that setTimeout() will call the specified function once, while setInterval() calls the specified function repeatedly.

-------

function setTimeout (functionReference:Object, delay:Number, args:Object) : Number;

functionReference:Object -- The name of the function to execute. Do not include quotation marks or

parentheses, and do not specify

delay:Number -- The delay, in milliseconds, until the function is executed.

args:Object -- Zero or more arguments, separated by commas, to be passed to the function.

Returns a Number that can be used as an argument to clearTimeout() to cancel the function call.

-------

function clearTimeout(id:Number) : Void;

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

-------

Example using both setTimeout() and clearTimeout()

The following example uses setTimeout() to call a function named my_delayedFunction after a two second delay, and uses the return value to call clearTimeout() if the user presses the Spacebar. The example will output the string "two second delay" after two seconds has elapsed, unless the user presses the Spacebar before my_delayedFunction is called.

var my_timedProcess:Number = setTimeout(my_delayedFunction, 2000, "two second delay");

function my_delayedFunction (arg1) {
trace(arg1);
}

var escListener:Object = new Object();
escListener.onKeyDown = function() {
if (Key.isDown(Key.SPACE)) {
clearTimeout(my_timedProcess);
}
};
Key.addListener(escListener);
maciekw said on Sep 15, 2005 at 8:52 AM :
unfortunately using setTimeout in external classes is not so easy, because of lack of intrinsic function declaration in toplevel.as

You can do it two ways:
1. call
_global.setTimeout()
_global.clearInterval()
instead
2. edit toplevel.as
(C:\Program Files\Macromedia\Flash 8\en\First Run\Classes on my computer)
and add two lines
intrinsic function clearTimeout(id:Number):Void;
intrinsic function setTimeout():Number;

before #endinitclip directive
maciekw said on Sep 16, 2005 at 2:47 AM :
also use setTimeout in external classes in the second form (exactly as setInterval)

setTimeout(scope:Object, funcName:String, miliSec:Number);
paulneave said on Sep 16, 2005 at 7:20 AM :
Is there any chance setTimeout could be added to the Flash 8 Help docs - it's currently omitted by the looks of it (searching for 'timeout' only brings up the Camera object at the moment).

Thanks.
dwabyick said on Nov 22, 2005 at 12:06 PM :
It seems like this API is slightly flawed, as setTimeout doesn't allow you to specify a "this" object, like the second form of setInterval For example, setInterval( this, "myfunc", 1000);

This can be worked around by passing "this" in the arguments, I guess. But still its a bummer.
Southern Sun said on Feb 25, 2006 at 7:15 PM :
This si the AS3 documentation of SetTimeout:

http://livedocs.macromedia.com/labs/1/flex/langref/flash/util/package.html#setTimeout()
Captain James said on Apr 7, 2006 at 8:54 AM :
It appears that clearInterval() and clearTimeout() can be used interchangeably:

var idTimeout:Number = setTimeout (myFunction, 1000);
clearInterval (idTimeout);

OR:

var idInterval:Number = setInterval (myFunction, 1000);
clearTimeout (idInterval);

Both situations work. Not sure how bad the potential for conflicts is, but I thought it warranted mentioning.
bribishop@hotmail.com said on Jan 29, 2007 at 3:45 PM :
In response to dwabyick, you can specify a 'this' pointer in leiu of setInterval's second usage [ie, "setInterval( this, "myfunc", 1000)"] by doing the following:

setTimeout(mx.utils.Delegate.create(this, this.myfunc), 1000, args);

checkout the documentation on mx.utils.Delegate.create() for more information.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001717.html