Chapter 36. Interfacing with JavaScript
Introduction
In this chapter
Communicating from Flash to JavaScript
Communicating from JavaScript to Flash
This chapter looks at Flash applications embedded in HTML pages and interfacing with JavaScript. We'll take a look at how you can communicate from Flash to JavaScript and vice versa.
Communicating Between JavaScript and Flash
When you deploy Flash content in a web browser, you may want to be able to communicate with the container HTML page. You may want to call JavaScript functions from the SWF, and you may want JavaScript functions to be able to call functions within the SWF. That lets you make integrated applications, of which the SWF is just one component.
The following sections take a look at the ways in which you can communicate between Flash and JavaScript.
Using ExternalInterface
You can use the flash.external.ExternalInterface
class to both call JavaScript functions from Flash and to call ActionScript functions from JavaScript. The ExternalInterface
class has been tested successfully in the following browsers:
Internet Explorer 5.0 and above for Windows
Netscape 8.0 and above for Windows and Macintosh
Mozilla 1.7.5 and above for Windows and Macintosh
Safari 1.3 and above for Macintosh
Firefox 1.0 and above for Windows and Macintosh
Calling JavaScript functions from Flash
Using ExternalInterface
, you can call JavaScript functions from within a Flash SWF. With ExternalInterface
, the JavaScript function can return a value to Flash.
To call a JavaScript ...
Get ActionScript™ 3.0 Bible 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.