flash swf与浏览器javascript 互相调用

package {
		import flash.external.ExternalInterface;
		import flash.text.TextField;
		import flash.display.*;
		import flash.events.*;
		import flash.events.MouseEvent;
     public class main extends Sprite{
     private var _sp:Sprite;
	 public function main():void{		 
	                _sp=new Sprite();    
	       		   _sp.graphics.beginFill(0xd6d6d6);
				   _sp.graphics.drawRect(0,0,550,60);
				   _sp.graphics.endFill();
				   addChild(_sp);
				  _sp.addEventListener(MouseEvent.CLICK,loadtitle);
				  //给浏览器调用函数
				  ExternalInterface.addCallback("getMessage",showMessage);
	 }
	 public function loadtitle(e:Event):void{
		    	 var w:TextField=new TextField();
				 var  str:String="浏览器返回值:"+ExternalInterface.call("getTitle");
				  w.text=str;
				  w.width=str.length*12;				  
				  w.x=100;
				  w.y=80;
				 addChild(w);
	 }
	 public function showMessage(str:String):String{
		   return str+"actionscript 返回值";
	 }
  }
}

html文件

<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>js</title>
<script language="JavaScript" type="text/javascript">
function getTitle()
{
    return "browser return";
}
function showme(){
  document.getElementById("show").innerHTML=detect("js").getMessage("goggogo");
}
function detect(id){
  if(navigator.appName.indexOf("Microsoft")!=-1){
     return window[id];
  }else{
     return window.document[id];
  }
}
// -->
</script>
</head>
<body bgcolor="#ffffff">
	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="550" height="400" id="js" align="middle">
	<param name="allowScriptAccess" value="sameDomain" />
	<param name="allowFullScreen" value="false" />
	<param name="movie" value="js.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	
<embed src="js.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="js" align="middle" allowScriptAccess="sameDomain"
 allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer_cn" />
	</object>
	<button οnclick="showme()">点击</button>
	<div id="show"></div>
</body>
</html>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值