DataGroup item added event : DataGroup « Data Model « Flex






DataGroup item added event

DataGroup item added event
         
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:s="library://ns.adobe.com/flex/spark">
    <mx:Script>
        
            import spark.events.RendererExistenceEvent;
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            
            private function itemAdded( evt:RendererExistenceEvent ):void
            {
                Alert.show(evt.index + " : " + evt.data + " : " + evt.renderer );
            }
            private function itemRemoved( evt:RendererExistenceEvent ):void
            {
                Alert.show(evt.index + " : " + evt.data + " : " + evt.renderer );
            }
            
            private function addItem():void
            {
                if( collection.length > 0 )
                    myContent.dataProvider.addItem( collection.removeItemAt(0) );
            }
            private function removeItem():void
            {
                if( myContent.dataProvider.length > 0 )
                {
                    var item:Object = myContent.dataProvider.removeItemAt( myContent.dataProvider.length - 1 );
                    collection.addItem( item );
                }
            }
      
    </mx:Script>
    <mx:String id="txt">this is a test</mx:String>
    <mx:ArrayCollection id="collection">
         <mx:Label text="Using DefaultComplexItemRenderer." />
         <mx:Button label="button 1" />
         <s:DropDownList dataProvider="{new ArrayCollection(txt.split(' '))}" />
         <mx:CheckBox selected="true" />
    </mx:ArrayCollection>    
    <s:DataGroup id="myContent"
                 rendererAdd="itemAdded(event);" 
                 rendererRemove="itemRemoved(event);"
                 itemRenderer="spark.skins.spark.DefaultComplexItemRenderer">
        <s:dataProvider>
            <mx:ArrayCollection />
        </s:dataProvider>
        
    </s:DataGroup>
    
    <mx:Button label="add" click="addItem();" />
    <mx:Button label="remove" click="removeItem();" />
    
</mx:Application>

   
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.Associating a DataGroup container's dataProvider with an array of strings.
2.Use the DefaultItemRenderer with a DataGroup containerUse the DefaultItemRenderer with a DataGroup container
3.shows a DataGroup container where all its children are Flex components.shows a DataGroup container where all its children are Flex components.
4.Item renderer for DataGroupItem renderer for DataGroup
5.DataGroup with Data providerDataGroup with Data provider
6.Control DataGroup widthControl DataGroup width
7.TitleLayout for DataGroupTitleLayout for DataGroup
8.DataGroup item removed eventDataGroup item removed event
9.Lazily Create and Recycle ChildrenLazily Create and Recycle Children
10.LayOut Children Using Rows and ColumnsLayOut Children Using Rows and Columns
11.Create a Custom 3D LayoutCreate a Custom 3D Layout