Chapter 43. Interfacing with JavaScript
FEATURED CLASSES
flash.external.*
In this chapter, I'll look at how you can communicate from Flash Player to JavaScript and vice versa. 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. Tightly integrating Flash Player and its container page yields a hybrid page that has the potential to be more accessible, quicker loading, or more standards compliant. You can play to the strengths of each technology, using small instances of Flash Player for graphically rich, multimedia, and highly interactive content, and using HTML for long stretches of fully accessible copy, dynamic CSS-directed layout, and CMS-driven content. With the glue described in this chapter, you can ensure these two pieces are tied together.
Using ExternalInterface
You can use the ExternalInterface class in the flash.external package to call JavaScript functions from Flash and call ActionScript functions from JavaScript. ExternalInterface is officially supported on the following browsers:
Firefox 1.0 and above for Windows and Mac, 1.5.0.7 and above for Linux
Safari 1.3 and above for Mac
Internet Explorer 5.0 and above for Windows
Discontinued browsers Netscape and Mozilla are also officially supported. In addition, I have had no problems using ExternalInterface with Opera or Chrome. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access