After playing with it for a while, I wasn't able to set the icon of a branch, but I was able for a leaf, though it's not that straightforward. 

[Embed('item_bullet.png')]
private var ITEM_BULLET_ICON: Class;

<mx:Tree iconField="icon" />
   <mx:dataProvider>
      <mx:XML>
         <node label="Node1" icon="Test2_ITEM_BULLET_ICON "/>
      </mx:XML>
   </mx:dataProvider>
</mx:Tree>

And what the heck is "Test2_ITEM_BULLET_ICON"?  It's the actual name of the class created by the embed.  You can see the name if you trace the variable ITEM_BULLET_ICON.  The project name I used was Test2 so that's where that came from.

I think the problem here is that the ListBase class (which Tree inherits from) requires a reference to the class when specifying the icon.  When I used a List component, the only way I got the icon to show up was to put the following in the Array dataprovider:

<mx:Object label="Item1" icon="{ITEM_BULLET_ICON}">

You can't do something like that for an XML dataprovider cause that XML is just seen as raw data, so you have to specify the name of the class to get it to work.

Meh...I just think it's broken.  It certainly doesn't follow what the docs say...


On 1/30/06, Brendan Meutzner < [EMAIL PROTECTED]> wrote:
Hi Jason,

Thanks for the reply.  I really should have been more specific last
night when I posted this...  I'm actually trying to define an icon
within the individual nodes using the "icon" parameter.  I've defined
the Class as you have by embedding an asset, but when I try to
reference that asset like so:

[Embed(source='mypng.png')]
public var myCustomIcon:Class;

<mx:Tree iconField="icon" />

and within the dataprovider structure for the tree...

<node label="Node 1" icon="myCustomIcon" />


it gives me the error I described previously.  What works in 1.5 does
not work in 2.0, although it's document the same... well actually, not
quite the same... the documentation for 2.0 still states that the
embedded asset be typed as String.  So it works as a String in 1.5,
but I've tried both String and Class in 2.0 with no luck.

Thanks,

Brendan



--- In flexcoders@yahoogroups.com, "Jason Y. Kwong" <[EMAIL PROTECTED]>
wrote:
>
> This works for me:
>
>     <mx:Script>
>         <![CDATA[
>             [Embed('item_bullet.png')]
>             private var ITEM_BULLET_ICON: Class;
>         ]]>
>     </mx:Script>
>
>     <mx:Canvas width="100%" height="100%">
>         <mx:Tree defaultLeafIcon="ITEM_BULLET_ICON">
>            ....
>         </mx:Tree>
>     </mx:Canvas>
>
> Or you can short-hand it a bit:
>
>         <mx:Tree defaultLeafIcon="@Embed('item_bullet.png')">
>
>
>
> On 1/30/06, Brendan Meutzner <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > When I try to implement a custom icon in a Tree component for Flex
> > 2.0, it gives me a runtime error stating that it can't find the
> > variable I've defined for the icon class...
> >
> > Has anyone gotten this to work?  I can post code if need be...
> >
> > Thanks,
> >
> > Brendan
> >
> >
> >
> >
> >
> >
> >
> > --
> > Flexcoders Mailing List
> > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >
>







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to