03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A reference to the global object that holds the core ActionScript classes, such as String,<br />

Object, Math, <strong>and</strong> Array. For example, you could create a library that is exposed as a global<br />

ActionScript object, similar to the Math or Date object. Unlike Timeline-declared or locally<br />

declared variables <strong>and</strong> functions, global variables <strong>and</strong> functions are visible to every timeline<br />

<strong>and</strong> scope in the SWF file, provided they are not obscured by identifiers with the same names<br />

in inner scopes.<br />

Note: When setting the value of a global variable, you must use the fully qualified name of the<br />

variable, for instance, _global.variableName. Failure to do so creates a local variable of the<br />

same name that obscures the global variable you are attempting to set.<br />

ReturnsA reference to the global object that holds the core ActionScript classes, such as<br />

String, Object, Math, <strong>and</strong> Array.<br />

Example<br />

The following example creates a top-level function, factorial(), that is available to every<br />

timeline <strong>and</strong> scope in a SWF file:<br />

_global.factorial = function(n:Number) {<br />

if (n&lt;=1) {<br />

return 1;<br />

} else {<br />

return n*factorial(n-1);<br />

}<br />

}<br />

// Note: factorial 4 == 4*3*2*1 == 24<br />

trace(factorial(4)); // output: 24<br />

The following example shows how the failure to use the fully qualified variable name when<br />

setting the value of a global variable leads to unexpected results:<br />

_global.myVar = "global";<br />

trace("_global.myVar: " + _global.myVar); // _global.myVar: global<br />

trace("myVar: " + myVar); // myVar: global<br />

myVar = "local";<br />

trace("_global.myVar: " + _global.myVar); // _global.myVar: global<br />

trace("myVar: " + myVar); // myVar: local<br />

See also<br />

set variable statement<br />

_highquality property<br />

_highquality<br />

Deprecated since Flash Player 5. This property was deprecated in favor of _quality.<br />

98 ActionScript language elements

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!