flash使用FlashVars接收html参数

方法一:在网页中使用js,SetVariable设置flashobject中的变量,代码如:
q ]"|.~ Q)uh0// "HtmlToSwf"为网页中的flashobject ID 中国经济网 经济博客 FH!hl Y|"ndl
HtmlToSwf.SetVariable("_root.info_str","Happy Newyear"); 中国经济网 经济博客y ya @[ P9T
方法二:路径参数,如test.swf?foo=happy2005 中国经济网 经济博客*}I~6XxL3f
方法三:使用FlashVars,以下主要介绍FlashVars的用法。使用FlashVars后嵌入HTML的flashobject代码如下: 中国经济网 经济博客'I4r8N7BC F0x;SY.Y
<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="550" height="400" id="FlashVars" align="middle"> 中国经济网 经济博客c@if s{4T f%j^
<param name="allowScriptAccess" value="sameDomain" />
&p0i:WM)k e!B0<param name="movie" value="FlashVars.swf" /> 中国经济网 经济博客4h!x{f$SO4i.q;o+G
<param name="FlashVars" value="foo=happy2005&program=flash&language=简体中文-中国" />
:~,l4OMAN0<param name="quality" value="high" /> 中国经济网 经济博客,crWC'JZ
<param name="bgcolor" value="#ffffff" /> 中国经济网 经济博客G A2g/f f4l { k6fg
<embed src="FlashVars.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="FlashVars" align="middle" allowScriptAccess="sameDomain" FlashVars="foo=happy2005&program=flash&language=简体中文-中国" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> 中国经济网 经济博客U t!E5fmj.z
中国经济网 经济博客w!G,K&Pi:Hx"v P
通过上面的代码,在SWF(FlashVars.swf)中就可以直接获取foo、program、language变量数据。FlashVars.fla获取FlashVars参数的代码如下: 中国经济网 经济博客f-G;b&H oSH4N
// 创建三个文本字段
;M*Id1B1@3})U0_root.createTextField("foo_txt",1,0,0,16,16);
3u"G0x l4BI,E3}9Y0_root.createTextField("program_txt",2,0,32,16,16);
Kju*?wn P t7`0_root.createTextField("language_txt",3,0,64,16,16);
VH^n5OJ+S0foo_txt.autoSize = true;
/{]E#GWG0foo_txt.border = true; 中国经济网 经济博客J*F;cr$Hd v
program_txt.autoSize = true; 中国经济网 经济博客M6rC W&]O
program_txt.border = true;
V/?4Z4` L^e O3G:SH0language_txt.autoSize = true; 中国经济网 经济博客HIs V%g+x*HM
language_txt.border = true;
}GQ8S;q'C"fO0// 获取FlashVars变量
d%D,v*U$B4I.SW_L0foo_txt.text = "HTML中的foo参数:"+foo;
"t#}n8/0I{0program_txt.text = "HTML中的program参数:"+program; 中国经济网 经济博客 _t-o%C4i6o:s]#?
language_txt.text = "HTML中的language参数:"+language; 中国经济网 经济博客r3Kg AE hl
中国经济网 经济博客5O@ wW,u.LS8po1TIv
三、两者的有效结合。
V-t{WB xS8f[0在HTML网页中使用js获取参数,然后将获取的参数作为FlashVars写入flashobject传递给swf。代码如下: 中国经济网 经济博客+N-sw[+ahd
<script. language=javascript> 中国经济网 经济博客F"]6q4n7YCb5X
<!--
X7C3LoBR//0function writeflashobject(parastr) {
-jo7ru,K2O3a"osHN0document.write("<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=/"550/" height=/"400/" id=/"FlashVars/" align=/"middle/"/>/n"); 中国经济网 经济博客#Tbs8wg/)a
document.write("<param name=/"allowScriptAccess/" value=/"sameDomain/" //>/n"); 中国经济网 经济博客^ GZ*B FW
document.write("<param name=/"movie/" value=/"FlashVars.swf/" //>/n"); 中国经济网 经济博客 `{S7^e
document.write("<param name=/"FlashVars/" value=/""+ parastr +"/" //>/n"); 中国经济网 经济博客rMV+fuC0|
document.write("<param name=/"quality/" value=/"high/" //>/n"); 中国经济网 经济博客fS&W:tTA3B?
document.write("<param name=/"bgcolor/" value=/"#ffffff/" //>/n"); 中国经济网 经济博客1qj2Y9M_0~j0/
document.write("<embed src=/"FlashVars.swf/" quality=/"high/" bgcolor=/"#ffffff/" width=/"550/" height=/"400/" name=/"FlashVars/" align=/"middle/" allowScriptAccess=/"sameDomain/" FlashVars=/""+ parastr +"/" type=/"application/x-shockwave-flash/" pluginspage=/"http://www.macromedia.com/go/getflashplayer/" //>"); 中国经济网 经济博客/C y;^1xO:bll
document.write("</object/>"); 中国经济网 经济博客hN*Lg { eG_
} 中国经济网 经济博客6A(OXmf*WHa
function getparastr() { 中国经济网 经济博客/XHd u!q)Jq
var hrefstr,pos,parastr,para,tempstr1; 中国经济网 经济博客7^/~*F/U.b(rF
hrefstr = window.location.href; 中国经济网 经济博客-oG/r m"ijLBw}c
pos = hrefstr.indexOf("?") 中国经济网 经济博客R#fo Vyr^R.Vk
parastr = hrefstr.substring(pos+1); 中国经济网 经济博客tC B2tR
return parastr; 中国经济网 经济博客u`0e{)sj*@n
}
C'EP-UFGl0var parastr = getparastr();
}5^S{~ HK5I0writeflashobject(parastr);
,| i8[v7{@'[/u0//--> 中国经济网 经济博客.s+`N;E$k?L%Z
</script>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值