flash和js通过什么类如何交互

JavaScript013

flash和js通过什么类如何交互,第1张

ExternalInterface 接口,有两个方法call和addCallback

call的作用:让Flash调用js里的方法。

addCallback是用来注册flash函数让js调用。

使用flash.external.ExternalInterface

步骤一:flash中定义可以访问的函数hello

flash as文件中的关键代码:

import flash.external.ExternalInterface  

function hello(){  

        return "测试成功了哦~~"  

    } 

//允许js调用flash中的函数 参数1:要调用flash函数的js函数,参数2:被调用flash函数  

ExternalInterface.addCallback("helloas",hello)

步骤二:js中定义可以访问的函数hello和flash文件加载

<script type="text/javascript">  

  function hello(v)  

  {  //js中定义的测试函数

      alert(v)   

  }  

</scritp>

<body>

  //flash组件

  <object  id="test" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="" width="560" height="270"> </object>

</body>

步骤三:flash访问js中的hello方法

ExternalInterface.call("hello", "jacky")

步骤四:js访问flash的hello方法

document.getElementById("test").helloas()