Cairngorm event gotcha
April 15th, 2008
The latest version of Cairngorm i.e. Cairngorm v2.2.1 has an added helper method in the CairngormEvent class. CairngormEvent->dispatch(e:CairngormEvent). The other day I was busy debugging an application and came across the following code inside one of the views:
var event:CairngormEvent = new CairngormEvent(); dispatchEvent(event);
At first glance this seems completely normal but will fail silently and cease to trigger the associated command.
While I do appreciate the new CairngormEvent helper method which should look like this:
var event:CairngormEvent = new CairngormEvent(); event.dispatch();
for clarity towards fellow team members who may not be familiar with Cairngorm and better distinction between Cairngorm application events and standard view events, I recommend still using the original syntax to dispatch your events:
var event:CairngormEvent = new CairngormEvent(); CairngormEventDispatcher.getInstance().dispatchEvent(event);
This will ensure that the event is clearly dispatched by the Cairngorm framework and not your view.