Actionscript: ExternalInterface

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 16-12-2009

0

Hi,

today in this post i going to explain how to use this helpful class that have the purpose to call and receive the return of javascript functions from the flash enviorment.

Basically the function that make the trick is call(), this static function let you call any existent javascript function in the current document and get the returned value if exist.

in an example:

Flash side:

import flash.external.ExternalInterface;

var result:String=ExternalInterface.call(“alertFunction”,”Hello World”);

trace(result);

Javascript Side:

function alertFunction(message){

if(alert(message)){

return true;

}else{

return false;

}

}

As you see, in the flash part we are calling statically the call functions and passing as first parameter the name of the javascript function and secondly and string, that are the parameter required by the javascript function. there is no limit in the amount of parameter that can be passed to the call function and going to be passed to the javscript function when is called. also as you see, we are storing the value returned by the javascript function in a variable also to use it later.

it’s useful method to manipulate html info or elements from the flash using this function as a bridge.

as far as i know, it work also on actionscript 2 but i’m not sure. also this work on the major browser that have javascript supported but again, i’m not sure if it work in all (example: IE6, IE7 etc..)

i hope it help you to use this function and if you need more reference, just look at the adode docs :D

Regards,

Shadow.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Write a comment