5

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...

Ghost9
  • 249
  • 3
  • 7
  • 15
  • and before someone sends me here: http://blog.six4rty.ch/tutorials/flash-flashvars-in-as3/, I've been there. It works if I do it in a blank file exactly how he has it, but if I try to incorporate it into my own flash file, it never works. ever.... – Ghost9 Jan 12 '11 at 17:54

3 Answers3

11

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.

m90
  • 11,434
  • 13
  • 62
  • 112
robertp
  • 3,557
  • 1
  • 20
  • 13
  • 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? – Ghost9 Jan 12 '11 at 18:02
  • Holy crap that stage.loaderInfo.parameters["yourparam"] works – Ghost9 Jan 12 '11 at 18:04
  • 1
    the problem was the " . I've tried no ", and ', as examples had shown me, but using "" is what worked. Jeez talk about pulling my hair out. Thanks Rob! – Ghost9 Jan 12 '11 at 18:05
  • @heartcode: You are my hero man... I have been struggling with issue of accessing the parameters. Finally, your way worked. Thanks a ton. It would be great if you can explain the reason for the same in this question: http://stackoverflow.com/questions/14603100/stage-loaderinfo-parameters-works-but-loaderinfothis-root-loaderinfo-parameter – abnvp Jan 30 '13 at 11:55
4

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>
nhahtdh
  • 55,989
  • 15
  • 126
  • 162
beatstream
  • 41
  • 2
1

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
}
Mat
  • 202,337
  • 40
  • 393
  • 406
santhu
  • 4,796
  • 1
  • 21
  • 29