0 Replies Latest reply on Aug 5, 2009 11:11 AM by webvalue

    Can Actionscript really do what MXML do (in databinding in thsi case)?

    webvalue

      Hi,

       

      I am trying to use AS to do binding but found that the data only are displayed correctly the first time, but the text that the data is bound to doesn't reflect any change. Below are the two examples side by side. Mxml version works but AS version doesn't (when you click buttons Change Data).

       

      Please shed some light.

       

      Thanks.

       

       

       

       

      <?xml version="1.0"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()"
          >

       

          <mx:Script>
                <![CDATA[
                    import mx.collections.ArrayCollection;
                  import mx.binding.utils.*;
         
                  [Bindable] public var dataOne:ArrayCollection = new ArrayCollection(["New York", "Washington", "Chicago", "Denver"]);
                  [Bindable] public var dataTwo:ArrayCollection = new ArrayCollection(["Dog", "Cat", "Fish", "Rabbit"]);

       

                  private function init():void {
                      BindingUtils.bindProperty(text4, "text", dataTwo, "0");
                      BindingUtils.bindProperty(text5, "text", dataTwo, "1");
                      BindingUtils.bindProperty(text6, "text", dataTwo, "2");
                      BindingUtils.bindProperty(text7, "text", dataTwo, "3");
                  }
                 
                  private function changeDataOne():void {
                      trace("before: " + dataOne.getItemAt(0));
                      dataOne.setItemAt('Boston',0);
                      trace("after: " + dataOne.getItemAt(0));
                  }
                 
                  private function changeDataTwo():void {
                      trace("before: " + dataTwo.getItemAt(0));
                      dataTwo.setItemAt('Cow',0);
                      trace("after: " + dataTwo.getItemAt(0));
                  }
              ]]>
          </mx:Script>

       

          <mx:DividedBox direction="horizontal" width="100%" height="100%">
              <mx:Panel title="Databinding using MXML tags" width="25%" height="100%" backgroundColor="0xCCCCCC">
                  <mx:Button label="Change Data" click="changeDataOne()"/>               
                  <mx:TextInput id="text0" text="{dataOne.getItemAt(0)}"/>
                  <mx:TextInput id="text1" text="{dataOne.getItemAt(1)}"/>
                  <mx:TextInput id="text2" text="{dataOne.getItemAt(2)}"/>
                  <mx:TextInput id="text3" text="{dataOne.getItemAt(3)}"/>
              </mx:Panel>
             
              <mx:Panel title="Databinding using Actionscript" width="25%" height="100%" backgroundColor="0xCCCCCC">
                  <mx:Button label="Change Data" click="changeDataTwo()"/>               
                  <mx:TextInput id="text4"/>
                  <mx:TextInput id="text5"/>
                  <mx:TextInput id="text6"/>
                  <mx:TextInput id="text7"/>
              </mx:Panel>
          </mx:DividedBox>
         
      </mx:Application>