Flex:修改嵌入式图标并在按钮中使用它? [英] Flex: Modify an embedded icon and use it in a button?

查看:383
本文介绍了Flex:修改嵌入式图标并在按钮中使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就是这样,如果你嵌入一个图标:

Just that, if you embed an icon:

[Embed(source='icons/checkmark.png')]
private static var CheckMark:Class;

你最终得到一个动态类。您可以通过调用setStyle方法在运行时轻松地将图标分配给按钮:

You end up with a dynamic class. You can pretty easily assign the icon to a button at runtime by calling the setStyle method:

var btn:Button = new Button();
btn.setStyle("icon", CheckMark);

但是如果你想在运行时更改图标,比如改变它的alpha值甚至重新绘制像素,该怎么办? ,在将它分配给按钮之前?

But what if you wanted to alter the icon at runtime, like changing it's alpha value or even redrawing pixels, before assigning it to the button?

到目前为止,我找不到满意的答案...

So far I can't find a satisfactory answer...

推荐答案

这是我能找到的唯一一个看起来很接近的答案:动态图标 (查看源示例)

This is the only answer I could find that seemed close: Dynamic Icons (example with View Source)

他的解决方案涉及一个自定义的DynamicIcon类,用于按钮的图标设置,以及一个自定义Button类,它为Button类添加一个方法来绘制动态图标。

His solution involves a custom "DynamicIcon" class which is used in the button's icon setting, and a custom Button class which adds one method to the Button class to draw dynamic icons.

最终结果是你可以将BitmapData发送到DynamicIcon类,它将显示在按钮中。因此,嵌入您的图像,实例化您的资产类,获取bitmapasset并根据需要修改它,并将bitmapData发送到图标。

The end result is that you are able to send BitmapData to the DynamicIcon class, which will show up in the button. So, embed your image, instantiate your asset class, get the bitmapasset and modify it however you need to and send the bitmapData to the icon.

这是一个有趣的问题,它似乎应该有一个更简单的解决方案,但这没有太多的麻烦。

It's an interesting problem and it seems like there should be an easier solution, but this works without a lot of hassle.

这篇关于Flex:修改嵌入式图标并在按钮中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆