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.

One Response to “Cairngorm event gotcha”

  1. iongion Says:

    I found some issues in the latest Cairngorm release in a FMS+Flex+Cairngorm box, i created some observers on some sharedobjects and it seems that if you create and dispatch events when properties are changing in the shared object(realtime or extremly fast) some of the events will not trigger their respective command execution.

Leave a Reply