I'm not sure I see the event logic you're talking about.
________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Sebastian Mohr Sent: Saturday, July 12, 2008 9:22 AM To: [email protected] Subject: Re: [flexcoders] Module hell... Flex 3 Hi there, I have the same problem as dbronk mentioned (see below) in conjunction with Cairngorm 2.2.1. I always have to dispatch the LoadTestEvent twice to make the LoadTestCommand calling the moduleReadyHandler-method. here is the code: package com.test { import com.adobe.cairngorm.commands.ICommand; import com.adobe.cairngorm.control.CairngormEvent; import flash.system.ApplicationDomain; import mx.events.ModuleEvent; import mx.modules.IModuleInfo; import mx.modules.ModuleManager; public class LoadTestCommand implements ICommand { private var moduleInfo:IModuleInfo; public function LoadTestCommand() { moduleInfo = ModuleManager.getModule('TestModule.swf'); moduleInfo.addEventListener(ModuleEvent.READY, moduleReadyHandler); moduleInfo.addEventListener(ModuleEvent.ERROR, moduleErrorHandler); } public function execute(event:CairngormEvent):void { moduleInfo.load(ApplicationDomain.currentDomain); } public function moduleReadyHandler(e:ModuleEvent) : void { trace('SUCCESS'); } public function moduleErrorHandler(e:ModuleEvent) : void { trace('ERROR'); } } } Is there a solution to dispatch the event only once to make the Command loading the module? Thank you, masu On 1/28/08, dbronk <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > wrote: I'm trying to get something very basic to work with modules. I have my app and two swf modules (Form1.swf and Form2.swf). Each test module simply has a couple TextInput fields. I have also extended Module so I can follow what is going on and I will be adding custom code later. MyModule extends Module has: public function MyModule() { super(); trace("Module constructor"); addEventListener(FlexEvent.INITIALIZE, onInitialize); } protected function onInitialize(event:Event) : void { trace("Module.onInit: " + this.toString()); dispatchEvent(new BaseEvent("moduleLoaded", this, true, true)); } Very basic. I want to be notified when the Module is initialized. When I have the following code inline to a button click which will load the module it works fine var moduleLoader : ModuleLoader = new ModuleLoader(); moduleLoader.id = moduleName; moduleLoader.url = moduleName; moduleLoader.loadModule(); moduleLoader.addEventListener("moduleLoaded", onModuleLoaded); moduleStackChild = moduleLoader; moduleStack.addChild(moduleStackChild); moduleMap.put(moduleName, moduleStackChild); My onModuleLoaded function gets called. Now for the issue. If I take this code and place it into a common object it no longer works THE FIRST TIME. I have two buttons, one to load Form1.swf and the other to load Form2.swf. When this code to load the module is in a separate class, it doesn't matter if I click button 1 or 2 first. It simply will not work on the first click. Second click and beyond work fine. Also, in debug mode, works great every time. What happens is that the last thing that runs is the loadModule() command. The constructor on MyModule never executes on the first execution. Future executions work fine. I'm hoping I explained this good enough as it is very strange. But I definitely want to have this function in my util classes and not have to duplicate the code all over the place. Suggestions? Thanks, Dale

