tags:

views:

224

answers:

1

I have a collection of objects that are displayed in two places - spatially as icons on a map, and in a tree control. I'd like to know if it's possible to use the image URLs that I use for displaying the icons elsewhere in a tree control.

I've tried simply using the name of the field that contains the URL as the iconField on the tree control, but apparently when the flex framework sees a string field as the icon field it looks for a property on the mxml file containing the tree with a name that's the same as the string value for the field on the tree item(!?!). Since my layout documents don't have any fields with names like "assets/well.png", this throws an error.

I need to reference the icons using the URL of the images rather than through embedding, because the client will need to be able to change the image without a recompile.

+1  A: 

Tree setItemIcon function (or itemIcons property) takes two Class objects as parameters. A possible solution would be to add this class to your project, and then use the following code to dynamically load your assets:

yourTree.itemIcons = {iconID: IconUtility.getClass(icon1, 'path/icon1.jpg'), iconID2: IconUtility.getClass(icon2, 'path/icon2.jpg')};


Edit:
Original post about the IconUtility class : http://blog.benstucki.net/?p=42

Zed-K