R – Flashing Button with Flex/Action Script

actionscript-3flashflex3

I want to make a button flash red in response to an event, and then stop flashing whenever the button is pressed. This would be much like the master alarm button in an aircraft. So the flashing effect needs to be something that I can programmatically stop.

I saw one example using a timer, but I want to avoid using a timer because I don't like to use timers unless I really have to. It just seems really chaotic to have all this timers going just to do trivial little things.

My hope is that there is some way to do a little animation with flash or something, on the button, and just tell the animation to play to make the button flash, and then stop/reset the animation to put it back at the original not flashing state.

I am using Flex Builder 3. I am new to Action Script and Flex/Flash.

Can someone give information on how to do this or point me to some information?

Thanks.

Best Answer

I would try with a tweening engine... something like this:

function flash() {
   TweenLite.to(button, .5, {tint:0xFF0000, onComplete:unflash});
}
function unflash() {
   TweenLite.to(button, .3, {removeTint:true, onComplete:flash});
}

function deleteFlashing(e) {
   TweenLite.killTweensOf(button);
   TweenLite.to(button, .2, {removeTint:true});
}