How do I access flashvars in AS3, and add them to

2019-06-21 20:36发布

问题:

Edit: I've come to realize the main problem I'm facing is that I want a text field that already exists in a movieclip or on the stage to take the string from a flashvar. For some reason it will not do that. How do I make a pre-existing text field change to match the flashvar text?

Html:

<div id="flashContent">
            <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100%" height="29px" id="egnewsTicker" align="middle">
                <param name="movie" value="egnewsTicker.swf" />
                <param name="flashvars" value="newslisttest=this is my test" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#ffffff" />
                <param name="play" value="true" />
                <param name="loop" value="true" />
                <param name="wmode" value="transparent" />
                <param name="scale" value="showall" />
                <param name="menu" value="false" />
                <param name="devicefont" value="false" />
                <param name="salign" value="lt" />
                <param name="allowScriptAccess" value="sameDomain" />
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="egnewsTicker.swf" width="100%" height="29px">
                    <param name="movie" value="egnewsTicker.swf" />
                    <param name="quality" value="high" />
                    <param name="bgcolor" value="#ffffff" />
                    <param name="play" value="true" />
                    <param name="loop" value="true" />
                    <param name="wmode" value="transparent" />
                    <param name="scale" value="showall" />
                    <param name="menu" value="false" />
                    <param name="devicefont" value="false" />
                    <param name="salign" value="lt" />
                    <param name="allowScriptAccess" value="sameDomain" />
                    <param name="flashvars" value="newslisttest=this is my test" />
                <!--<![endif]-->
                    <a href="http://www.adobe.com/go/getflash">
                        <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>
        </div>

I know this is supposed to be a simple task, and I have found several web articles that give examples, but I simply cannot make it work when I'm trying to do my own code. All I want to do is pass a flashvar string and be able to access it by name in flash using AS3, but I can't seem to accomplish that.

I'm trying:

var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
newsItem.newsHeadline.text = String(paramObj[varName]);

I've also tried:

newsItem.newsHeadline.text = this.loaderInfo.parameters.newslisttest;

Nothing I try works, it always just stays blank. What is the trick to accessing flashvars in flash as3? I'm just not getting it and I can't find a good explanation anywhere...

回答1:

Try this: stage.loaderInfo.parameters.yourparam or stage.loaderInfo.parameters["yourparam"]

Can you post your html code, so we can see how you pass the flashvars to Flash.



回答2:

I've been wasted all the day long for that...

AS3:

var uid:String;
// your code
this.loaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
// your code
function loaderComplete(e:Event=null):void
{
    var fv = stage.loaderInfo.parameters;
    uid = fv['uid'] || "'uid' not found";
}

HTML:

<object type='application/x-shockwave-flash' data='/flash/yourSWF.swf' width='320' height='240'>
<param name='wmode' value='transparent' />
<param name='FlashVars' value='uid=yourData' />
<param name='movie' value='/flash/yourSWF.swf' />
</object>


回答3:

If you are still having this problem, follow below lines. I used flash vars, they work fine for me.

My html script was:

<html>
<body>
<div id="flashContent">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"FlashVars="uid=123&name=santhu" width="100%" height="100%" id="index" align="middle">
  <param name="movie" value="index.swf" />
  <param name=FlashVars value="uid=123&name=santhu">
  <!--[if !IE]>-->
   <object type="application/x-shockwave-flash" data="index.swf" 
            FlashVars="uid=123&name=santhu"  width="100%" height="100%">
     <param name="movie" value="index.swf" />
     <param name=FlashVars value="uid=123&name=santhu">
  <!--<![endif]-->
  <!--[if !IE]>-->
   </object>
  <!--<![endif]-->
</object>
</div>
</body>
</html>

and my AS code to load vars is

this.root.loaderInfo.addEventListener(Event.COMPLETE, SWFLoadComplete);
private function SWFLoadComplete(e:Event)
{
  obj=this.root.loaderInfo.parameters;
  trace(obj.uid , obj.name);  // outputs: 123 santhu
}