O'Reilly logo

ActionScript 3.0 Bible by Roger Braunstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required