Flex Blog

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!

    • Thumb

      Flex Mobile Examples

      Check out our Flex Mobile 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
  • Flex Books
  • Forum
  • Contact Us
Subscribe to Flex BlogSubscribe
  • Examples
  • iOS
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 (47 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?

Please rate this post, follow us @ twitter, or link to this page from your website!

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

832a10f4721c85e52e3107c709f4618ddelicious

Comments

6 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!

  4. Arjan on November 17th, 2010 7:17 pm

    Hey Arjan,
    Is there a way to disable the disclosureopen/closeicon for partticular rows of an ADG programmatically ??

    Bhargav

  5. Arjan on November 18th, 2010 7:58 am

    Yeah that should be possible by doing some additional coding on the click event to check wheter this item can be opened or not. Stopping event propagation might work for this. Im not sure if you can show another icon/image for the “disabled” rows, but propably, there is.

  6. murali on January 19th, 2011 11:10 am

    hello sir! i have an advanced data grid which shows heirachial data. and two buttons to expand all and one button to revert back. after expanding all how can i revert back to previous perspective(opening same nodes which were opened before clicking expand all)
    plz help me

Get Adobe Flash player

  • +1?

  • Support Flex Blog!

  • $ 13 raised
    • 2012/01/13 8:22 PM Russell Brown donated $ 3.00
    • 2011/10/31 4:43 PM Steve Dakin donated $ 5.00
    • 2011/05/11 3:37 PM Roelof Albers donated $ 5.00
  • Stay in touch!

  • Popular Tags

    • AdvancedDataGrid
    • AIR
    • ArrayCollection
    • baseColor
    • Button
    • CursorManager
    • DataGrid
    • Dynamic
    • Effects
    • File
    • FileStream
    • Flash Builder
    • Flash Builder 4
    • Flex 4
    • Flex Mobile
    • Framework
    • Icon
    • Image
    • itemRenderer
    • LinkBar
    • Mobile
    • PHP
    • ProgressBar
    • Repeater
    • Style
    • SWIZ
    • Timer
    • Tree
    • Twitter
    • ViewStack
  • Advertisements

  • Recent Posts

    • Spooky Frenzy – iPad Game
    • Fountain Example
    • Reading & Writing files in Adobe AIR
    • CheckBox in List using MobileIconItemRenderer for Flex Mobile
    • Data Dependent decoratorClass in MobileIconItemRenderer Example
    • Flex 4 Resize Effect Example
    • Jump to next field using the Focus Manager
    • Searching Data using a Class Example
    • Flex Mobile: Two finger tap gesture to toggle actionBar visibility in a View (AIR for Android)
    • TabbedMobileApplication Example in Flex Mobile (AIR for Android)
  • Categories

    • Examples
    • Guest Poster
    • iOS
  • Archives

    • September 2011
    • July 2011
    • May 2011
    • March 2011
    • February 2011
    • November 2010
    • October 2010
    • September 2010
    • 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

    • Progressbar in Datagrid Example 13 votes, average: 5.00 out of 513 votes, average: 5.00 out of 513 votes, average: 5.00 out of 513 votes, average: 5.00 out of 513 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction 8 votes, average: 5.00 out of 58 votes, average: 5.00 out of 58 votes, average: 5.00 out of 58 votes, average: 5.00 out of 58 votes, average: 5.00 out of 5 (5.00 out of 5)
    • List Directory with AIR in Flex 4 7 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Flex FlashVars in AS3 Example 7 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Flex Dynamic Chart 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)