Calling Javascript functions from Flash

2008 June 21
by kunalbharati

Calling Javascript functions from Flash is very easy. We use a class called ExternalInterface. Here is ActionScript code:

import flash.external.*;
import flash.events.Event;

button1.addEventListener(MouseEvent.CLICK, buttonHandle);

function buttonHandle(event:MouseEvent)
{
    ExternalInterface.call("showMessage");
}

Here flash.external is a package where the class ExternalInterface is found.
The code is very simple. Event listener to button is added. And call is a method of ExternalInterface class, the parameter passed to call() is a name of the Javascript function.

The Javascript function is an alert message:

function showMessage()
{
    alert("Hi from flash");
}

Javascript function called from Flash

One Response leave one →
  1. 2009 September 21
    pollo permalink

    i want to use

    Image 2

    a html link to a class, (lightbox image effect) but on flash can you help me??

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS