Skip to main content
Inspiring
June 1, 2009
Question

how to pass a value to javascript from flash using externalinterface

  • June 1, 2009
  • 1 reply
  • 710 views

hi,

i'm currently trying to call a javascript function and pass values to it. but i'm not really familiar in using the addcallback since i only tested on calling a function from flash without passing anything to the function.

Basically, i'm going to retrieve the values of a node from xml.

and then i will assign those values to a variable in flash.

now what i'm going to do next is pass this value to a javascript parameter..is it done using externalinterface?

Could anyone give me an example.

I just need to throw the value to the javascript function parameter and no return values to the actionscript.

The event is that whenever an image is click, the corresponding value for each image is passed to the javascript function.

here is my unfinished script.

function imageClicked(e:Event):void {

    
    for each (var imageURL:XML in xml.images.link_to)
    {
        ExternalInterface.call("TestButton",imageURL);
       
    }
   
}

thanks so much in advance.

This topic has been closed for replies.

1 reply

Inspiring
June 1, 2009

first, it seems that the 'TestButton' funciton in JS will be called several times when an image is clicked - for each loop in the 'for each' loop you wrote.

second, in order to test the communication between AS and JS, try starting with something simple, like -

ExternalInterface.call('alert', 'OK');

if this doesn't work try tracing the ExteranlInterface.available property/

if it does work, place an alert within the 'TestButton' in the JS code, to see its actually being called.

and so forth...

good luck,

eRez