Actionscript3 - Call javascript function from AS3 and viceversa

Quick example on how to call a js function via URLRequest:

var r:URLRequest = new URLRequest("javascript:functionName()");
navigateToURL(r,'_self');
 

Call AS3 function from JS using ExternalInterface class

To call an Actionscript 3 function from Javascript:

import flash.external.ExternalInterface;
 
ExternalInterface.addCallback("changeText", changeTheText); // so javascript from html can talk to flash
 
function changeTheText(t:String):void {
	txtText.text = t;
}

Call the AS3 function from Javascript. (first select the Flash object in the DOM)

 
var flashObj = document.getElementById('flashObject');
 
<a href="#" onClick="flashObj.changeText('it works!');">Click me!</a>

Call JS function from AS3 using ExternalInterface class

Use the ExternalInterface class to call a JavaScript function from AS3:

ExternalInterface.call("javascript_function");

Pass an argument to the Javascript function and/or receive a return value from it :

var returnvalue:int = ExternalInterface.call("js_function", "argument_for_js_function","another_argument");
Reply:
 
 
 
 
Whoops! Replied to the previous comment.

Could I get an example of this? I'm trying to make the mute button work with these calls here: www.friedmanllp.com/home3.php and I'm having some errors. Need to pass a pass a click event (the mute button) to the other flash file and turn off and on the sound.

Thanks in advance.
Thanks for the \"Quick example\". I didn\'t know it could be done like that.
Could I get an example of this? I'm trying to make the mute button work with these calls here: www.friedmanllp.com/home3.php and I'm having some errors. Need to pass a pass a click event (the mute button) to the other flash file and turn off and on the sound.

Thanks in advance.
rendered @ Fri Apr 25 9:55:20 CEST 2014