![](/user_photo/_userpic.png)
Beginning ActionScript 2.0 2006
.pdf![](/html/611/317/html_NlflBIWLQ1.kSNL/htmlconvd-4s6rvZ621x1.jpg)
![](/html/611/317/html_NlflBIWLQ1.kSNL/htmlconvd-4s6rvZ622x1.jpg)
![](/html/611/317/html_NlflBIWLQ1.kSNL/htmlconvd-4s6rvZ623x1.jpg)
![](/html/611/317/html_NlflBIWLQ1.kSNL/htmlconvd-4s6rvZ624x1.jpg)
![](/html/611/317/html_NlflBIWLQ1.kSNL/htmlconvd-4s6rvZ625x1.jpg)
![](/html/611/317/html_NlflBIWLQ1.kSNL/htmlconvd-4s6rvZ626x1.jpg)
![](/html/611/317/html_NlflBIWLQ1.kSNL/htmlconvd-4s6rvZ627x1.jpg)
![](/html/611/317/html_NlflBIWLQ1.kSNL/htmlconvd-4s6rvZ628x1.jpg)
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.
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 make any changes.
When you use ExternalInterface with Flash movies contained in a local HTML page, you get an error like the alert window shown in Figure 24-1.
![](/html/611/317/html_NlflBIWLQ1.kSNL/htmlconvd-4s6rvZ629x1.jpg)
![](/html/611/317/html_NlflBIWLQ1.kSNL/htmlconvd-4s6rvZ630x1.jpg)