Copy link to clipboard
Copied
Hello,
I'm trying to call some flashVar HTML parameters in my .swf. This is my first time doing this, so I'm a bit confused.
Here is how I have the HTML params-- The first should call an image; the rest are numerical values except the last one, its a boolean.
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="1280" height="720" id="SCGPreLoad" align="middle">
<param name="movie" value="SCGPreLoad.swf" />
<param name=FlashVars value="img2Load=image&imprintXPos=imprintXposition&imprintYPos=imprintYposition&imprintXScale=imprintWidth&imprintYscale=imprintHeight&isMetal=false" />
<param name="quality" value="high" />
<param name="bgcolor" value="#666666" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="window" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="SCGPreLoad.swf" width="1280" height="720">
<param name="movie" value="SCGPreLoad.swf" />
<param name=FlashVars value="img2Load=image&imprintXPos=imprintXposition&imprintYPos=imprintYposition&imprintXScale=imprintWidth&imprintYscale=imprintHeight&isMetal=false" />
<param name="quality" value="high" />
<param name="bgcolor" value="#666666" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="window" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<!--<![endif]-->
Here is how I have the variables in the actionScript file-
//flashVar Variables from HTML Parameters
var img2Load:Object = LoaderInfo(this.root.loaderInfo).parameters.img2Load;
var imprintXPos:Number = LoaderInfo(this.root.loaderInfo).parameters.imprintXPos;
var imprintYPos:Number = LoaderInfo(this.root.loaderInfo).parameters.imprintYPos;
var imprintXScale:Number = LoaderInfo(this.root.loaderInfo).parameters.imprintXScale;
var imprintYScale:Number = LoaderInfo(this.root.loaderInfo).parameters.imprintYScale;
var isMetal:Boolean = LoaderInfo(this.root.loaderInfo).parameters.isMetal;
Then, I'm trying to call the img2Load variable in a URLRequest--
var bgImgReq : URLRequest = new URLRequest("img2Load");
However, No imag loads. Am I evern close to doing this right?
Copy link to clipboard
Copied
First off, I'd suggest using SWFObject instead of the terribly ugly Object/Embed code. It makes it super easy to pass in FlashVars.
That being said... if what you have is right, and FlashVars are getting passed in all you should need to do to get to them is like so:
//flashVar Variables from HTML Parameters
var img2Load:Object = loaderInfo.parameters.img2Load;
Also you are trying to load a string "img2Load" instead of the variable you just loaded:
This line: var bgImgReq : URLRequest = new URLRequest("img2Load");
should be: var bgImgReq : URLRequest = new URLRequest(img2Load); //no quotes
Copy link to clipboard
Copied
Thanks for the help. If I don't put img2Load in quotes I get this error. Do you know of a way around?
implicit coercion of a value with static type Object to a possibley unrelated type string
Copy link to clipboard
Copied
You have the variable defined as an Object... I'm not really sure what you're passing, but if it is a String then just change the definition:
var img2Load:String = loaderInfo.parameters.img2Load;
Copy link to clipboard
Copied
I'm trying to pass an image. Setting the variable to a string doesn't give any errors, but the image doesn't load. I'm pretty sure the variable should be set to an object if I'm trying to pass an image.
Copy link to clipboard
Copied
Ok, just read that the flashvar variable has to be a string. So, img2Load has the value of image. So, upon the url request "img2Load" will return the value of "image" from the parameter and then it should work, right? I'm confused. Not really sure of the question I should be asking here...