-
AS3 pass URL parameter
I must be missing something obvious. I'm trying to pass a parameter from a URL into a text field in flash, but it doesn't seem to work...
I've got a dynamic text field (display as html is checked), with an instance name txt_txt. Here's the only line of code in the file:
Code:
txt_txt.htmlText="test "+this.loaderInfo.parameters.nameVar;
And, when I upload it and use the following, I get "test undefined" as my return!?
http://www.brianwpiper.com/fk/tstURL...ameVar=testing
Can anyone help out on this??? What obvious thing am I overlooking??
TIA!!!
-
The parameters available from loaderInfo are the flashvars (if any) set in the embed/object for the swf. URL parameters for the page are not automatically available. To get them in the flashvars, you'll need to set the flashvars parameter with or whatever javascript you're using to generate the embed/object tag. If you're using a server side script to generate the page, you could put the parameters on the swf url there instead.
-
Hmm....thanks...so, there's no way to directly get the info from the URL parameters??
The flash file is being launched in a modal window put together by the client so I'll have to work with them to make sure the parameters get read and passed to the flashvars correctly and the right javascript is in there...
Thanks!
-
Not directly, no. But if you can have script access, you could use ExternalInterface to run some javascript to get the page url, then parse it yourself.
Something like this:
Code:
function getPageParams():Object{
var params:Object = {};
if (ExternalInterface.available){
var pageurl:String = ExternalInterface.call("function getPageURL(){return document.location.href}");
var paramStr:String = pageurl.substr(pageurl.indexof("?")); //get the part after ?
var paramPairs:Array = paramStr.split('&'); //split into name/value pairs
for (var i:int = 0; i < paramPairs.length; i++){
var nameVal:Array = paramPairs[i].split("=");
params[nameVal[0]] = nameVal[1];
}
}
return params;
}