Dynamically to change the icon of a Button, you can use the following code and its simple and small.
For Example in MXML There’s a Button:
<Button id=”btn” icon=”@Embed(images/icon1.png)” />
Then to change the Icon for the Above Button in AS use the Following code in Script Tag:
[Embed(source=”images/icon2.png”)]
[Bindable]
public var iconSymbol:Class;btn.setStyle(“icon”,iconSymbol); —>This will change the icon.
This change can be made on an Event like click on another Button.
Click here to view the Example of it.
Think Dynamically, 🙂 Enjoy the Post.Comments are welcome.
Updated:
[showmyads]
Download code here
Very good post. Thank you
Thanks. Allowing view source on your example would be appreciated.
Hi,
i will mail you the code, thanks.
regards,
kumar.
Would you please post the code for this example? It’s exactly what I’m looking for, but I’m not able to duplicate your results.
Hi,
i will do that ASAP.
regards,
kumar.
Many Thanks
Thank you~!
Thanks!! very useful!
how can i set shortcut key in menubar in flex4?
Is it possible to load the icon image from a URL instead of having to be embedded in the app?
“Button icons must be embedded at compile time” , or you can use Image control to load image at run time here using URL.
regards,
kumar.
It worked just fine to me. Thanks a lot.
Thank u.