Your posting has ModelLocator in the subject. If you had an additional level between the user object and the binding (like the ModelLocator of Cairngorm), it would work as well.
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"> <mx:Script> <![CDATA[ [Bindable] private var model : ModelLocator = ModelLocator.getInstance(); private var index : int = 0; private function createUser() : void { index++; model.user = new User("user " + index ); } ]]> </mx:Script> <mx:Label text="{ model.user.fullname }" /> <mx:Button label="create user" click="createUser()"/> </mx:Application> //--------------------------------------------- package { public class ModelLocator { [Bindable] public var user : User; private static var instance : ModelLocator; public static function getInstance() : ModelLocator { if( instance == null ) instance = new ModelLocator(); return instance; } } } //--------------------------------------------- package { public class User { [Bindable] public var fullname : String; public function User( inFullname : String ) { fullname = inFullname; } } } //--------------------------------------------- Cheers Ralf. On Nov 24, 2007 11:20 PM, nxzone <[EMAIL PROTECTED]> wrote: > > > > > > > Yes, the binding is lost because it now working. But do you know how > to do this? Now i'm doing this with a watcher and is working. Anybody > have another suggestion? > > Thank you > > > --- In [email protected], "Ralf Bokelberg" > <[EMAIL PROTECTED]> wrote: > > > > You are binding to the concrete instance of the User. If you change > > the instance, the binding is lost. > > If you change the content of the bound User object, it should work. > > > > Cheers > > Ralf > > > > > On Nov 24, 2007 4:55 PM, nxzone <[EMAIL PROTECTED]> wrote: > > > > > > > > > > > > > > > > > > > > > For me too but you dont change the user during runtime. > > > > > > > > > ?xml version="1.0" encoding="utf-8"?> > > > <mx:Application > > > xmlns:mx="http://www.adobe.com/2006/mxml" > > > layout="absolute"> > > > > > > <mx:Script> > > > <![CDATA[ > > > [Bindable] > > > private var userBind : User = User.getInstance(); > > > private function changeUser():void{ > > > User.setUser(new User("test")) > > > } > > > ]]> > > > </mx:Script> > > > > > > <mx:Button label="{ userBind.fullname }" click="changeUser()" /> > > > > > > > > > </mx:Application> > > > > > > package > > > { > > > [Bindable] > > > public class User > > > { > > > public var fullname : String; > > > > > > public function User( inFullname : String ) > > > { > > > fullname = inFullname; > > > } > > > > > > private static var instance : User; > > > > > > public static function setUser(u:User):void{ > > > instance =u; > > > > > > } > > > > > > public static function getInstance() : User > > > { > > > if( instance == null ) instance = new User("test"); > > > return instance; > > > } > > > } > > > } > > > > > > --- In [email protected], "Ralf Bokelberg" > > > <ralf.bokelberg@> wrote: > > > > > > > > > > > The following code works for me > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > <mx:Application > > > > xmlns:mx="http://www.adobe.com/2006/mxml" > > > > layout="absolute"> > > > > > > > > <mx:Script> > > > > <![CDATA[ > > > > [Bindable] > > > > private var userBind : User = User.getInstance(); > > > > ]]> > > > > </mx:Script> > > > > > > > > <mx:Button label="{ userBind.fullname }" /> > > > > > > > > </mx:Application> > > > > > > > > package > > > > { > > > > [Bindable] > > > > public class User > > > > { > > > > public var fullname : String; > > > > > > > > public function User( inFullname : String ) > > > > { > > > > fullname = inFullname; > > > > } > > > > > > > > private static var instance : User; > > > > > > > > public static function getInstance() : User > > > > { > > > > if( instance == null ) instance = new User("test"); > > > > return instance; > > > > } > > > > } > > > > } > > > > > > > > In contrast to what i said before it works with getInstance() > in the > > > > binding as well. > > > > Cheers > > > > Ralf. > > > > > > > > > > > On Nov 23, 2007 9:00 PM, nxzone <nxzone@> wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Yes, all the class > > > > > > > > > > --- In [email protected], "Ralf Bokelberg" > > > > > <ralf.bokelberg@> wrote: > > > > > > > > > > > > Is fullname declared as bindable as well? > > > > > > Cheers > > > > > > Ralf. > > > > > > > > > > > > > > > > > On Nov 23, 2007 8:05 PM, nxzone <nxzone@> wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Thank you for you answer. But is not working... > > > > > > > > > > > > > > I tried this: > > > > > > > > > > > > > > > > > > > > > In User.AS > > > > > > > public static function setUser(u:User):void{ > > > > > > > loggedUser=u; > > > > > > > } > > > > > > > public static function getInstance():User{ > > > > > > > if(loggedUser==null){ > > > > > > > loggedUser= new User(0,"Pas"," > > > > > > > } > > > > > > > return loggedUser; > > > > > > > } > > > > > > > > > > > > > > In Myapp.mxml > > > > > > > [Bindable] > > > > > > > private var userBind:User = User.getInstance(); > > > > > > > > > > > > > > <mx:Button id="btConnection" label="{userBind.fullname}" > > > > > > > click="openLoginWindow()" /> > > > > > > > > > > > > > > But userBind is alway the same... When the user in static > > > UserClass > > > > > > > change, userBind is not reflected :(. > > > > > > > > > > > > > > --- In [email protected], "Ralf Bokelberg" > > > > > > > > > > > > > > <ralf.bokelberg@> wrote: > > > > > > > > > > > > > > > > Binding is based on the name of a property, it doesn't > work if > > > > > there > > > > > > > > is a method call involved. > > > > > > > > Assign the model returned by getInstance to a local > bindable > > > > > property > > > > > > > > and bind to it instead. > > > > > > > > Cheers > > > > > > > > Ralf. > > > > > > > > > > > > > > > > On Nov 23, 2007 5:42 PM, nxzone <nxzone@> wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Should i user a observer/watcher > > > > > > > > > > > > > > > > > > > > > > > > > > > --- In [email protected], "nxzone" <nxzone@> > wrote: > > > > > > > > > > > > > > > > > > > > Why databinding is not working? User class in bindable. > > > When I > > > > > > > set the > > > > > > > > > > new user, with setUser the fullname in Myapp in not > > > changed. > > > > > > > > > > > > > > > > > > > > In User.AS > > > > > > > > > > public static function setUser(u:User):void{ > > > > > > > > > > loggedUser=u; > > > > > > > > > > } > > > > > > > > > > public static function getInstance():User{ > > > > > > > > > > if(loggedUser==null){ > > > > > > > > > > loggedUser= new User(0,"Pas"," > > > > > > > > > > } > > > > > > > > > > return loggedUser; > > > > > > > > > > } > > > > > > > > > > In Myapp.mxml > > > > > > > > > > <mx:Button id="btConnection" > > > > > label="{User.getInstance().fullname}" > > > > > > > > > > click="openLoginWindow()" /> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > Ralf Bokelberg <ralf.bokelberg@> > > > > > > > > > > > > > > > Flex & Flash Consultant based in Cologne/Germany > > > > > > > > Phone +49 (0) 221 530 15 35 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > Ralf Bokelberg <ralf.bokelberg@> > > > > > > Flex & Flash Consultant based in Cologne/Germany > > > > > > Phone +49 (0) 221 530 15 35 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > Ralf Bokelberg <ralf.bokelberg@> > > > > Flex & Flash Consultant based in Cologne/Germany > > > > Phone +49 (0) 221 530 15 35 > > > > > > > > > > > > > > > > > > > > > -- > > > Ralf Bokelberg <[EMAIL PROTECTED]> > > Flex & Flash Consultant based in Cologne/Germany > > Phone +49 (0) 221 530 15 35 > > > > > -- Ralf Bokelberg <[EMAIL PROTECTED]> Flex & Flash Consultant based in Cologne/Germany Phone +49 (0) 221 530 15 35

