Hello,
I have a question regarding passing a parameter to a function from an event listener.
Not sure that it sounds very clear. Basically, in the example below, when i press the magenta (myButton) rectangle, i want to move the grey rectangle (myRectangle) from a Y distance passed from the listener :
local myRectangle = display.newRect(150, 300, 150, 50)
myRectangle.strokeWidth = 3
myRectangle:setFillColor(140, 140, 140)
myRectangle:setStrokeColor(180, 180, 180)
local myButton = display.newRect(100, 400, 150, 50)
myButton.strokeWidth = 3
myButton:setFillColor(140, 0, 55)
myButton:setStrokeColor(180, 180, 180)
local function moveY (distance)
myRectangle.y = myRectangle.y - distance
end
myButton:addEventListener("touch", moveY(20))
i tried also:
myButton:addEventListener("touch", moveY(event, 20))
myButton:addEventListener("touch", moveY(,20))
Nothing seems to work.
Any idea if it is possible or if there is a workaround?
Thanks for the help!
Dim [import]uid: 100310 topic_id: 24852 reply_id: 324852[/import]