Read more

Exchange messages between Javascript and Flash

Henning Koch
March 02, 2011Software engineer at makandra GmbH

Flash movies (.swf files) can talk with Javascript code embedded in the same HTML page. There are two ways to do this:

  • The preferred way is to use the ExternalInterface Show archive.org snapshot class to call Javascript functions from ActionScript, and to bind ActionScript functions to the Flash movie's DOM element so they can be called from Javascript.
  • The deprecated way is to use the global fscommand Show archive.org snapshot function to call a Javascript function with a fixed name from Javascript. In return Javascript can sort of communicate with ActionScript by calling SetVariable(name, value) on the Flash movie's DOM element. This is super-legacy, but still encountered in the field.
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

Note that communication between a Flash movie and a piece of Javascript code is blocked unless they both live on the same domain. You can lift this restriction by adding a allowscriptaccess="always" attribute to the Flash movie's <embed> tag, and a <option name="allowScriptAccess" value="true" /> child tag to the Flash movie's <object> tag (which we keep around for Internet Explorer).

The attached link has more information.

Posted by Henning Koch to makandra dev (2011-03-02 17:08)