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:

[showmyads]
Download code here

About these ads

13 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. 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.

  4. Nicola says:

    Many Thanks

  5. pixel_1001 says:

    Thanks!! very useful!

  6. JOTHEES says:

    how can i set shortcut key in menubar in flex4?

  7. Darren says:

    Is it possible to load the icon image from a URL instead of having to be embedded in the app?

  8. jmatosjr says:

    It worked just fine to me. Thanks a lot.

  9. Flexlerner says:

    Thank u.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: