Get HTML page parameters in SWF

Source: Internet
Author: User
Tags html page
Web page

This tutorial focuses on how HTML pages get the Foo parameters like Test.html?foo=mytest, and how to pass parameters to the SWF in an HTML Web page.

  First, use JS to get parameters in HTML Web pages.

We know that HTML pages are executed on the client side, so that the parameters must be obtained using client script (such as JavaScript), which differs from the server-side script fetching parameters.

The following JS code to get HTML page shape such as "Test.html?foo=mytest&program=flash" "?" After all the parameters.

<script language=javascript>
<!--
var hrefstr,pos,parastr;
Hrefstr = window.location.href;
pos = Hrefstr.indexof ("?");
Parastr = hrefstr.substring (pos+1);
if (pos>0) {
document.write ("All Parameters:" +PARASTR);
} else {
document.write ("no parameters");
}
-->
</script>

The following JS code can be more detailed to get an HTML page of a parameter

<script language=javascript>
<!--
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;
}
Get program Parameters
var programstr = getparastr ("program");
document.write (PROGRAMSTR);
-->
</script>

  Pass parameters to the SWF in the HTML Web page.

Method One: Use js,setvariable in the Web page to set the variables in Flashobject, such as:

"Htmltoswf" is the Flashobject ID in the Web page
Htmltoswf.setvariable ("_root.info_str", "Happy newyear");

Method Two: Path parameters, such as test.swf?foo=happy2005

Method Three: Use Flashvars, the following is mainly about flashvars usage. The Flashobject code for embedding HTML after using Flashvars is as follows:

<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=" "height=" id= "flashvars" align= "Middle" >
<param name= "allowscriptaccess" value= "Samedomain"/>
<param name= "movie" value= www.webjx.com/htmldata/2005-10-25/FlashVars.swf "/>
<param name=" flashvars "value=" foo=happy2005& program=flash&language= Simplified Chinese-China "/>
<param name=" quality "value=" high "/>
<param name=" bgcolor "Value=" #ffffff/>
<embed src= "http://www.webjx.com/htmldata/2005-10-25/FlashVars.swf" quality= "High" Bgcolor= "#ffffff" width= "height=" name= "flashvars" align= "Middle" allowscriptaccess= "Samedomain" FlashVars= "Foo=happy2005&program=flash&language= Simplified Chinese-Chinese" type= "Application/x-shockwave-flash" pluginspage= "http:// Www.macromedia.com/go/getflashplayer "/>

With the above code, you can get Foo, program, and language variable data directly in SWF (HTTP://WWW.WEBJX.COM/HTMLDATA/2005-10-25/FLASHVARS.SWF). Flashvars.fla the code to get the Flashvars parameter is as follows:

Create three text fields
_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;
Get Flashvars variable
Foo_txt.text = "Foo parameter in HTML:" +foo;
Program_txt.text = "program parameters in HTML:" +program;
Language_txt.text = "Language parameter in HTML:" +language;

  Three, the effective combination of the two.

Use JS in an HTML Web page to get parameters, and then pass the obtained arguments as Flashvars write flashobject to the SWF. The code is as follows:

<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=\" http://www.webjx.com/htmldata/2005-10-25/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=\" http://www.webjx.com/htmldata/2005-10-25/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>

Four, attach: final effect , source Download



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.