How To Change widget.newButton newButton image or Can I?

I need to change my widget.newButton’s image after taping on to indicate whether or not a selection was correct or incorrect…

Example :

myBtn = widget.newButton{      id = "myBtn",      left = 255,      top = 58,      width = 44,      height = 44,      default = "image1.png",      over = "image2.png",      onEvent = onBtn }   -- trying to change image after tap. local onBtn = function( event )              if (event.target.id == "Y" ) then             print("Correct....")                         myBtn.default = "correct.png"             NextQuestion(appGlobals.CurrentQuestion);         else            print("Wrong....")            myBtn.default = "wrong.png"                    end end

Hi @doubleslashdesign,

Once you configure the widget button, you can’t later change (dynamically) what the “default” and “over” images will be. You would need to re-create the button, i.e. put a new one in place of the previous one.

Also, as a quick note, in your code above the “onBtn” function will not be called because it’s out of scope. You declared it as a local function below the widget setup which calls it, so that widget will not be aware of that function at all.

Take care,

Brent

Hi @doubleslashdesign,

Once you configure the widget button, you can’t later change (dynamically) what the “default” and “over” images will be. You would need to re-create the button, i.e. put a new one in place of the previous one.

Also, as a quick note, in your code above the “onBtn” function will not be called because it’s out of scope. You declared it as a local function below the widget setup which calls it, so that widget will not be aware of that function at all.

Take care,

Brent