User Guide
Using the ExternalInterface class 505
If the container is an HTML page, this method invokes the JavaScript function with the
specified name, which must be defined in a
<script> element in the containing HTML
page. The return value of the JavaScript function is passed back to ActionScript.
<script language="JavaScript">
// adds two numbers, and sends the result back to ActionScript
function addNumbers(num1, num2)
{
return (num1 + num2);
}
</script>
If the container is some other ActiveX container, this method causes the Flash Player ActiveX
control to dispatch its
FlashCall event. The specified function name and any parameters are
serialized into an XML string by Flash Player. The container can access that information in
the
request property of the event object and use it to determine how to execute its own code.
To return a value to ActionScript, the container code calls the ActiveX object’s
SetReturnValue() method, passing the result (serialized into an XML string) as a parameter
of that method. For more information about the XML format used for this communication,
see “The External API’s XML format” on page 522.
Whether the container is a web browser or another ActiveX container, if the call fails or the
container method does not specify a return value,
null is returned. The
ExternalInterface.call() method throws a SecurityError exception if the containing
environment belongs to a security sandbox to which the calling code does not have access. You
can work around this by setting an appropriate value for
allowScriptAccess in the
containing environment. For example, to change the value of
allowScriptAccess in an
HTML page, you would edit the appropriate attribute in the
<object> and <embed> tags.