2 Replies Latest reply on Oct 8, 2006 7:09 PM by samagination79

    Binding with data models

    samagination79 Level 1
      hello again

      I'd like to create a data model that will hold a lot of the labels/form data etc for the UI elements in my application. I'm doing this so I have better control of the state of the application. So I can clear all form fields when a user logs out, for example, by simply clearing the data model rather than referencing the form elements themselves.

      I'd like all these variables to be under a parent scope, just for organisational purposes. So for example my data model may be set up like so

      public var myParentScope:Object = {
      myChildScope1 : {
      text1 : "testing1",
      text2 : "testing2"
      myChildScope2 : {
      text1 : "testing1",
      text2 : "testing2"

      Lets say I put a Text component on the stage, and set the text to {myParentScope.myChildScope1.text1}

      <mx:Text text="{myParentScope.myChildScope1.text1}" id="myText" />

      when I load up that page, the text says "testing1" as is expected. However if I then change value of myParentScope.myChildScope1.text1, I'd like the text to update automatically. I test this by simply creating a button to change the value of that variable.

      <mx:Button label="Button" click="myParentScope.myChildScope1.text1 = 'change test'" />

      I have verified that the value of that variable is changing, but the text doesn't update unless I tell it to with something like

      myText.text = myParentScope.myChildScope1.text1;

      Is there a way to get this happening automatically? I have tried using mx:Binding but with no success.
      Did a little search and found something about objectProxy - is that what I need to be looking into? with a quick glance I didn't really understand the objectProxy stuff, and don't want to waste my time with it if it's not going to solve the problem.

      Appreciate any responses.