Using the ExternalInterface API to access JavaScript from Flex

The easiest way to call JavaScript functions from your Flex application is to use the ExternalInterface API. You can use this API to call any JavaScript method on the wrapper, pass parameters, and get a return value. If the method call fails, Flex returns an exception.

The ExternalInterface API encapsulates checks for browser support, so you are not required to do that when using its methods. However, you can check whether the browser supports the interface by using its available property. For more information, see About the ExternalInterface API.

The ExternalInterface API consists of a single class, flash.external.ExternalInterface. This class has the call() static method that you use to facilitate the JavaScript to Flash communication. You can also call methods in your Flex application from the wrapper by using the ExternalInterface API's addCallback() method. For more information, see About the addCallback() method.

To use the ExternalInterface, you must make the id and name properties in the HTML page callable. For more information, see Editing the Flex application's id and name properties.

Subtopics

Calling JavaScript methods from Flex applications

Flex 2.01

Take a survey