Chapter 24. Putting JavaScript to Work

In this chapter, you learn how to use JavaScript to communicate between Flash and the browser. You see how to call JavaScript from Flash, and how to use both the Flash JavaScript Integration Kit and the External API to pass data from JavaScript to ActionScript and vice versa.

Before jumping into JavaScript, though, there is one bit of housekeeping to take care of: an issue with Flash security and how it affects JavaScript.

Changing Security Settings

To try this chapter's examples locally, you first need to make a change to a security setting. Flash player version 8 introduced additional restrictions to the security model to better prevent malicious attacks against your computer. For a local SWF file to be able to interact with an HTML page that is local to your computer, you need to designate the SWF file as being trusted content. You can elect to designate a single .swf file as trusted content, or you can designate an entire directory. It is recommended that you perform all of your Flash development in one parent directory and designate that directory as trusted. From then on, all .swf files in that directory and its subdirectories are trusted content and won't generate an error.

Note

This step only needs to be performed for viewing files locally from your own computer, as you would do during development. When your Flash content is uploaded to a web server and is then accessed from there, ExternalInterface will work without the viewer needing to ...

Get Beginning ActionScript 2.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.