I agree with all the theory out there, but i cannot seem to put it into a
working example.
Let's try to be practical here with some trivail code:
myComp :
<mx:Script>
<![CDATA[
import mx.controls.*;
public function addLabel(value:String):void
{
var myNewLabel:Label = new Label();
myNewLabel.text = value;
myPanel.addChild(myNewLabel);
}
]]>
</mx:Script>
<mx:Panel id="myPanel">
<mx:Button label="Add Label" click="addLabel('New Label')"/>
</mx:Panel>
This short piece of code is trivial.
Now let's try to leverage this via Cairngorm :
1/ The button which adds a new label can be anywhere in the application. So
on click, we gonna dispatch a cg event which is gonna run a command.
2/ As i need to do some business logic also, i will put it in that command.
(optionnal)
3/ Now for xxx reasons, the function addLabel needs to reside where it is.
So the command is gonna have to trigger this function. One very bad way to
do this would be to add " Application.application.myComp.addLabel('New
Label') " to the command.
But that won't scale at all for obvious reasons : what if i want to trigger
different functions, or if there is a function name change or whatever...
4/ The good way to do it would be to update data in ModelLocator from the
command with value "New Label". So that i can bind this data in myComp to
trigger addLabel('dataFromML') everytime data changes.
This is theory, and it looks like what you all say should be done.
But how do i trigger addLabel() each time data in modelLocator changes ?
That is how do i bind the data to the trigerring of a Function. This is what
i'm missing, it is probably obvious, but i don't see it !
And if it needs to be refactored, ok, but i don't see how.
This is simple case, but function could be way more complex.
Best,
Jean-Luc
----- Original Message -----
From: "Tom Chiverton" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, May 24, 2006 9:58 AM
Subject: Re: [flexcoders] Re: Newbie : How do i listen to a value ?
Cairngorm inside.
On Tuesday 23 May 2006 16:53, Jean-Luc ESSER wrote:
> I meant that i need to know the component name because the command is
> gonna change things in this component (and thus pass it as a param in my
> dispatch event). That's why initially it was a view function.
You should refactor things so this doesn't happen. What in your view is the
command going to change, and why can't that thing use modelLocator data
binding ?
> As to "if the function performs some buisness level task, it should be a
> command" i'm not sure of this.
> But in some cases, you will have to update a view by adding or removing
> children, or even doing much complex things which are not business
> dependant. Things which will require actionscript, and thus a function.
> And
> i don't see how using bindings could resolve all these issues.
Ahh, OK, I see now :-)
> Unless you tell me there is a way to trigger a local function by
> listenning
> to data in ModelLocator.
If you've got a list of items, that list can be in modelLocator, and you can
repeat over the list.
Then your buisness command updates the model, and all is well.
--
Tom Chiverton
****************************************************
This email is sent for and on behalf of Halliwells LLP.
Halliwells LLP is a limited liability partnership registered in England and
Wales under registered number OC307980 whose registered office address is at
St James's Court Brown Street Manchester M2 2JF. A list of members is
available for inspection at the registered office. Any reference to a
partner in relation to Halliwells LLP means a member of Halliwells LLP.
Regulated by the Law Society.
CONFIDENTIALITY
This email is intended only for the use of the addressee named above and may
be confidential or legally privileged. If you are not the addressee you
must not read it and must not use any information contained in nor copy it
nor inform any person other than Halliwells LLP or the addressee of its
existence or contents. If you have received this email in error please
delete it and notify Halliwells LLP IT Department on 0870 365 8008.
For more information about Halliwells LLP visit www.halliwells.com.
We are pleased to announce that Halliwells LLP has been voted AIM Lawyer of
the Year at the 2005 Growth Company Awards
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
| Web site design development | Computer software development | Software design and development |
| Macromedia flex | Software development best practice |
YAHOO! GROUPS LINKS
- Visit your group "flexcoders" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

