Add item to a list from TextInput : TextInput Data « Components « Flex






Add item to a list from TextInput

Add item to a list from TextInput
          
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        
        
            import mx.events.CollectionEventKind;
            import mx.events.CollectionEvent;
            import mx.collections.SortField;
            import mx.collections.Sort;
            import mx.collections.ArrayCollection;
            
            private var index:Number = 0;
            
            public function collectionChange(event:CollectionEvent):void
            {
                switch (event.kind)
                {
                    case CollectionEventKind.ADD:
                        myTextArea.text += "Item Added\n";
                        break;
                    case CollectionEventKind.REPLACE:
                        myTextArea.text += "Item Replaced\n";
                        break;
                    case CollectionEventKind.REMOVE:
                        myTextArea.text += "Item Removed\n";
                        break;
                }
            }
            
            public function addItem():void
            {
                myCollection.addItem({label: myTextInput.text, data: index});
                index++;
            }
            private function removeItem():void
            {
                if (myList.selectedItem != null)
                    myCollection.removeItemAt(myList.selectedIndex);
            }
            
      
    </mx:Script>
    
    <mx:ArrayCollection id="myCollection" collectionChange="collectionChange(event)" />
    
    <mx:TextInput id="myTextInput" />
    <mx:List id="myList" dataProvider="{myCollection}" width="200" height="200" />
    <mx:Button label="ADD" click="addItem()" />
    <mx:Button label="REMOVE" click="removeItem()" />
    <mx:TextArea id="myTextArea" width="200" height="200" />
    
</mx:Application>

   
    
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.Using actionscript to access TextInput data in TextUsing actionscript to access TextInput data in Text
2.Use TextInput as the Credit card number data sourceUse TextInput as the Credit card number data source
3.Show an MXML-based data model with properties of TextInput controls bound into its fieldsShow an MXML-based data model with properties of TextInput controls bound into its fields
4.A TextInput's text property is bound to two data models, and data model properties are bound to the text properties of two Label controls.A TextInput's text property is bound to two data models, and data model properties are bound to the text properties of two Label controls.
5.shows an MXML-based data model with properties of TextInput controls bound into its fields:shows an MXML-based data model with properties of TextInput controls bound into its fields:
6.Max char and restrict letter for TextInputMax char and restrict letter for TextInput
7.Restrict input letter for TextInputRestrict input letter for TextInput