Timer Issue

I want to have buttons in an app that “flash”. I was planning on doing that by changing the bitmap on a button. I haven’t figured out how to do that, but I did figure how to hide a button. So, to prototype what I want to do, I tried hiding the button and showing it to simulate flashing.

I am using the timer function to execute the flash logic, but it doesn’t work the way I think it should.
This code:

local function flash( event )  
 print ( "flash" )  
 if b10.isVisible  
 then b10.isVisible = false  
 else b10.isVisible = true  
 end  
 end  
  
function MainHandler( event )  
  
 timer.performWithDelay( 5000, flash, 0 )  
  
end  
Runtime:addEventListener("enterFrame", MainHandler)  

Causes the B10 button to be solid for five seconds, then it flashes really fast off and on for five seconds, then solid again and back and forth. I would expect it to turn on for five second, off for five seconds and alternate that every five seconds, but it doesn’t. Am I reading the code reference wrong? Or is this a bug?

Any other suggestions (including an example of how to change the bitmap on a button) would be greatly appreciated!

Thanks. [import]uid: 25195 topic_id: 5421 reply_id: 305421[/import]

Just to respond to one thing you said: I wouldn’t change the button’s bitmap – I’d create two different buttons where one is visible and the other is not. Just toggle between them.

I’m not sure about the timer issue.

If no one else responds to this thread and you can’t figure it out, try to create a small stand-alone program that will illustrate the problem using rectangles instead of bitmaps, and post that code.
[import]uid: 9659 topic_id: 5421 reply_id: 18181[/import]

Thank you, that worked. (But the boolean flip didn’t seem to work for some reason. For now, I just left the if/then logic. I’ll play with it more as I learn the language more.) [import]uid: 25195 topic_id: 5421 reply_id: 18266[/import]

should be .isVisible sorry not .visible (updated) [import]uid: 6645 topic_id: 5421 reply_id: 18418[/import]

[lua]b10.isVisible=true

local function flash( event )
b10.isVisible = not b10.isVisible
end

timer.performWithDelay( 5000, flash, 0 )[/lua]

no need for enterframe there specifically
[import]uid: 6645 topic_id: 5421 reply_id: 18188[/import]