518
Chapter 26: Using the external API
The ActionScript™ 3.0 external API enables straightforward communication between ActionScript and the container
application within which Adobe® Flash™ Player 9 or Adobe® AIR™ is running. There are several situations in which
you may want to use the external API—for example, when you create interaction between a SWF document and
JavaScript in an HTML page, or when you build a desktop application that uses Flash Player or AIR to display a SWF
file.
This chapter describes how to use the external API to interact with a container application, how to pass data between
ActionScript and JavaScript in an HTML page, and how to establish communication and exchange data between
ActionScript and a desktop application.
Note: This chapter only covers communication between ActionScript in a SWF and the container application that
includes a reference to the Flash Player or instance in which the SWF is loaded. Any other use of Flash Player within an
application is outside the scope of this documentation. Flash Player is designed to be used as a browser plug-in or as a
projector (standalone application). Other usage scenarios may have limited support.
Contents
Basics of using the external API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
External API requirements and advantages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
Using the ExternalInterface class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520
Example: Using the external API with a web page container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524
Example: Using the external API with an ActiveX container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
Basics of using the external API
Introduction to using the external API
Although in some cases a SWF file can run on its own (for example, if you create a SWF projector), in the majority
of cases a SWF application runs as an element inside of another application. Commonly, the container that includes
the SWF is an HTML file; somewhat less frequently, a SWF file is used for all or part of the user interface of a desktop
application.
As you work on more advanced applications, you may find a need to set up communication between the SWF file
and the container application. For instance, it’s common for a web page to display text or other information in
HTML, and include a SWF file to display dynamic visual content such as a chart or video. In such a case, you might
want to make it so that when users click a button on the web page, it changes something in the SWF file. ActionScript
contains a mechanism, known as the external API, that facilitates this type of communication between ActionScript
in a SWF file and other code in the container application.
Common external API tasks
The following common external API tasks are explained in this chapter:
Getting information about the container application
Using ActionScript to call code in a container application, including a web page or desktop application

Get ADOBE® FLEX® 3: PROGRAMMING ACTIONSCRIPT™ 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.