Use iconFunction to determine the icon to display : Icon « Graphics « Flex






Use iconFunction to determine the icon to display

Use iconFunction to determine the icon to display
         
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
        
        [Embed(source="logo.jpg")]
        public var imageIcon1:Class;
        [Embed(source="logo.jpg")]
        public var normalSymbol:Class;
        private var myData: Array;
        private function initList():void {
            myData = [{Artist:'A', Album:'AA',Price:1.99},
                      {Artist:'B', Album:'BB',Price:1.99},
                      {Artist:'C', Album:'CC',Price:5.99}];
            list1.dataProvider = myData;
        }
        private function myiconfunction(item:Object):Class{
            var type:String = item.Artist;
            if (type == "A") {
                return imageIcon1;
            }
            return normalSymbol;
        }
      
    </mx:Script>
    <mx:VBox>
        <mx:List id="list1" initialize="initList()" labelField="Artist" iconFunction="myiconfunction" />
    </mx:VBox>
</mx:Application>

   
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.Bind icon to classBind icon to class
2.Set the default leaf icon to null to hide it, and uses custom icons for the folder open and closed iconsSet the default leaf icon to null to hide it, and uses custom icons for the folder open and closed icons
3.Adding an icon to the buttonAdding an icon to the button