Understanding ExternalInterface in Flash 8
Listen to this article
:: Talkr
What is ExternalInterface?
ExternalInterface (flash.external.ExternalInterface) is a set of API which lets you communicate seamlessly between ActionScript and the Flash Player container. The container can be a HTML page containing some JavaScript functions, a Visual Basic or VC++ wrapper or a 3rd party desktop application which has Flash player embedded in it. The concept is very similar to using fscommand to communicate with JavaScript but ExternalInterface is more flexible and powerful than fscommand. With ExternalInterface you can call a JavaScript function from Flash and send any number of arguments in most of the data types like Boolean, String, Numbers etc., and the JavaScript function can send data back to Flash and is received by Flash almost immediately.
For a matrix of Browser - OS support look at the table in the livedocs here.
Properties & Methods in ExternalInterface Class
Properties :
public static available : Boolean [read-only]
Usage:
var isAvailable:Boolean = ExternalInterface.available;
Methods:
public static addCallback(methodName:String, instance:Object, method:Function) : Boolean
Usage:
ExternalInterface.addCallback("flAlert", null, showAlert);
In this case flAlert is not the actual function which is written inside Flash but a friendly name which the JavaScript or the host application can call to invoke the actual function ( in this case showAlert) which is written in Flash.
**Note** : This method returns a Boolean value of true if the call was successful and false if it fails. The reason for failure may be due to a non-existent function, a security sandbox restriction or some other error. The LiveDocs page for ExternalInterface has some comments to the problem people are facing with and some answers to them.
public static call(methodName:String, [parameter1:Object]) : Object
This method is used to call a function defined in the host application.
Usage:
ExternalInterface.call("jsAlert", "Welcome");
This method returns an Object which is the response received from the host application.
To summarize addCallback method is used to communicate FROM the host application TO flash and the call method is used to communicate FROM flash TO the host communication.

You can see a simple example here.
Download the example files here.
The FLA file has extensive inline comments to understand what is going on. If you still have doubts leave a comment and I will answer.
Related readings:
ExternalInterface (flash.external.ExternalInterface)
Simplecart and External Interface (Flash 8)
External Interface example @ deconcept
JavaScript Integration in Flash 8
Questions & Comments
Hi,
I downloaded your source files for this example but it does not work. However, the page from the link you provided works. The html code for both the downloaded and the one up online is exactly the same. Why is that?
Thanks,
Jeff
Posted by: Jeff | February 18, 2006 12:16 AM
to jeff.
The demo can only be ok when you are running it under a "http" proctol.
BTW, to the host of this site, can I get some examples of VC++ and Flash
's commnuication with "ExternalInterface"?
I saw some documents of SW , it's too hard for me, so would u please support an example of "hello world"...
Posted by: Awflasher | March 2, 2006 11:38 PM