You are here: Recent News » Projects » Flash JavaScript Integration Kit » Tutorials » Calling a JavaScript function from ActionScript

 

Calling a JavaScript function from ActionScript

Again, make sure all four of the required JavaScript files are included in the HTML page that contains the JavaScript function you want to invoke.

<script type="text/javascript" src="Exception.js"></script>
<script type="text/javascript" src="FlashTag.js"></script>
<script type="text/javascript" src="FlashSerializer.js"></script>
<script type="text/javascript" src="FlashProxy.js"></script>

Import the JavaScriptProxy class into your Flash project:

import com.macromedia.javascript.JavaScriptProxy;

You then create an instance of the JavaScriptProxy class like this, passing in a unique identifier to ‘glue’ the Flash-side portion to the Browser-side portion:

var proxy:JavaScriptProxy = new JavaScriptProxy( lcId, );

You can call a JavaScript function in two ways.

First, you can use the call API like this:

proxy.call("javaScriptMethodName", "arg1", new Object());

The first argument is the name of the function to call in JavaScript. Any additional arguments will be passed as arguments to the JavaScript function being called.

You can also call methods directly on the JavaScriptProxy class, and they will be proxied to JavaScript. For Example:

proxy.javaScriptMethodName("arg1", new Object());

projects/flashjs/tutorials/jstoas.txt · Last modified: 2007/12/12 17:52 by reubidium