Search:
  • Home
  • Examples
    • Thumb

      Flex Examples

      Check out our Flex Examples!

    • Thumb

      Flash Builder Examples

      Check out our Flash Builder Examples!

    • Thumb

      AIR Examples

      Check out our AIR Examples!

    Adobe® Flex, Adobe® Flash Builder and Adobe® AIR are registered trademarks of Adobe Systems.
  • Components
    • Thumb

      WP Flex Contact Form

      Check out our WP Flex Contact Form!

    • Thumb

      Flash CountDown Plugin

      Check out our Flash CountDown Plugin!

    This is an overview of all our Flash/Flex based Components.
  • Jobs
  • Guest Poster
  • Forum
  • Contact Us
Subscribe to Flex BlogSubscribe
  • Examples
Browse > Home / Examples / Change open and close icons on Flex Tree

Change open and close icons on Flex Tree

12 November 2009

Line Break

Author: Arjan (36 Articles) - Author Website

Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and music. He is also the co-owner of Flex-Blog.com.


Personally I don’t like the default open / close icons (the down arrow / right arrow icons ) on the Tree control in Flex. Luckily, can can easy change them into a different icon.

The Flex Tree has a number of properties you can style, what we are looking for here are the following two: disclosureOpenIcon and disclosureClosedIcon.

So lets declare a Tree and some XML data provider:

XML Data:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<mx:XML xmlns="" id="xml"> 
    <data>
        <node name="node1">
            <node name="node2">
                <leaf name="Leaf1"/>
                <leaf name="Leaf2"/>
            </node>
        </node>
        <node name="node3">
            <leaf name="Leaf3"/>
            <leaf name="Leaf4"/>
            <leaf name="Leaf5"/>
        </node>
        <node name="node4">
            <leaf name="Leaf6"/>
        </node>
    </data>
</mx:XML>

Tree control:

1
2
3
4
5
6
<mx:Tree id="tree"
         dataProvider="{xml}"
         width="300"
         height="360"
         labelField="@name"
         showRoot="false"/>

Ok, now we need to embed the icons we are going to use instead of the default arrow icons:

In your script section add the following (assuming that you have an assets folder with the two icon files in them:

1
2
3
4
5
[Embed(source="assets/plus.gif")]
public var plus:Class;
           
[Embed(source="assets/minus.gif")]
public var minus:Class;

Ok, now all we need to do is to set the disclosureOpenIcon and disclosureClosedIcon styles, lets create an method that’s called on the initialize event that does this:

1
2
3
4
5
private function init():void
{
        tree.setStyle("disclosureOpenIcon", minus);
    tree.setStyle("disclosureClosedIcon", plus);
}

That’s all, take a look at the sample application below to see the result (use right-mouse->view source to see the complete source code):

Related posts:

  1. Remove Folder and File icons from Flex Tree
  2. Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction
  3. Style Flex Tree Label Example
  4. Drag and Drop from DataGrid or AdvancedDataGrid to Tree
  5. Tree in Advanced DataGrid Example

Written by Arjan · Filed Under Examples 

Was this post useful to you?

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4.67 out of 5)
Loading ... Loading ...

Comments

3 Responses to “Change open and close icons on Flex Tree”

  1. Alison on December 15th, 2009 4:21 pm

    Is it possible to the header text works as a link to expand the node?
    In this example, only the tree expands when we clik on the minus and plus icon. I wanna clik en the header (node1… node6) and expand the tree.

    Is it possible?

    Thanks

  2. Arjan on December 15th, 2009 9:08 pm

    Hi Alison,

    Yeah that’s possible. Just add an event listener to your Tree component on the click event:

    click=”handleClick(event)”

    And add the following function to your script:

    private function handleClick(event:MouseEvent):void
    {
    tree.expandItem( tree.selectedItem, !tree.isItemOpen( tree.selectedItem ) );
    }

    This will open the clicked item if it’s closed and close it if it’s open.

    Good luck!

    Arjan

  3. Alison on December 16th, 2009 1:54 pm

    Hi Arjan.

    Thank you. Works perfectly!

Get Adobe Flash player

  • Sponsors

  • Popular Tags

    • AdvancedDataGrid
    • AIR
    • ArrayCollection
    • baseColor
    • Button
    • CursorManager
    • DataGrid
    • Dynamic
    • Effects
    • File
    • Flash Builder
    • Flash Builder 4
    • Flashvars
    • Flex 4
    • Framework
    • HSlider
    • Icon
    • Image
    • itemRenderer
    • LinkBar
    • PHP
    • ProgressBar
    • Repeater
    • Style
    • SWIZ
    • Timer
    • Tree
    • Twitter
    • ViewStack
    • VSlider
  • Flex Blog Readers

  • Flex Jobs (from Flex Jobs.org)

    Your Job here? Post your job @ Flex Jobs.org

    Advertisement

  • Recent Posts

    • SWIZ Framework in Flex 4 Example: Part I
    • Dynamic AdvancedDataGridColumn in Flex 4
    • How to make a magnetic button in Flex 4
    • Using ASDoc as an External Tool in Flash Builder 4
    • Flex Encryption (MD5, SHA1, SHA224, SHA256, HMAC)
    • The SWIZ framework for Flex 3 / Flex 4: Easy, Light and Very Powerfull
    • Call Javascript function from Flex / Flash Builder (AS3)
    • Flex FlashVars in AS3 Example
    • Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction
    • WordPress Flash / Flex Comments Form
  • Categories

    • Examples
    • Guest Poster
  • Archives

    • August 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • October 2009
    • March 2009
    • February 2009
  • Blogroll

    • Adobe Flex Jobs
    • NL for Business
  • Meta

    • Register
    • Log in
    • WordPress
    • XHTML

Copyright © 2010 Flex Blog · AdobeĀ® and AdobeĀ® Flex are registered trademarks of Adobe Systems.

WordPress Adobe Flex Adobe Flash Builder Adobe AIR Creative Commons License

  • Popular Posts

    • List Directory with AIR in Flex 4 5 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Control Webpage in HTML Control in AIR 5 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction 5 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Progressbar in Datagrid Example 4 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 5 (5.00 out of 5)
    • WordPress Flash / Flex Comments Form 4 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 5 (5.00 out of 5)