Setting a custom icon field in a Flex Tree control

The following example shows how you can specify a custom icon field in a Flex Tree control to set an icon on a specific node.

Full code after the jump.


<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<mx:Application xmlns:mx=""

            public var myBulletStarIcon:Class;

    <mx:XML id="dp">
            <league label="American League">
                <division label="East">
                    <team label="Boston" icon="myBulletStarIcon" />
                    <team label="New York" />
                    <team label="Toronto" />
                    <team label="Baltimore" />
                    <team label="Tampa Bay" />
                <division label="Central">
                    <team label="Cleveland" icon="myBulletStarIcon" />
                    <team label="Detroit" />
                    <team label="Minnesota" />
                    <team label="Chicago" />
                    <team label="Kansas City" />
                <division label="West">
                    <team label="Los Angeles" icon="myBulletStarIcon" />
                    <team label="Seattle" />
                    <team label="Oakland" />
                    <team label="Texas" />

    <mx:Tree id="TreeProject"
            height="240" />


View source is enabled in the following example.

8 thoughts on “Setting a custom icon field in a Flex Tree control

  1. Any chance you’ve got an example that allows for setting a unique icon based on the level of nesting? I.e., I’d like to have one icon for the first level of hierarchy, a different one for the second, etc.

  2. Anon,

    Nope, it isn’t me, but I more or less gave up trying to stop people from stealing my code. This blog has always been released under a Creative Commons license, but that never matters at the end of the day.

    I guess it’s all good as long as people are finding the content useful (I hope) and maybe eventually they’ll come back here. I’ve also been trying to add my content to other sources such as the Adobe Flex Cookbook ( and I’m hoping to get some content added to the Adobe Tour de Flex (


Comments are closed.