Archive

Posts Tagged ‘cairngorm’

Cairngorm and Flash

October 22nd, 2008

When developing Flash Applications I like to use the Cairngorm micro-architecture as I do in Flex. Without all the nice Flex Framework classes it takes a little more work. Iteration Two did a Cairngorm Flash 0.95 package but that seems to have fallen of the web.
So I took the Flex Open-Source 2.1 Cairngorm classes and removed everything until it started to work.

You can download the Cairngorm to Flash code here.

To think about is that;
- Delegates needs to handle the creation and sending of external services
- Bindable does not exist so instead dispatch when data is updated
There are probably a lot of more things here.

Flash ,

Cairngorm – Chain Events

August 7th, 2008

Found an Example of Chain Events at http://www.cairngormdocs.org/bjorn_schultheiss/eventChaining/EventChainExample.html (right click and check source).

So I put the code to an default Cairngorm Structure that you can download here. Just make sure that you have the Cairngorm.swc package in libs.

This is what files that exist.

cairngormdefault

Important to think of:
1.) All events extends ChainEvent

public class TestAEvent extends ChainEvent

2.) All commands extends SequenceCommand

public class TestACommand extends SequenceCommand implements ICommand

3.) All commands take the nextEvent and execute when done.

override public function execute(event:CairngormEvent):void
{
    nextEvent = ChainEvent(event).nextChainedEvent;
    // Do Command Action
    this.executeNextCommand();
}

That’s is…
Here is an example of executing a couple of commands.

var beginChain : ChainEvent = EventChainFactory.chainEvents([
    new UpdateViewEvent(ModelData.VIEW_LOADING),
    new CheckSoftwareVersionEvent(),
    new GetLocalSettingsEvent(),
    new GlobalApplicationEvent(),
    new GetFeedListEvent(),
    new UpdatePostStatusEvent(),
    new UpdateViewEvent(ModelData.VIEW_POSTS)
    ]);
cgDispatcher.dispatchEvent( beginChain );

————–
UPDATE: 2008-02-21
I’ve added a couple of changes for the demo files.
E.g. when creating an event it’s possible to send custom data
new TestAEvent( “CustomValue” )
and it’s just as easy to extract it in the command

var customEventValue:* = event.data;

You can add any data to the next event in the chain from the command, maybe to pass forward the data or something new. Here is an example.

nextEvent.data = customEventValue;

You can as well runtime change the next event from a command, here is an example.

nextEvent = new TestCEvent();

Flex , ,