Change Button Options

I have created a button widget object on the app and set some properties to it.

After some time i want to change the default file image of the button, but don’t want to recreate the object again. Is this possible in corona?

local button1 = widget.newButton { width = 240, height = 120, defaultFile = "buttonDefault.png", overFile = "buttonOver.png", label = "button", onEvent = handleButtonEvent } -- Center the button button1.x = display.contentCenterX button1.y = display.contentCenterY -- Change the button's label text button1:setLabel( "2-Image" ) -- Change the button's default file button1:setDefaultFile("buttonDefault-Changed.png") ????

Hi @blablu1212,

This could be done via a somewhat advanced workaround, but generally no, you can’t change the button image after it has been created. I suggest you re-create the object OR that you create a button that is mostly transparent, and you place some other non-button image behind it. Then, you could remove and replace that image without replacing the entire button.

Brent

Thats a very good idea @Brent, i will keep it in mind :slight_smile:

For now i fixed it by creating 2 buttons, one visible and the other invisible (that consumes more memory that idea you gave me)

Thanks :slight_smile:

Hi @blablu1212,

This could be done via a somewhat advanced workaround, but generally no, you can’t change the button image after it has been created. I suggest you re-create the object OR that you create a button that is mostly transparent, and you place some other non-button image behind it. Then, you could remove and replace that image without replacing the entire button.

Brent

Thats a very good idea @Brent, i will keep it in mind :slight_smile:

For now i fixed it by creating 2 buttons, one visible and the other invisible (that consumes more memory that idea you gave me)

Thanks :slight_smile: