How to call javascript functions from flash ExternallInterface on release action

1.4k Views Asked by At

My HTML is:

<object width="800" height="600"
    classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
    codebase="http://fpdownload.macromedia.com/
    pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">
        <param name="SRC" value="intros/01/intro.swf" />
        <param name="allowscriptaccess" value="always" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#999900" />
            <param name="play" value="true" />
            <param name="loop" value="true" />
            <param name="wmode" value="window" />
            <param name="scale" value="showall" />
            <param name="menu" value="true" />
            <param name="devicefont" value="false" />
            <param name="salign" value="" />
        <embed src="intros/01/intro.swf" width="800" height="600"></embed>
</object>

I have this code on my button Flash:

on (release) {
    import flash.external.*;
    var isAvailable:Boolean = ExternalInterface.available;
    if( isAvailable ) {
        ExternalInterface.call( "sample" );
    }
}

and javascript/jquery is:

jQuery( document ).ready( function(){

    function sample() {

       alert( 'message' );
    }
});

what am I doing wrong? I'm using action script 2.0. When I test it in flash, for example, to know if isAvalaible variable is true, it really is... it's true.

4

There are 4 best solutions below

2
On

don't put sample() inside of (document).ready()

It isn't in scope anymore. It should work fine as long as its outside of ready.

Also, since its a function declaration, you don't need it inside of ready anyway.

6
On

It's been quite a while since I've done AS2, but I see two things here that I'd change. First, get rid of the import statement on your button code.

var isAvailable:Boolean = flash.external.ExternalInterface.available;

Then, the jquery you have is structured as an anonymous function. Try this instead on your webpage:

function sample(){...}
$(sample);

Then, when jQuery is initialized, it will call sample, and sample will be available from elsewhere.

0
On

Thank u all. I've found the solution.... It was about security and permissions of flash player... Your suggestions of code were part of the solution too.

0
On