This Is A FineDay

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  93 随笔 :: 0 文章 :: 69 评论 :: 0 Trackbacks
试了半天没出来原来是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&amp;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) 

posted on 2009-01-04 16:30 Peter Pan 阅读(2414) 评论(1)  编辑  收藏 所属分类: FLEX

评论

# re: flex 中module之间参数传递 2012-05-25 16:39 ss
ddddd  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: