AS调用JS中的方法

ActionScript中通过ExternalInterface.call可以调用javascript的方法,Flex和html通信,可以通过as和js的沟通进行。

MXML中代码:

<mx:Script>
<![CDATA[
private function callJavaScript():void {
                ExternalInterface.call("sayHelloWorld");
            }
]]>
</mx:Script>
   <mx:Button label="Say 'Hello World'"
            click="callJavaScript();" />

HTML中代码:

<html>
  <head>
    <title>index.html</title>
<script type="text/javascript">
function sayHelloWorld(){
alert("Hello~欢迎来到FlexStudy世界!!");
}
</script>
  </head>
  
  <body>
    <h align="center">欢迎来到FlexStudy世界!!<h></br>
    这里要使用embed标签载入swf文件:</br>
    <embed src="flex/FlexStudy.swf" width="400" height="300"/>
  </body>
</html>


你可能感兴趣的:(AS调用JS中的方法)