Using Arrays for style properties of Tree component in Flex 4 or Flash Builder

February 1st, 2011 by aabhaanjan

By assigning colors to a property in an Array using comma-separated list to the property’s definition we can use array for style properties. The index is assigned to each entry in the order that it appears in the list.

Tree control’s depthColors style property can use a different background color for each level in the tree.

Example :


<?xml version=”1.0″?>






@namespace mx “library://”;

mx|Tree {

depthColors: #FF3300, #FFCC99, #CC9900;




<fx:XMLList id=”treeData”>

<node label=”Node 1″>

<node label=”subnode1″>

<node label=”text1″/>

<node label=”text2″/>

<node label=”text3″/>


<node label=”subnode2″>

<node label=”text1″/>

<node label=”text2″/>


<node label=”text1″/>

<node label=”text2″/>




<s:Panel title=”Style Using Array” width=”100%”>

<mx:Tree id=”myTree” width=”100%” labelField=”@label” dataProvider=”{treeData}”/>


Tags: ,