Help a newbie with a button problem

Hallo,

Just started to use corona and stuck in a simple place. How to make a button do something.

In simulator I see that button reacts to being pressed/released, but code is not running assigned to button:

local widget = require(“widget”)

local button = widget.newButton

{

defaultFile = “b1.png”,

overFile = “b2.png”,

onRelease = pressButton

}

button.x = 240

button.y = 400

– THIS IS NOT WORKING :frowning:

local function pressButton( event )

button.x = 240

button.y = 500    

end

=================

PLEASE PLEASE, how to make the damn button do stuff?

Thank you all

Lauras

Have you tried to move the function above the declaration of the button?

When onRelease is reached pressButton is nil.

(Hope this helps…) 

Tried. 

It gives error

attempt to index global ‘button’

What is strange, that I have done my code according to samples provided in corona. But mine doesnt’t work.

Any other solution please?

Lauras

Instead of using the “button” variable in your function, use this instead:

event.target

So for instance

event.target.x = 10

@luaras.balaisa

Sorry, about that. Do both what Danny and I suggested. 

Regarding buttons and touch events, phases are quite important and a good thing to look into. This is a good start:

http://developer.coronalabs.com/content/events-and-listeners#Touch_Events

Have you tried to move the function above the declaration of the button?

When onRelease is reached pressButton is nil.

(Hope this helps…) 

Tried. 

It gives error

attempt to index global ‘button’

What is strange, that I have done my code according to samples provided in corona. But mine doesnt’t work.

Any other solution please?

Lauras

Instead of using the “button” variable in your function, use this instead:

event.target

So for instance

event.target.x = 10

@luaras.balaisa

Sorry, about that. Do both what Danny and I suggested. 

Regarding buttons and touch events, phases are quite important and a good thing to look into. This is a good start:

http://developer.coronalabs.com/content/events-and-listeners#Touch_Events