flash与javacsript交互

IE中
<param name="movie" value="test.swf" />
<param name="quality" value="high" />
<param name="flashvars" value="youUrl=123" />

<param name="menu" value="false" />

<embed
src="test.swf"
quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash"
width="580"
height="350" />

Firefox中

<param name="movie" value="test.swf" />
<param name="quality" value="high" />
<param name="flashvars" value="youUrl=123" />
<param name="menu" value="false" />
<embed
flashvars="youUrl=123"
src="test.swf"
quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash"
width="580"
height="350" />

很清楚在IE中只要放在<param name="flashvars" value="youUrl=123" />
而在Firefox中却是要放在<embed flashvars="youUrl=123" />才是有效的

所以建议大家在param和embed中都放上一个这样兼容性也就高了。




<script type="text/javascript">
var swfVersionStr = "10.2.0";
var xiSwfUrlStr = "playerProductInstall.swf";

var flashvars = {
sid : "<?=$sid?>",
user : "<?=$user?>",
time : "<?=$time?>",
hash : "<?=$hash?>",
ip : "<?=$ip?>",
port : "<?=$port?>",
hasrole : "<?=$hasrole?>",
fcm : "<?=$fchm?>",
path : "<?=$path?>",
version : "<?=version?>",   //IE
};

var params = {
flashvars: flashvars,
quality :  "high",
allowscriptaccess : "always",
wmode : "window",
menu : "false",
bgcolor : "#050505"
};

var attributes = {
id : "Loader",
name : "loader",
align : "middle"
};


var swf = flashvars["path"] + flashvars["version"] +"Loader.swf";


swfobject.embedSWF(swf, "flashContent","100%", "100%",swfVersionStr, xiSwfUrlStr,flashvars, params, attributes);


swfobject.createCSS("#flashContent", "display:block;text-align:left;");
    </script>

<object type="application/x-shockwave-flash" id="loader" name="loader" align="middle" data="<?=$path?><?=version?>/Loader.swf" width="100%" height="100%">
<param name="flashvars" value="[object Object]&amp;sid<?=$sid?&amp;user=<?=$user?&amp;time=<?=$time?&amp;hash=<?=$hash?>&amp;ip=<?=$ip?>&amp;port=<?=$port?>&amp;hasrole=<?=$hasrole?>&amp;fcm=<?=$fchm?>&amp;path=<?=$path?>&amp;version=<?=$version?>">
<param name="quality" value="high">
<param name="allowscriptaccess" value="always">
<param name="wmode" value="window">
<param name="menu" value="false">
<param name="bgcolor" value="#050505">
</object>
    
    <noscript>
            <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="1000" height="600" id="Game">
<param name="movie" value="Loading.swf"/>
                <param name="quality" value="high" />
                <param name="bgcolor" value="#000000" />;
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="true" />;
<!--[if !IE]-->
<object type="application/x-shockwave-flash" data="Loading.swf" width="1000" height="600">;
<param name="quality" value="high" />
                    <param name="bgcolor" value="#000000"  />;
                    <param name="allowScriptAccess" value="sameDomain" />
                    <param name="allowFullScreen" value="true" />
                <!--![endif]-->
                <!--[if gte IE 6]-->
                <p> 
                Either scripts and active content are not permitted to run or Adobe Flash Player version
                0.0.0 or greater is not installed.
</p>
                <!--![endif]-->;
                <a href="http://www.adobe.com/go/getflashplayer"/>;
    </object>
             </object>
      </noscript>>

《--------------------------------------------------------------as  and   js  通信---------------------------------------------------------------》

一: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代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!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 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" >
     < 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" id = "form1" method = "post" action = "" >
   < input type = "text" id = "inputData" name = "inputData" maxlength = "45" onchange = "sendData(this)" />
</ form >
< p > </ p >
</ body >
</ html >

你可能感兴趣的:(flash与javacsript交互)