2 Replies Latest reply on Apr 29, 2010 7:30 PM by haibin_sh

    issuse of updating a list in a form

    haibin_sh

      I have a simple code below. It allows users to click on Add button to add to a list. Button "Add 2" works but button "Add 1" does not. Any idea? The only difference is one list is in a form and the other not.

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
          <mx:Script>
              <![CDATA[
                  import mx.collections.ArrayCollection;
                 
                  [Bindable]
                  private var dg1:ArrayCollection = new ArrayCollection();
                 
                  [Bindable]
                  private var dg2:ArrayCollection = new ArrayCollection();

                  private function onAdd1():void
                  {
                      var valObj:Object = new Object();
                      valObj["name"] = "name 1";
                      dg1.addItem(valObj);
                  }

                  private function onAdd2():void
                  {
                      var valObj:Object = new Object();
                      valObj["name"] = "name 1";
                      dg2.addItem(valObj);
                  }
              ]]>
          </mx:Script>
          <mx:Form>
              <mx:FormItem>
                  <mx:List dataProvider="{dg1}" labelField="name" />           
              </mx:FormItem>
              <mx:FormItem>
                  <mx:Button label="Add 1" click="onAdd1()" />           
              </mx:FormItem>
          </mx:Form>
          <mx:List dataProvider="{dg2}" labelField="name" />           
          <mx:Button label="Add 2" click="onAdd2()" />           
      </mx:Application>