Be the first to write a review
Flash 8 – ActionScript and JavaScript communication
In previous versions of Flash, getting ActionScript and JavaScript to communicate was a big effort. You could use getURL and fscommand to call a JavaScript function from within a Flash movie. If you’ve ever worked with fscommand, you’ll know that creating this type of communication can be pretty hard going.
Flash 8 includes a brand new way to communicate called the ExternalInterface class or the External API. The External API allows a Flash movie to communicate with a Web browser or any other container that plays the Flash movie. Not only can your Flash movie communicate with JavaScript, but you can also call a C#, VB.NET or Python function in a desktop application. The only drawback is that you have to target Flash Player 8 to be able to use this functionality.
In this tutorial, we’ll set up a simple two-way communication between Flash and a form on a Web page. You’ll be able to enter details in Flash, and transfer them to a form on a Web page. You’ll also be able to enter details in the Web form and transfer them through to Flash.
You’ll need a copy of Flash 8 so you can work with the External API. Download the source files for the tutorial from the blue Properties box that contains the article PDF. There’s a heading titled Code Download and you can click the Details link next to it to get the zip file. The download includes the starter files you’ll need as well as the completed files.
Note: If you have difficulties downloading the source files or PDF, you might have a problem with your cookies. Delete the cookies from your machine and try again. In Internet Explorer, you can do this by choosing Tools > Internet Options... and clicking the Delete Cookies... button on the General tab.
As we’ll focus on Web browser communication in this tutorial, we’d better find out which browsers support the External API and how the Flash Player 8 security model has changed.
Sas Jacobs
Hello. I'm the Principal of Anything Is Possible, an Australian web development business specialising in web applications development and training. I'm interested in using Flash with dynamic content and I've presented at a number of International conferences on topics relating to applications development, XML and scripting components. I have recently released my second print book Beginning XML with DOM and Ajax to match the first one - Foundation XML for Flash. I have a business web site
and a personal web site.