8 Replies Latest reply on Jan 31, 2011 8:20 AM by Gregory Lafrance

    Bizarre behavior involving Form, List, and Button

    Gregory Lafrance Level 6

      The following code does not work, but if you uncomment the opening and closing HBox tags it does work.

       

      By "work" I mean click the button and the default string should be added to the data provider and appear in the list.

       

      Very strange.

       

      <?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 detailsAC:ArrayCollection = new ArrayCollection();
            private var addNewDetailPrompt:String = "click to add new details entry";
            
            private function addDetail():void{
              if(detailsAC.length == 0 || detailsAC.getItemAt(0) != addNewDetailPrompt){
                detailsAC.addItemAt(addNewDetailPrompt, 0);
              }
            }
          ]]>
        </mx:Script>
        <mx:Form>
          <mx:FormItem label="Event details:">
            <!--<mx:HBox>-->
              <mx:List id="detailsList" editable="true"
                dataProvider="{detailsAC}">
                <mx:itemRenderer>
                  <mx:Component>
                    <mx:TextArea text="{data}"/>
                  </mx:Component>
                </mx:itemRenderer>          
              </mx:List>
              <mx:Button label="Add..." click="addDetail();"/>                
            <!--</mx:HBox>-->
          </mx:FormItem>
        </mx:Form>  
      </mx:Application>