Common SWF questions: How can I call a Javascript function?
To call Javascript from Actionscript, it's a simple as this:
The AS2 / AS3 (Both are the same)
var msg1:String = "Hello";
var msg2:String = "World";
import flash.external.*;
ExternalInterface.call("testFunction('"+msg1+"','"+msg2+"')");
This example above passes two variables to the function.
The Javascript
Put the following just before the closing head tag in HTML:
<script type="text/javascript">
function testFunction(m1,m2)
{
alert(m1+","+m2);
}
</script>
The result

|