Changing the Button Icon Dynamically.Using the setStyle() method.

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:

Download code here

5 Responses to “Changing the Button Icon Dynamically.Using the setStyle() method.”

  1. Flex user Says:

    Very good post. Thank you

  2. Jason R Says:

    Thanks. Allowing view source on your example would be appreciated.

  3. andy matthews Says:

    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.

Leave a Reply