开发者

How to use a runtime generated Sprite object as the icon of a List or Tree?

开发者 https://www.devze.com 2023-01-30 16:43 出处:网络
I have been searching regards this question for months. By default, the iconFunction of List and Tree return only Class as the icon, which is for embeded images or iconUtility kindly provided by this

I have been searching regards this question for months.

By default, the iconFunction of List and Tree return only Class as the icon, which is for embeded images or iconUtility kindly provided by this site http://blog.benstucki.net/?p=42. It works very well with pre-created images.

But what I really want is to accept a completely runtime generate sprite object, similar to what is done by Legend, with the color changes according to what the current status. I assume I could do something to make the ListBase to accept icon argument other than Class. Am I rite? or please kindly advise what I shall do.

开发者_如何学运维

Thank you very much!

Wildog


Instead of setting the icon for the tree item, I would create a custom item renderer using TreeItemRenderer as a starting point. Then put whatever component you want to the left of the text and move the text to the right a bit. Another advantage of this approach is that you can have your sprite change dynamically as the data that gets set to the item renderer changes. Hope that helps.


I'm not sure if this is exactly what you want to do, but you can turn your sprite into BitmapData easily enough (Which you can use to create a BitmapAsset)

e.g.

var bmp:BitmapData = new BitmapData(sprite.width, sprite.height);
bmp.draw(sprite);

var bmpasset:BitmapAsset = new BitmapAsset(bmp);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号