Critter’s Code

This is a picture of a bridge and a city. I like bridges and cities. They make me smile.

Jan-17-2008

Changing button icons at runtime using Actionscript

Changing button icons at runtime using Actionscript8.5104

I had to do quite a bit of searching around this morning to figure out how to change the icons on my video player at runtime.

phoenix-032   phoenix-031

I thought I could easily modify the [button].icon property, but I could not access that at runtime. You can, however, do the following:

//    embed your icons
[Embed(source='com/images/play.png')]
[Bindable]
public var imagePlay:Class; 

[Embed(source='com/images/pause.png')]
[Bindable]
public var imagePause:Class;

//    using one button to toggle play and pause of video
private function playpause():void
{
    if (seesmicVideo.playing)
    {
        seesmicVideo.pause();
        btn_play.setStyle("icon",imagePlay);
    }
    else
    {
        seesmicVideo.play();
        btn_play.setStyle("icon",imagePause);
    }
}        

Using [button].setStyle() will allow you to change the icon at runtime.

VN:F [1.7.5_995]
Rating: 8.5/10 (4 votes cast)
VN:F [1.7.5_995]
Rating: +2 (from 2 votes)
Posted under AIR, ActionScript, Flex, Samples
  • Alejandro
    Excellent tip. Thanks a lot.
blog comments powered by Disqus