User Guide

ExternalInterface (flash.external.ExternalInterface) 549
Example
In the following example, a function throws an error (with a specified message) if the two
strings that are passed to it are not identical:
function compareStrings(str1_str:String, str2_str:String):Void {
if (str1_str != str2_str) {
throw new Error("Strings do not match.");
}
}
try {
compareStrings("Dog", "dog");
// output: Strings do not match.
} catch (e_err:Error) {
trace(e_err.toString());
}
See also
message (Error.message property), throw statement, try..catch..finally
statement
ExternalInterface
(flash.external.ExternalInterface)
Object
|
+-flash.external.ExternalInterface
public class ExternalInterface
extends Object
The ExternalInterface class is the External API, an application programming interface that
enables straightforward communication between ActionScript and the Flash Player container;
for example, an HTML page with JavaScript, or a desktop application with Flash Player
embedded.
ExternalInterface is similar in functionality to the
fscommand(), CallFrame() and
CallLabel() methods, but is more flexible and more generally applicable. Use of
ExternalInterface is recommended for JavaScript-ActionScript communication.
From ActionScript, you can call any JavaScript function on the HTML page, passing any
number of arguments of any data type, and receive a return value from the call.
From JavaScript on the HTML page, you can call an ActionScript function in Flash Player.
The ActionScript function can return a value, and JavaScript receives it immediately as the
return value of the call.