How to use ExternalInterface to integrate AS3 with JavaScript

Here's a quick snippet of code for integrating your SWFs with JavaScript, using ExternalInterface:

Actionscript:
  1. import flash.external.ExternalInterface;
  2.  
  3. // Calling a JavaScript function from AS3 (with optional parameters)
  4. if (ExternalInterface.available) ExternalInterface.call("javascriptFunction", param1, param2);
  5.  
  6. // Implementing a JavaScript callback in AS3 (flashFunction is called when JavaScript calls javascriptFunction)
  7. if (ExternalInterface.available) ExternalInterface.addCallback("javascriptFunction", flashFunction);

About Liam

Creative developer and webmaster of spikything.com
This entry was posted in AS3, Flash and tagged , , , , , . Bookmark the permalink.

Leave a Reply