User Guide
504 Using the External API
Getting information about the external container
The ExternalInterface.available property indicates whether the current Flash Player is
in a container that offers an external interface. If the external interface is available, this
property is
true; otherwise, it is false. Before using any of the other functionality in the
ExternalInterface class, you should always check to make sure that the current container
supports external interface communication, as follows:
if (ExternalInterface.available)
{
// Perform ExternalInterface method calls here.
}
The ExternalInterface.objectID property allows you to determine the unique identifier
of the Flash Player instance (specifically, the
id attribute of the <object> tag in Internet
Explorer or the
name attribute of the <embed> tag in browsers using the NPRuntime
interface). This unique ID represents the current SWF document in the browser, and can be
used to make reference to the SWF document—for example, when calling a JavaScript
function in a container HTML page. When the Flash Player container is not a web browser,
this property is
null.
Calling external code from ActionScript
The ExternalInterface.call() method executes code in the container application. It
requires at least one parameter, a string containing the name of the function to be called in the
container application. Any additional parameters passed to the
ExternalInterface.call()
method are passed along to the container as parameters of the function call.
// calls the external function "addNumbers"
// passing two parameters, and assigning that function's result
// to the variable "result"
var param1:uint = 3;
var param2:uint = 7;
var result:uint = ExternalInterface.call("addNumbers", param1, param2);
NOTE
The ExternalInterface.available property reports whether the current container is a
type that supports ExternalInterface connectivity. It will not tell you if JavaScript is
enabled in the current browser.