You don't neccessarily 'have' to use 'C' ;-)
All you need to do is understand what a 'singleton' pattern means and what bindable means.
The principle of a model locator is simple. Create one object, create a public API for the one instance and store your data in the one instance while using data binding to dynamically update your public API as it changes.
Note:
if you have a TextArea;
<mx:TextArea text="{MyLocator.getInstance().welcomText}" />
and somwhere else in your app you set the locators public property;
MyLocator.getInstance ().welcomText = "Hello World";
Then you text is instantly updated. The same applies to the text EXCEPT, you need this in a change event from my testing if you are tracking someone typing text and don't explictly set the 'text' property of the TextArea.
Here is the quasi class
Class
--------------------------------------------
package my.package
{
[Bindable]
public class MyLocator
{
private static var instance:MyLocator = null;
/**
* Returns the single instance.
*/
public static function getInstance():MyLocator
{
if (!instance)
instance = new MyLocator();
return MyLocator;
}
public function MyLocator()
{
super();
// you could throw an error here if instance is already crated
// you could initialize things here
}
/**
* This is automatically bindable since the bindable tag is a
* above the class keyword.
*/
public var welcomeText:String = "HelloWorld";
}
}
Peace, Mike
On 10/6/06, Samúel Jónasson <[EMAIL PROTECTED]> wrote:
Tom Chiverton wrote:
Hi,On Friday 06 October 2006 10:05, Samúel Jónasson wrote:
What is the recommended way? It is rather clumsy binding to
Application.application and I also think it makes sense to store all the
data in one place - not divide it in to multiple places.
Have you considered something like Cairngorn's ModelLocator singleton ?
Actually I haven't looked at all into Cairngorn. I guess it exists for a reason and that I should look into it. I just wish they had come up with a better name for it. Not being able to pronounce it's name has kept me away :)
Sammi
--
What goes up, does come down. __._,_.___
--
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
Software development tool Software development Software development services Home design software Software development company
Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe
__,_._,___
- [flexcoders] Logical place for data? Samúel Jónasson
- Re: [flexcoders] Logical place for data? Tom Chiverton
- Re: [flexcoders] Logical place for data? Samúel Jónasson
- Re: [flexcoders] Logical place for data? Michael Schmalle
- Re: [flexcoders] Logical place for data... Samúel Jónasson
Reply via email to

