Indeed, it works this way.
Here is the working code for those interested.
 
TestLocator
----------------
package {
 
 public class TestLocator {
  
  private static var testLocator:TestLocator;
  
  [Bindable]
  public var someProperty:String;
  
  public static function getInstance():TestLocator {
   if(testLocator == null)
    testLocator = new TestLocator();
 
   return testLocator;
    }
  
  public function TestLocator() {
   this.someProperty = "Some value";
  }
  
 }
}
 
Test.mxml
---------------
<?xml version="1.0" ?>
<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml" xmlns="*">
 
<mx:Script>
 <![CDATA[
  import TestLocator;
  
  public var model:TestLocator = TestLocator.getInstance();
  
  private function onChangeClick():Void {
   model.someProperty = 'Some other value';
  }
 ]]>
</mx:Script>
 
<mx:Label text="{model.someProperty}" />
 
<mx:Button label="Change value" click="onChangeClick()" />
 
</mx:Application>
 
Thanks.
 
Benoit Hediard


De : [email protected] [mailto:[EMAIL PROTECTED] De la part de Clint Modien
Envoyé : mardi 25 octobre 2005 16:24
À : [email protected]
Objet : [Norton AntiSpam] Re: [flexcoders] Implementing ModelLocator pattern in AS3/Flex2

It would if you created an internal var first
 
Test.mxml
-----------------
<?xml version="1.0" ?>
<mx:Application xmlns:mx=" http://www.macromedia.com/2005/mxml" xmlns="*">
 
<mx:Script>
 <![CDATA[
  import TestLocator;
  private var myTestLocator = TestLocator.getInstance ();
  private function onChangeClick():Void {
   TestLocator.getInstance().someProperty = 'Some other value';
  }
 ]]>
</mx:Script>
 
<mx:Label text="{myTestLocator.someProperty}" />
 
<mx:Button label="Change value" click="onChangeClick()" />
 
</mx:Application>


 
On 10/25/05, Benoit Hediard <[EMAIL PROTECTED]> wrote:
I don't think that bindings works on singleton instance syntax.
 
TestLocator.as
---------------------
package {
 
 public class TestLocator {
  
  private static var testLocator:TestLocator;
  
  public var someProperty:String;
  
  public static function getInstance():TestLocator {
   if(testLocator == null)
    testLocator = new TestLocator();
 
   return testLocator;
    }
  
  public function TestLocator() {
    this.someProperty = "Some value";
  }
  
 }
}
 
Test.mxml
-----------------
<?xml version="1.0" ?>
<mx:Application xmlns:mx=" http://www.macromedia.com/2005/mxml" xmlns="*">
 
<mx:Script>
 <![CDATA[
  import TestLocator;
  
  private function onChangeClick():Void {
   TestLocator.getInstance().someProperty = 'Some other value';
  }
 ]]>
</mx:Script>
 
<mx:Label text="{TestLocator.getInstance().someProperty}" />
 
<mx:Button label="Change value" click="onChangeClick()" />
 
</mx:Application>
 
Anyway, I'll wait for the release of Cairngorm for Flex2.0 to see how Steven and Allistair did this part of their framework.
 
Thanks.
 
Benoit Hediard


De : [email protected] [mailto: [email protected]] De la part de Matt Chotin
Envoyé : lundi 24 octobre 2005 19:39
À : [email protected]
Objet : RE: [flexcoders] Implementing ModelLocator pattern in AS3/Flex2

 

I haven't investigated this for real but you may need to turn ModelLocator into a singleton so that there's an instance of an object to watch.  Because we're doing code-gen and not prototype hacking it's impossible to make a Class object an EventDispatcher.  The singleton approach would allow us to use the code-gen and then you'd simply bind to ModelLocator.getInstance().myModel instead of ModelLocator.myModel.

 

Matt

 


From: [email protected] [mailto:[email protected]] On Behalf Of Clint Modien
Sent: Friday, October 21, 2005 12:18 PM
To: [email protected]
Subject: Re: [flexcoders] Implementing ModelLocator pattern in AS3/Flex2

 

Make the objects in the Model Locator typed.... by importing the classes you need to ref.

On 10/21/05, Benoit Hediard < [EMAIL PROTECTED]> wrote:

Since it is not possible to create bindings to static properties, how do you implement the ModelLocator pattern in AS3?

 

Benoit Hediard

 

PS: by the way, any information on an alpha release of Cairngorm for Flex2.0?



--
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




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




YAHOO! GROUPS LINKS




Reply via email to