My code has gotten too complex to post, but a search of the archives here found a great example by a fellow flexcoder. I have posted it below.
Note, there has been a recent discussion about making the singleton more bullet proof by preventing use of "new" , but I couldn't get it to work and moved on for the time being. Search for "SingletonEnforcer"; if you want. Tracy 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 ________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Alan Gruskoff Sent: Thursday, April 17, 2008 1:57 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Calling http services in separate file I have been looking at best ways to use the data model and interested in this technique. Could you post some of the relevant code that does these things? Thanks - Alan Gruskoff --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "Tracy Spratt" <[EMAIL PROTECTED]> wrote: > > Implement this as data model, using a bindable singleton. Keep the > result data in that object. > > Implement public properties and methods to control the functionality. > Bind the UI to the model's properties. > > I just used this technique for the first time myself, and it rocks. > Tracy