The ExternalInterface ClassThe ExternalInterface class is designed to be able to communicate with external functionality such as JavaScript. It is important that when using this class to import it first at the beginning of your script, like this: import flash.external.ExternalInterface; PropertiesavailableAvailability: FP:8, AS:1.0 Generic Template: ExternalInterface.available; Description: The property indicates whether the player it is residing in is capable of offering an external interface; true if yes and false if no. Example: This example will send to the Output panel the availability status of an external interface: import flash.external.ExternalInterface; trace(ExternalInterface.available); MethodsaddCallbackAvailability: FP:8, AS:1.0 Generic Template: ExternalInterface.addCallback(nickName, instance, function); Returns: Boolean This will indicate if the call succeeded. If it did not, check the allScriptAccess attribute in both the OBJECT and EMBED tags to make sure you are not in a security violation. Parameters:
Description: This method will add the capability for an external interface to be able to call a function on the Flash timeline. Example: This example will send to the Output panel the availability status of an external interface: import flash.external.ExternalInterface; //the function function visitSams() { getURL("http://www.sams.com", "_blank"); } //add the callback ExternalInterface.addCallback("visitSams", this, visitSams); And then in the HTML, you might have something like this: <script> function goOut() { document.getElementById("visitSams").flash.visitSams(); } </script> <form> <input type="button" onclick="goOut()" value="Go to Sams" /> </form> NOTE When setting up the JavaScript to call the Flash function, you must make sure the id attribute of the object tag and the name attribute of the embed tag are set to the same thing. callAvailability: FP:8, AS:1.0 Generic Template: ExternalInterface.call(function, parameters); Returns: Object This will be the response from the external function being called if there is one. If there is no return value, or the method failed, null will be returned. Parameters:
Description: This method will allow Flash to call functions in the external interface as well as pass parameters to them. Example: This example will call the alert function in JavaScript, passing it a simple string: import flash.external.ExternalInterface; //send an alert ExternalInterface.call("alert", "there is an alert"); Again, if this does not work at first, check the allowScriptAccess attribute in your HTML. |