开发者

Passing param to flex module via url

Im using a few modules repeatedly in a Flex app and varying the conditions by passing in params via the 'loaderInfo.url' var. This works fine for the first iteration of a given module but subsequent attempts will always see the same params as the first creation regardless of what is ac开发者_如何学编程tually used.

Is there some way to reset this value when the module is created?

private var moduleInfo : IModuleInfo;
private function loadPageModule( pathString : String, pageParam : String ) : void
{
    pathString = "modules/" + pathString + ".swf?param=" + pageParam;

    moduleInfo = ModuleManager.getModule( pathString );
    moduleInfo.addEventListener( ModuleEvent.READY, onPageModuleReady, false, 0, true);
    moduleInfo.load( ApplicationDomain.currentDomain, null, null );
}

When I view the param in the 'CreationComplete' handler (eg 'trace( this.loaderInfo.url );') its the same every time (for a given module) regardless of what is actually passed in via the ?param=string. What am I doing wrong?


I'm little confused by your code. "moduleInfo" is a local variable in loadPageModule, meaning after the function executes it should be garbage collected. Typically adding a event listener would stop the object from being GC'ed but you specifically set the "weakListener" argument of addEventListener to true.

Can you set the weakListener argument of addEventListener to false and manually remove the listener in onPageModuleReady? Like below:

// change true to false on this line
moduleInfo.addEventListener( ModuleEvent.READY, onPageModuleReady, false, 0, false);

// tweak onPageModuleReady
private function onPageModuleReady(e:Event):void {
e.target.removeEventListener(ModuleEvent.READY, onPageModuleReady);
// that will allow the object to be GC'ed 
...rest of your code

Test it again with that configuration and report back if things change.


Well I don't know why this is doing what its doing.. but.. an effective way to pass unique params to different instances of a module is to use the IModuleInfo.data param. The url method never worked properly (for me).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜