Jan-17-2008
Changing button icons at runtime using Actionscript
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.
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.
Posted under AIR, ActionScript, Flex, Samples