13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Using the external API<br />

File Description<br />

IntrovertIMApp.fla<br />

or<br />

IntrovertIMApp.mxml<br />

Preparing for ActionScript-browser communication<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The main application file for Flash (FLA) or Flex (MXML).<br />

com/example/programmingas3/introvertIM/IMManager.as The class that establishes and manages communication betwe<strong>en</strong><br />

ActionScript and the container.<br />

com/example/programmingas3/introvertIM/IMMessageEv<strong>en</strong>t.as Custom ev<strong>en</strong>t type, dispatched by the IMManager class wh<strong>en</strong> a message<br />

is received from the container.<br />

com/example/programmingas3/introvertIM/IMStatus.as Enumeration whose values repres<strong>en</strong>t the differ<strong>en</strong>t “availability” status<br />

values that can be selected in the application.<br />

html-flash/IntrovertIMApp.html<br />

or<br />

html-template/index.template.html<br />

The HTML page for the application for Flash (htmlflash/IntrovertIMApp.html)<br />

or the template that is used to create the<br />

container HTML page for the application for Adobe Flex (htmltemplate/index.template.html).<br />

This file contains all the JavaScript<br />

functions that make up the container part of the application.<br />

One of the most common uses for the external API is to allow ActionScript applications to communicate with a web<br />

browser. Using the external API, ActionScript methods can call code writt<strong>en</strong> in JavaScript and vice versa. Because of<br />

the complexity of browsers and how they r<strong>en</strong>der pages internally, there is no way to guarantee that a SWF docum<strong>en</strong>t<br />

will register its callbacks before the first JavaScript on the HTML page runs. For that reason, before calling functions<br />

in the SWF docum<strong>en</strong>t from JavaScript, your SWF docum<strong>en</strong>t should always call the HTML page to notify it that the<br />

SWF docum<strong>en</strong>t is ready to accept connections.<br />

For example, through a series of steps performed by the IMManager class, the Introvert IM determines whether the<br />

browser is ready for communication and prepares the SWF file for communication. The first step, determining wh<strong>en</strong><br />

the browser is ready for communication, happ<strong>en</strong>s in the IMManager constructor, as follows:<br />

Last updated 6/6/2012<br />

849

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!