1

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 actually 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?

ethrbunny
  • 10,379
  • 9
  • 69
  • 131
  • I am experiencing this problem as we speak. I am loading the module multiple times in the application, and passing data by query string. It works the first time the module loads, but the data is the same every time after. – goalie7960 May 23 '11 at 20:19
  • So you're loading an identical module repeatedly but sending different URL params each time? (wanting to understand your issue) – ethrbunny May 24 '11 at 13:12
  • That is correct. The URL params give some info about how the module should act. I tried explicitly calling removeEventListener(ModuleEvent.Ready,...) but that did not help. I've actually found a workaround by setting some data on a shared model. It's not ideal, but it solves my issue. – goalie7960 May 26 '11 at 16:07

2 Answers2

1

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.

Shakakai
  • 3,514
  • 1
  • 16
  • 18
  • I pulled out some lines where I was storing 'moduleInfo' for later use. It looked like too much clutter for this example.. though now that you point it out the sample is lame++. – ethrbunny Feb 07 '11 at 04:51
0

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).

ethrbunny
  • 10,379
  • 9
  • 69
  • 131