试了半天没出来原来是flex的bug,汗啊!
Steps to reproduce:
1. Create an application which loads a module.
2. Pass url-encoded variables along the query string while loading the module. For example:
[code]
<mx:ModuleLoader url="modules/modules/Module2.swf?name=jerry&flavor=chunky%20monkey" />
[/code]
3. Try and get the "name" and "flavor" parameters from the loaded module.
Actual Results:
From within the module, the "this.loaderInfo.parameters" object is empty, even though you passed values along the query string. you can get the values, but it involves a weird mix of RegEx class, URLUtil or URLVariables classe, or writing all your own parsing logic.
Expected Results:
this.loaderInfo.parameters should parse the "url" variable for you and create all the variables.
Workaround (if any):
Parse the URL from within the module and use regular expressions to remove everything up to (and including) the question mark. Next, parse the url-encoded name/value pairs using the URLUtil class or the URLVariables class, like so:
[code]
private function init():void {
// discard everything up to, and including, the question mark (?) in the URL.
var re:RegExp = /.*\?/;
var urlStr:String = (this.loaderInfo.url).replace(re, "");
// Use the URLUtil.stringToObject() method to parse the query-string.
var str2:Object = URLUtil.stringToObject(urlStr, "&");
nameLbl.text = "name=" + str2.name;
// Use the URLVariables class to parse the query-string.
var urlV:URLVariables = new URLVariables(urlStr);
flavorLbl.text += "flavor=" + urlV.flavor;
}
[/code]
The Flex documentation uses for loops and String.split() and rewrites most of the logic themselves, but that solution is a bit overkill considering the two solutions above work (and with a lot less code)