Attempt to call method 'setEnabled' (a nil value)

I am trying to make a button unable to touch after i create it, like this:

mybutton:setEnabled("false")

and i will enable its touch again after some transitions will happen;

but is giving me error: Attempt to call method ‘setEnabled’ (a nil value)

Thanks in advance

Hi @blablu1212,

Most likely, this is because Lua doesn’t know the button reference any longer (perhaps you moved to a different scene, or the reference was in the scope of a function but nowhere outside of it, etc.).

Also, remember that :setEnabled() accepts a boolean true or false, not a string “true” or “false”.

[lua]

mybutton:setEnabled( false )

mybutton:setEnabled( true )

–NOT THIS

mybutton:setEnabled( “false” )

mybutton:setEnabled( “true” )

[/lua]

Brent

Sorry @Brent for string, i was messing around with it and copy-paste the last version.

But i tried a bool ( false ) value and i get same error.

local function createbutton() -- body local mygroup=display.newGroup() local button=widget.newButton { id = "btnid", left=0, top=0, defaultFile = "button-default.png", overFile = "button-over.png", onRelease=release\_function } button.width=100 button.height=40 button.isVisible=true button:setEnabled(false) --false or true, gives same nil error mygroup:insert(button) end

Is there any way to disable touch click for an entire display group object?

Thanks

Hi @blablu1212,

I can’t imagine why this isn’t working for you. I pasted your code into a test app and it works fine… no errors, and the button is disabled.

What version of Corona are you using? What is your system specifications?

Brent

Do you mean you are trying at a later point to use :setEnabled(true) and this isn’t working?

If so your ‘button’ reference is local to createButton, so trying to access it outside of that function won’t work. If you put local button at the top of the file, then button = widget.newButton…   , you can then access the object later on.

@Brent,

i am using Version 2014.2511 (2014.11.18), i am working on OS X Yosemite 10.10.2

@nick_sherman

i am using same code as above. I put it inside the general function

Hi @blablu1212,

Most likely, this is because Lua doesn’t know the button reference any longer (perhaps you moved to a different scene, or the reference was in the scope of a function but nowhere outside of it, etc.).

Also, remember that :setEnabled() accepts a boolean true or false, not a string “true” or “false”.

[lua]

mybutton:setEnabled( false )

mybutton:setEnabled( true )

–NOT THIS

mybutton:setEnabled( “false” )

mybutton:setEnabled( “true” )

[/lua]

Brent

Sorry @Brent for string, i was messing around with it and copy-paste the last version.

But i tried a bool ( false ) value and i get same error.

local function createbutton() -- body local mygroup=display.newGroup() local button=widget.newButton { id = "btnid", left=0, top=0, defaultFile = "button-default.png", overFile = "button-over.png", onRelease=release\_function } button.width=100 button.height=40 button.isVisible=true button:setEnabled(false) --false or true, gives same nil error mygroup:insert(button) end

Is there any way to disable touch click for an entire display group object?

Thanks

Hi @blablu1212,

I can’t imagine why this isn’t working for you. I pasted your code into a test app and it works fine… no errors, and the button is disabled.

What version of Corona are you using? What is your system specifications?

Brent

Do you mean you are trying at a later point to use :setEnabled(true) and this isn’t working?

If so your ‘button’ reference is local to createButton, so trying to access it outside of that function won’t work. If you put local button at the top of the file, then button = widget.newButton…   , you can then access the object later on.

@Brent,

i am using Version 2014.2511 (2014.11.18), i am working on OS X Yosemite 10.10.2

@nick_sherman

i am using same code as above. I put it inside the general function