Archived:Using the externalInterface class of Flash in WRT
Article Metadata
Code Example
Source file: Media:externalInterfaceExample.zip
Article
Created: Risalmin
(15 Sep 2010)
Last edited: hamishwillee
(26 Jul 2012)
This draft document will describe how to use the externalInterface class in Adobe Flash for communicating between a Web Runtime Widget (JavaScript) and a Flash SWF (ActionScript). A good example of such implementation is the On demand Web TV – have your favorite channels with you
Contents |
HTML
Add an id to the Flash object's embed tag:
<object
id='swfObject'
height='100%'
width='100%'
data='myFlashApp.swf'
allowscriptaccess='always'
allowFullScreen='true'
usefullscreen='true'
type='application/x-shockwave-flash'
loop='false'
name='swfObject'>
<param name="canHandleException" value="true" />
</object>
ActionScript
ActionScript 2
//required to use the externalinterface class
import flash.external.*;
//Add a function call that can be accessed from javascript
ExternalInterface.addCallback("hello",this, hello);
//and the actual function
function hello(){
//do something
}
ActionScript 3
//required to use the externalinterface class
import flash.external.*;
//Add a function call that can be accessed from javascript
ExternalInterface.addCallback("hello", hello);
//and the actual function
function hello(){
//do something
}
Calling the function in Flash from JavaScript
function hello() {
document.getElementById("swfObject").hello();
}
Example implementation
You can download an example FLA and WRT widget from this link

