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?

3
  • 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. Commented May 23, 2011 at 20:19
  • So you're loading an identical module repeatedly but sending different URL params each time? (wanting to understand your issue) Commented May 24, 2011 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. Commented May 26, 2011 at 16:07

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.