一:flash代码

import com.hexagonstar.util.debug.Debug;//alcon调试工具所需包
import flash.external.ExternalInterface;//js与flash交互所需包
import flash.events.Event;
import flash.events.MouseEvent;

var str:String=this.loaderInfo.parameters.myFlash;//加载时获取网页的flash对象
Debug.trace("flash:"+str);//输入对象看看是否为空

ExternalInterface.addCallback("callFlash",flashTest);//js调用flash方法(在js那边调用的方法别名为callFlash)

function flashTest(textValue:String):void
{
	myText.text=textValue;
	Debug.trace("js传过来的值为:"+textValue);
}

btnSend.addEventListener(MouseEvent.CLICK,sendFun);
function sendFun(e:MouseEvent):void
{
	ExternalInterface.call("calljs",text1.text);//flash调用js中的方法
}

二:html代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>flash和js通信实例</title>
<script language="javascript" type="text/javascript">
var flash;//flash对象
function sendData(obj)
{
    var vtext=obj.value;
    if(navigator.appName.indexOf("Microsoft") > -1)//IE浏览器
    {
        flash=window["myFlash"];
    }
    else//兼容非IE浏览器、火狐等。
    {
        flash=document["myFlash"];
    }
    if(flash!=null&&flash!=undefined)
    {
        flash.callFlash(vtext);//js调用flash中的方法
    }
}
function calljs(text)
{
    document.getElementById("inputData").value=text;
}
</script>
</head>
<body bgcolor="#ffffff">
<!-- 影片中使用的 URL-->
<!-- 影片中使用的文本-->
<p>
  <object class>
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="movie" value="flash和js通信实例.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#ffffff" />
    <embed src="flash和js通信实例.swf" quality="high" bgcolor="#ffffff" width="300" height="100" name="myFlash" swLiveConnect="true" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> 
  </object>
</p>
<form name="form1" >
  <input type="text"  />
</form>
<p> </p>
</body>
</html>

相关文章:

  • 2022-12-23
  • 2021-09-25
  • 2021-12-10
  • 2021-08-05
  • 2022-12-23
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-27
  • 2022-12-23
  • 2021-07-23
  • 2021-05-04
  • 2021-08-16
  • 2021-10-17
  • 2021-06-18
相关资源
相似解决方案