1

I am using flashvars to get some info. When im using LoaderInfo(this.root.loaderInfo).parameters from the main fla frame it works fine but how can I use it from withing a class?

Something like this -

public function display_user_info()
        {
            var keyStr:String;
            var valueStr:String;
            var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
            valueStr = String(paramObj['user_name']);       
        }

I'm getting this error message: Access of possibly undefined property root through a reference with static type.

Hope someone could guide me how to overcome this. thanks!

jazz
  • 143
  • 1
  • 3
  • 8
  • 1
    Only DisplayObjects have the root property, so if your class is not a DisplayObject, that's probably why you get the error. Normally, you would read the loaderInfo parameters in the class of some main DisplayObject, like the specified "document class" in a fla based project, act on them from there or store them somewhere where other classes can access the values. – Lars Blåsjö Dec 04 '11 at 17:39

1 Answers1

3

Try this:

package {
    import flash.display.Sprite;

    public class Main extends Sprite {

        public function Main() {
            trace(this.loaderInfo.parameters.yourFlashVarName);
        }
    }
}

This is what's suggesting wvxvw:

package 
{
    import flash.display.MovieClip;
    import flash.events.Event;
    //
    public class FlashvarsTest extends MovieClip
    {

        public function FlashvarsTest()
        {
            addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
        }

        public function addedToStageHandler(evt:Event)
        {
            trace(this.loaderInfo.parameters.yourFlashVarName);
        }
    }
}
AsTheWormTurns
  • 1,318
  • 3
  • 13
  • 26