A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Help with FlashVars in AS3

  1. #1
    Senior Member
    Join Date
    Feb 2006
    Location
    Portland OR
    Posts
    138

    Help with FlashVars in AS3

    Well I've read a few of the threads on accessing flashvars with AS3 and am still grappling with it, I'm hoping someone who has tackled this will take mercy on my poor soul and help me out.

    Essentially I've inherited making some changes to a flash file (a cover loader, carousel, media player thingy) that was built by a couple of other developers and am stumbling around - and I'm new to AS3.

    The project is constructed with a number of classes and packages and I have imported the LoaderInfo / import flash.display.LoaderInfo;

    and assumed I could simply access the flashvars like this:
    public var loadV = root.loaderInfo.parameters.loadVideo;

    where loadV becomes the value I pass into the function that tells the carousel which cover to stop on. and loadVideo is the flashvar value in the html page

    I also tried this approach, but neither worked for me:
    public var flashvars:Object = LoaderInfo(this.root.loaderInfo).parameters;
    public var tloadVideo = flashvars['loadVideo'];

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    That looks correct to me - make sure you're testing this in a browser (with the vars declared)...if you're still having trouble, throw a textfield on the stage and start tracing things out...start with String(this) and keep adding on until you find the problem.

  3. #3
    Senior Member
    Join Date
    Feb 2006
    Location
    Portland OR
    Posts
    138
    Thanks, I am testing in the browser with vars declared...

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Also you might want to try stage instead of root...they should be the same object (unless youre getting freaky with the loader) but it's worth checking.

  5. #5
    Senior Member
    Join Date
    Feb 2006
    Location
    Portland OR
    Posts
    138
    Thanks.
    that still didn't work so I've modified the approach a little bit:

    public static var __oInitData :Object;
    __oInitData = new Object();
    __oInitData.loadV = loaderInfo.parameters.loadVideo;


    yet still coming up with nothing...

  6. #6
    Senior Member
    Join Date
    Feb 2006
    Location
    Portland OR
    Posts
    138
    well starting over from scratch and with a little guidance from the help files I am able to read the flashvar.

    Part of the challenge I think is that my flashvar value was a number and I am trying to pass it as a number once inside the project so where I was hoping to get:

    //in the html:
    flashvar.loadVideo = 3;

    then:
    public var flashvars:Object = LoaderInfo(loaderInfo).parameters;
    public var loadV = flashvars['loadVideo'];

    and use it in another function:
    tf.text = loadV+3; // and have the result be 6
    I wound up with "33"


    anyone have any idea how to keep the var an int or uint?
    the other challenge I'm facing is now that I've got it in the document class how do I access that var in another function in a separate class or .as file?

  7. #7
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Anything coming into flash from the outside world is basically unknown so it generally gets treated as a String...to remedy that you need to 'cast' it back to an int...that will solve the addition problem as well but it introduces the opposite issue that you're then trying to put an int into a textfield, so you have to cast that back to a string to display it:

    PHP Code:
    public var loadV:int int(flashvars['loadVideo']);

    // ...

    tf.text String(loadV 3

  8. #8
    Senior Member
    Join Date
    Feb 2006
    Location
    Portland OR
    Posts
    138
    well probably not the prettiest solution but eventually got it working.

    In the document class where the flashvar was declared I have an initHandlers function that called the loader and movie to the stage in the init function...

    so I added the flashvar as a param in that method call:

    movie.init(stage, loadV); //where loadV is the value of the flashvar

    then in the main init function the var is passed as the second param:

    public function init(myStage:Stage, myFlashVar:String):void
    {
    if(myFlashVar != null || myFlashVar != undefined){
    var xmlPath:String = "/filepath/xml/"+myFlashVar+".xml";
    }else{
    var xmlPath:String = "/filepath/xml/filename.xml";
    }

  9. #9
    Senior Member
    Join Date
    Feb 2006
    Location
    Portland OR
    Posts
    138

    same post as above : I edited attempting to be more clear

    well probably not the prettiest solution but eventually got it working.

    In the document class where the flashvar was declared I have an initHandlers function that called the preloader and a movie to the stage from another init function in the loadXML class...

    so I added the flashvar as a param in that method call from the doc class, which handed it off to the loadXML:

    movie.init(stage, loadV); //where loadV is the value of the flashvar

    then in the main init function the var is passed as the second param:

    public function init(myStage:Stage, myFlashVar:String):void
    {
    if(myFlashVar != null || myFlashVar != undefined){
    var xmlPath:String = "/filepath/xml/"+myFlashVar+".xml";
    }else{
    var xmlPath:String = "/filepath/xml/filename.xml";
    }
    Last edited by knottyDJ; 09-11-2008 at 12:49 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center