Is anyone using the Universal Mind version of Cairngorm? I am struggling
w/getting the ModuleController to work correctly. When I open two instances
of a module, all the events dispatched by the module get handled 2x.
When a subcontroller is registered w/the main controller, the listeners
should get added. However, when the module is loaded, the commands gets
registered again, when the subcontroller gets registered.
It almost seems like the subcontroller shouldn't be instantiated, which
would allow the main FrontController to handle everything.
Finally, there is a bit of strangeness in the FrontController code; the call
to checkModuleType() will always return false or throw an error--it doesn't
ever seem to return true!
public function addSubController(controllerRef : Class):void {
if (!isControllerRegistered(controllerRef)) {
// 1) let's create instance
// 2) listen for all events for that module
// 3) direct handler for those events to that module controller
// Cache the moduile instance for later reuse
var module : * = new controllerRef();
if (checkModuleType(module) == true) {
__subControllers[controllerRef] = module;
// Register events and handlers
var moduleEvents : Array = (module
asModuleController).registeredEvents;
for each (var eventID : String in moduleEvents) {
listenForEvent(eventID,module.eventHandler);
}
}
}
}
// ***********************************************************
// Private methods
// ***********************************************************
/**
* This method checks the runtime type of the sub-controller.
* If not a subclass of ModuleController, then an error is thrown.
*
* @subController This is an instance of a class that "should be" a
sub-Controller
*/
private function checkModuleType(subController:*):Boolean {
if (subController is ModuleController) return false;
else {
var msg : String = "SubControllers must be subclasses of
ModuleController.";
throw new Error( msg );
}
}
By changing the return value to true in checkModuleType (and recompiling the
swc), and not instantiating the controller in my modules, everything seems
to work as expected. However, I am not sure what I might be breaking in the
process. Anyone else having a similar experience? Any thoughts from the
guys at UM?
--
Scott Talsma
CTO, echoEleven