Home | Web Design | App / Game development | Flash | Flash Games | Graphic Illustration | Technical Illustration | Contact | Site Map    Twitter
 
  Galaxy Graphics Limited

Technical InformationCommon 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

Hello World

 
Site content Copyright © 2001-2014 Galaxy Graphics Limited. | Privacy Policy | Terms of use