My task is very simple that i want to show alert in view.
But I am in Cairngorm architecture, so i have to go by the rules.
Which staes that there should be an Event and Command for this
purpose.
But command can update model not the view, on which I need to show the
PopUp.

So, the traditional approach is, that I will take a Boolean Variable
in the ModelLocator,
change its value evry time the command is executed.

To listen the change I will use <mx:Binding> in my view, where the
source will be binded to the modelLocator's variable
and destination will be the variable inside this view.

Now variable will be something like: private var set var(val:Boolean),
this will finaly end up in triggering the function of your view, and I
can write the PopUp code here.

But why I have done all this ?

Because the PopUpManager.createPopUp(), needs the refrence of the
parent view, on which the popup needs to be displayed, and command
cannot contain the view's refrence, as by Cairngorm.

Now, we look upon the another approach for doing the same work.

I am planning to dispatch an event from the view, and get a callback
function invoked, after the command have finished its work.

When writing an CustomEvent Class in Cairngorm, take an additional
property in class, sumthing like:

public var ref:Function;

Now, while disptaching the event from the view, I will fill up this
property, with the help of constructor.
Something like: new CustomEvent(func1, .. , .. , ..)

where this func1: is the function in my view part, which I want to be
called back, after the completion of my commmand.

and constructor of the CustomEvent class will store the refrence to
the function func1 into the ref variable.

Coming to the CustomCommand:

In the execute(), I have the (event:CairngormEvent), the object of my
custom class as a prameter.
I will type caste it to the CustomEvent(event).
Now the only thing left is to call the function, that is stored as the
ref in my CustomEvent class.

CustomEvent(event).ref();

And my function is executed in the view.


I can write the same code as in setter,in the previous approach.

But, whether I have violated cairngorm anywhere ??

Comments are most welcome.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to