Use the ExternalInterface class for ActionScript-JavaScript communication.
ExternalInterface defines two especially important static functions:
- call( functionName:String, ... arguments ) - call a container function
- addCallback( functionName:String, closure:Function ) - expose a Flex function to the container
Calling JavaScript from ActionScript is easy with ExternalInterface . Simply call the static call() function passing the function name and, optionally, any arguments.
// call a JavaScript function defined in the container page
var result:String =
ExternalInterface.call( "doSomethingInJavaScript", arg1, arg2 );
Learn more about calling JavaScript from ActionScript with ExternalInterface at Flex After Dark...