实现flash与javacript通信。

ActionScript代码:

package cn.vicky { import flash.display.MovieClip; import flash.external.ExternalInterface; import flash.events.*; import flash.display.SimpleButton; public class Example extends MovieClip { public function Example() { btn.addEventListener(MouseEvent.CLICK,onclick); } private function onclick(e:MouseEvent):void { // 核心,使用ExternalInterface去调用JavaScript的函数! ExternalInterface.call("callJavaScript","Vicky"); //将Vicky作为参数传递给javascript里面的函数callJavaScript去 } } }

 

JavaScript代码:

 

<mce:script language="javascript"><!-- function callJavaScript(name) { window.alert("你好:" + name); document.write("你好:" + name); mlocation.href="http://www.baidu.com"; } // --></mce:script>

你可能感兴趣的:(JavaScript,function,Flash,Class,import,actionscript)