;

PDA

Click to See Complete Forum and Search --> : Help with FlashVars in AS3


knottyDJ
09-09-2008, 01:42 PM
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'];

neznein9
09-09-2008, 02:27 PM
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.

knottyDJ
09-09-2008, 03:06 PM
Thanks, I am testing in the browser with vars declared...

neznein9
09-09-2008, 03:10 PM
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.

knottyDJ
09-09-2008, 03:39 PM
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...

knottyDJ
09-09-2008, 06:54 PM
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?

neznein9
09-09-2008, 07:06 PM
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:

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

// ...

tf.text = String(loadV + 3)

knottyDJ
09-10-2008, 08:23 PM
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";
}

knottyDJ
09-11-2008, 12:13 PM
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";
}