So I was having a problem dynamically creating icons for my Tree. What I have is an xml file that gets loaded up and has a tree created for it. Each item in the xml(tree node) has some information about it. One piece of info is the image that should be used for the node. As you know you can supply the iconFunction to the Tree. The problem is you can not just return a new Image with the source assigned to it. What you really need to return is a Class that is going to be used. So in searching around on the net I found this by Ben Stucki’s site. This is a great utility that allows you to have an image data created for you. It also keeps track of what UIComponent the data goes with by using a dictionary. However this is also the one problem for it as well. I don’t necessarily want to associate a UIComponent with the image data. In this case I just want the string value (link to my image) to be the item that is associated with the data. All that needs to be done to the IconUtility class is to change the first argument to * instead of UIComponent. Then you will be able to use this for your Tree or other ListBase iconFunction.
Flex Gig
Mostly flex related topics
« The Ride

11 Users Responded In This Post
Was looking for the same thing … This doesnt seem to be working for me …
I tried using it along with tree’s iconlabel function like
return IconUtility.getClass(data,”",w,h); Any suggestion ….
Sorry iconFunction!
Okay got it … it should be Tree.itemToItemRenderer(data) and not simply data …
Correct. Use the renderer. You will have to change the IconUtility class to accept any type of object and not just a UIComponent though.
I am using same method i.e.
return IconUtility.getClass(treeNode.itemToItemRenderer(item),”assets/images/network_icon_16.gif”); but icon is hiding when i am clicking on tree and on mouse move it showing. can u give me sample program
Hi,I meet the same problem withe Vijay.
How to resolve it?
how do you use the iconFunction if the tree is being instance use actionscript i.e
var tree:Tree()=new Tree();
tree.iconFunction = myFunc;
private function myfunc(item:Object):Class{
how can I know the tree?
}
if I use the mxml tree tag, the class work nice, but if the tree is dynamic crated, it will not work.
I have the same problem as Vijay. The icons get downloaded and assigned to the tree but they only become visible when i move the mouse pointer over the icon location. Then if the tree gets re-rendered (eg a branch gets expanded), all the icons disappear and will only show if the mouse is moved over them again. It’s driving me crazy, I can’t find what causes the icons to not show in the first place. Any ideas ? getting desperate here.
The solution I found is to keep a dictionary with a UID for each tree node as the key, and the returned Class as the value. When the iconFunction is called, check to see if the a Class already exists for this node, and if so, use it. Otherwise, get the icon using the above prescribed way, and then store it off in the dictionary.
Also, I found that due to animation, sometimes the call to itemToItemRenderer returns null so you cannot call getClass, thus no icon is shown right away. To solve this, just check if it returns null, and if so, call
this.callLater(myTree.invalidateList);
Pingback and Trackback
Leave A Reply