一: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代码
01 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
02 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN"> |
03 | <head> |
04 | <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> |
05 | <title>flash和js通信实例</title> |
06 | <script language="javascript" type="text/javascript"> |
07 | var flash;//flash对象 |
08 | function sendData(obj) |
09 | { |
10 | var vtext=obj.value; |
11 | if(navigator.appName.indexOf("Microsoft") > -1)//IE浏览器 |
12 | { |
13 | flash=window["myFlash"]; |
14 | } |
15 | else//兼容非IE浏览器、火狐等。 |
16 | { |
17 | flash=document["myFlash"]; |
18 | } |
19 | if(flash!=null&&flash!=undefined) |
20 | { |
21 | flash.callFlash(vtext);//js调用flash中的方法 |
22 | } |
23 | } |
24 | function calljs(text) |
25 | { |
26 | document.getElementById("inputData").value=text; |
27 | } |
28 | </script> |
29 | </head> |
30 | <body bgcolor="#ffffff"> |
31 | <!-- 影片中使用的 URL--> |
32 | <!-- 影片中使用的文本--> |
33 | <p> |
34 | <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="300" height="100" id="myFlash" align="middle"> |
35 | <param name="allowScriptAccess" value="sameDomain" /> |
36 | <param name="movie" value="flash和js通信实例.swf" /> |
37 | <param name="quality" value="high" /> |
38 | <param name="bgcolor" value="#ffffff" /> |
39 | <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" /> |
40 | </object> |
41 | </p> |
42 | <form name="form1" id="form1" method="post" action=""> |
43 | <input type="text" id="inputData" name="inputData" maxlength="45" onchange="sendData(this)" /> |
44 | </form> |
45 | <p> </p> |
46 | </body> |
47 | </html> |
Flash与JS通信实例教程

2902

被折叠的 条评论
为什么被折叠?



