The principle is almost the same as that in Silverlight (see how Silverlight and JS call each other ):
Actionscript3Code:
Btncalljs. addeventlistener (mouseevent. click, fncalljs); function fncalljs (E: mouseevent): void {trace ("ready to call... "); // call the jshello method in JS and display the returned value to lblresult in the label. TEXT = externalinterface. call ("jshello", "as3 passed parameters");} function calledbyjs (P: string): String {return "calledbyjs in Flash is called, this is the parameter passed in JS: "+ P;} externalinterface. addcallback ("myfunction", calledbyjs); // here: myfunction is the name of the method exposed to JS calls.
Embedded in Flash pages:
<Object classid = "CLSID: d27cdb6e-ae6d-11cf-96b8-444553540000 "... id = "js_as3">... </Object> <SCRIPT type = "text/JavaScript"> function jshello (MSG) {var r = "this is the method in JS. Parameter:" + MSG; alert (R ); return R;} function fncallas (MSG) {var flashobj = document. getelementbyid ("js_as3"); var sasreturn = flashobj. myfunction ("parameters in JS"); alert (sasreturn);} fncallas ("test"); </SCRIPT>