<script language=javascript>下面的这段js代码则可以更加细化获取HTML网页某一参数
<!--
var hrefstr,pos,parastr;
hrefstr = window.location.href;
pos = hrefstr.indexOf("?");
parastr = hrefstr.substring(pos+1);
if (pos>0){
document.write("所有参数:"+parastr);
} else {
document.write("无参数");
}
//-->
</script>
<script language=javascript>二、在HTML网页中向swf传递参数。
<!--
function getparastr(strname) {
var hrefstr,pos,parastr,para,tempstr;
hrefstr = window.location.href;
pos = hrefstr.indexOf("?")
parastr = hrefstr.substring(pos+1);
para = parastr.split("&");
tempstr="";
for(i=0;i<para.length;i++)
{
tempstr = para[i];
pos = tempstr.indexOf("=");
if(tempstr.substring(0,pos) == strname) {
return tempstr.substring(pos+1);
}
}
return null;
}
// 获取program参数
var programstr = getparastr("program");
document.write(programstr);
//-->
</script>
// "HtmlToSwf"为网页中的flashobject ID方法二:使用FlashVars,以下主要介绍FlashVars的用法。使用FlashVars后嵌入HTML的flashobject代码如下:
HtmlToSwf.SetVariable("_root.info_str","Happy Newyear");
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"通过上面的代码,在SWF(FlashVars.swf)中就可以直接获取foo、program、language变量数据。FlashVars.fla获取FlashVars参数的代码如下:
codebase=
http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0
width="550" height="400" id="FlashVars" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="FlashVars.swf" />
<param name="FlashVars" value="foo=happy2005&program=flash&language=简体中文-中国" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<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" />
// 创建三个文本字段三、两者的有效结合。
_root.createTextField("foo_txt",1,0,0,16,16);
_root.createTextField("program_txt",2,0,32,16,16);
_root.createTextField("language_txt",3,0,64,16,16);
foo_txt.autoSize = true;
foo_txt.border = true;
program_txt.autoSize = true;
program_txt.border = true;
language_txt.autoSize = true;
language_txt.border = true;
// 获取FlashVars变量
foo_txt.text = "HTML中的foo参数:"+foo;
program_txt.text = "HTML中的program参数:"+program;
language_txt.text = "HTML中的language参数:"+language;
<script language=javascript>
<!--
function writeflashobject(parastr) {
document.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");
document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\" /\>\n");
document.write("<param name=\"movie\" value=\"FlashVars.swf\" /\>\n");
document.write("<param name=\"FlashVars\" value=\""+ parastr +"\" /\>\n");
document.write("<param name=\"quality\" value=\"high\" /\>\n");
document.write("<param name=\"bgcolor\" value=\"#ffffff\" /\>\n");
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\" /\>");
document.write("</object\>");
}
function getparastr() {
var hrefstr,pos,parastr,para,tempstr1;
hrefstr = window.location.href;
pos = hrefstr.indexOf("?")
parastr = hrefstr.substring(pos+1);
return parastr;
}
var parastr = getparastr();
writeflashobject(parastr);
//-->
</script>
四、附:源码下载
/upimg/soft/3/1_060702212855.zip
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |