开发者

Unload module event handling in flex

I am developing an AIR app. In开发者_StackOverflow社区 the main app I have a module loader 'mainModuleLoader'. I am creating modules as separate mxml files using the <mx:Module> tag. And I am loading such a module in mainModuleLoader dynamically using actionscript. Everything works fine.

For the module which I am creating as mxml files, I would like to know how to add an unload event handler. So that, whenever I call mainModuleLoader.unload(), the unload event hander is triggered from inside the module.mxml. I have tried the following without any success.

<mx:Module creatingComplete="init()" unload="unloadHandler()"/>
<mx:Module creatingComplete="init()" remove="unloadHandler()"/>

The problem with the second statement above is that it triggers the unloadHandler even if some child is removed inside the module. I have also tried to add the following in the action script.

private function init()
{
  this.addEventListener(ModuleEvent.UNLOAD, unloadHandler);
}

But, it doesn't trigger on unloading the module. Kindly let me know if I am going wrong somewhere or if there is any other method to attach the event handlers. Thanks!!


You are part-way there with the remove; just check that event.target is the module before doing your work. It'll ignore the other ones then.


I think you have to handle the unload event of your mainModuleLoader:

<mx:ModuleLoader id="mainModuleLoader" unload="unloadHandler()"/>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜