Change Button Image during the game(ui.lua)

Hi. I'm using ui.lua to create buttons to my game. Is there a way to change the image of the button when the game is running? if yes, how can I do that?

is not possible. UI use display objects as images and image of a display object can't be changed. so the available option is to remove the old object and insert a new own.
see the sample below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local ui = require("ui")
local playBTN
 
local function gotogame()
 
  playBTN:removeSelf()
  playBTN = ui.newButton{
        default = "newimage1.png",
        over = "newimage2.png",
        onRelease = gotogame
  }
  playBTN.x = display.contentWidth /2
  playBTN.y = 210
 
end
 
playBTN = ui.newButton{
        default = "image1.png",
        over = "image2.png",
        onRelease = gotogame
}
playBTN.x = display.contentWidth /2
playBTN.y = 210

Ok. Thank you very much.

views:2869 update:2011/10/11 15:24:38
corona forums © 2003-2011