This has been driving me nuts. I’ve worked with SWFObject in the past which is great. However I have a requirement not to use JavaScript. So when I try to do flashvars examples all over the net, they don’t seem to work for me.
Steps to repeat:
1) Create a pure AS3 project using Flex or Flash Builder
2) In the index.html wherever there is a .swf, add a name value pair suffix.
test.swf?foo=bar
3) In the constructor of the main class Sprite, trace(root.loaderInfo.parameters.foo).
Expected: bar but traces out as undefined
I’ve tried setTimeout() to evaluate 5 seconds in the future, still doesn’t work as if it’s not loaded at all.
<noscript>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="${width}" height="${height}" id="${application}">
<param name="movie" value="${swf}.swf?foo=bar" />
<param name="quality" value="high" />
<param name="bgcolor" value="${bgcolor}" />
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="true" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="${swf}.swf?foo=bar" width="${width}" height="${height}">
<param name="quality" value="high" />
<param name="bgcolor" value="${bgcolor}" />
<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
${version_major}.${version_minor}.${version_revision} or greater is not installed.
</p>
<!--<![endif]-->
<a href="http://www.adobe.com/go/getflashplayer">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" />
</a>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</noscript>
AS3
package
{
import flash.display.LoaderInfo;
import flash.display.Sprite;
public class FlashVarsTest extends Sprite
{
public function FlashVarsTest()
{
var paramsObj:Object =
LoaderInfo(root.loaderInfo).parameters;
trace("foo="+paramsObj["foo"]);
}
}
}
This doesn’t work either:
package
{
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.events.Event;
public class FlashVarsTest extends Sprite
{
public function FlashVarsTest()
{
this.addEventListener(Event.ADDED_TO_STAGE, init)
}
private function init(event:Event):void
{
var paramsObj:Object =
LoaderInfo(root.loaderInfo).parameters;
trace("foo="+paramsObj["foo"]);
}
}
}
Update after seeing OP code:
Your error is in the non-IE object tag:
Gotta love a typo!
Have you tried using the FlashVars object param tag instead of passing them as part of the URL?
Obviously I’ve omitted a lot of extra stuff here, but this should illustrate how variable passing is done.
As a side note though, passing variables though the URL should work in AS3, as this blog by Peter deHann illustrates: http://blogs.adobe.com/pdehaan/2006/07/using_flashvars_with_actionscr.html
Testing myself:
I used ExternalInterface to output to the Firebug console. Both outputs come out as expected, proving that there is not drawing delay associated with
root.loaderInfoHTML: