User Guide
552 ActionScript classes
Returns
Boolean - If the call succeeded, returns true. If it failed because the instance was not
available, a security restriction was encountered, there was no such function object, a
recursion occurred, or something similar, returns
false.
A return value of
false may also mean that the containing environment belongs to a security
sandbox to which the calling code does not have access. You can work around this problem by
setting an appropriate value for the
allowScriptAccessOBJECT tag or EMBED tag in the
HTML of the containing environment.
Example
The following example registers the
goToMacromedia() function as callable from the
container with the name
goHome.
import flash.external.*;
var methodName:String = "goHome";
var instance:Object = null;
var method:Function = goToMacromedia;
var wasSuccessful:Boolean = ExternalInterface.addCallback(methodName,
instance, method);
var txtField:TextField = this.createTextField("txtField",
this.getNextHighestDepth(), 0, 0, 200, 50);
txtField.border = true;
txtField.text = wasSuccessful.toString();
function goToMacromedia() {
txtField.text = "http://www.macromedia.com";
getURL("http://www.macromedia.com", "_self");
}
For the previous example to work properly, you should copy and paste the following code into
the containing HTML page. This code relies on the
id attribute of the OBJECT tag and the
name attribute of the EMBED tag to have the value externalInterfaceExample. The function
thisMovie returns the appropriate syntax depending on the browser, since Internet Explorer
and Netscape refer to the movie object differently. Unless the HTML page is hosted on a
server, your browser may alert you with a security warning.
<form>
<input type="button" onclick="callExternalInterface()" value="Call
ExternalInterface" />
NOTE
Avoid using other methods of accessing the plug-in object, such as
document.getElementByID(“pluginName”) or document.all.pluginName, because these
other methods do not work consistantly across all browsers.