Reputation: 1555
So im trying to gain access to flash vars but i kept getting this error:
Line 27 1180: Call to a possibly undefined method LoaderInfo.
I have tried putting the below code in and outside of my class but it seems from what i have gathered that it thinks 'LoaderInfo' is another function which it is not.
public function getFlashVars():Object {
var paramList:Object = LoaderInfo( this.root.loaderInfo ).parameters;
var myParam:String = paramList["myParam"];
return myParam;
}
How do i get around this?
Eli
Upvotes: 0
Views: 1207
Reputation: 10163
If you want an elegant way to work with flashvars, you could use FlashVars class from the temple library. This class is a wrapper around the flashvars, so they can be accessed at places where there is no Stage.
You have the possibility to set a default and a class-type for each flashvar individually. In combination with a FlashVarNames enum class you know which flashvars are used in the application.
You should instantiate/configure the FlashVars once in your main file.
package
{
import temple.data.flashvars.FlashVars;
import flash.text.TextField;
public class FlashVarsExample extends DocumentClassExample
{
private static const _LANGUAGE:String = 'language';
private static const _VERSION:String = 'version';
private static const _IS_DEMO:String = 'is_demo';
public function FlashVarsExample()
{
FlashVars.initialize(this.loaderInfo.parameters);
FlashVars.configureVar(_LANGUAGE, 'nl', String);
FlashVars.configureVar(_VERSION, 1, int);
FlashVars.configureVar(_IS_DEMO, true, Boolean);
var txt:TextField = new TextField();
txt.width = 550;
txt.height = 400;
this.addChild(txt);
trace('FlashVars.getValue(_LANGUAGE) : ' + FlashVars.getValue(_LANGUAGE) + "\n");
trace('FlashVars.getValue(_VERSION) : ' + FlashVars.getValue(_VERSION) + "\n");
trace('FlashVars.getValue(_IS_DEMO) : ' + FlashVars.getValue(_IS_DEMO) + "\n");
trace(FlashVars.dump());
}
}
}
Upvotes: 0
Reputation: 22604
It looks like you forgot the import for flash.display.LoaderInfo
.
But you can probably just as well omit the type cast:
this.root.loaderInfo.parameters;
Upvotes: 3
Reputation: 13151
From the likes of your function name & return type, it seems you are rather tryiing to implement this:
function getFlashVars():Object{
return root.loaderInfo.parameters;
}
Besides this is already a static object for you. You don't really need a function to fetch these parameters.
At least not the one as above. You may fetch them as:
root.loaderInfo.parameters.myParam1
root.loaderInfo.parameters.myParam2
root.loaderInfo.parameters.myParam3
...
Upvotes: 0