Avg. Rating 2.0

Problem

You want to change the default icon of a single node in the tree

Solution

Use the iconField method

Detailed explanation

The Application:

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="horizontal" viewSourceURL="srcview/index.html">
    <mx:Script>
        <![CDATA[
           
           
            [Bindable]
            [Embed("assets/closed.png")]
            public var myFolderClosedIcon:Class;

            [Bindable]
            [Embed("assets/opened.png")]
            public var myFolderOpenIcon:Class;


            [Bindable]
            [Embed("assets/pdf.png")]
            public var pdfIcon:Class;
           
            [Bindable]
            [Embed("assets/doc.png")]
            public var docIcon:Class;
           
           
        ]]>
    </mx:Script>
    <mx:XML id="xmlData" xmlns="">
        <rootNode>
            <directory label="dir">
                <file icon="pdfIcon" label="label1"  />
                <file icon="docIcon" label="label2"  />
            </directory>
            <directory label="dir1">
                <file icon="pdfIcon" label="label3"  />
                <file icon="docIcon" label="label4"  />
            </directory>
        </rootNode>
    </mx:XML>
    <mx:Panel title="Tree">
       
   
    <mx:Tree
       
        borderStyle="none"
        backgroundAlpha="0"
        labelField="@label"
        iconField="@icon"
          width="300"
          height="200"
        id="treeAdmin"
        folderOpenIcon="{myFolderOpenIcon}"
        folderClosedIcon="{myFolderClosedIcon}"
       
        dataProvider="{xmlData.directory}" alpha="1" />
       
        </mx:Panel>
</mx:Application>



 

For an Italian version of this entry please visit flex-developers.org

 

Report abuse

Related recipes