Hi community,
My code is - I believe - really basic and I don't see where the error comes from.
I have tried to isolate the part that raises an issue. Error could be located somewhere else but I have no idea where it could be :
function Interface:init()
-- FB
local fbButton
fbButton = Button.new(Bitmap.new(...))
fbButton:addEventListener("click", self.onFbClick, self)
stage:addChild(fbButton)
fbButton.debugName = "bob"
end |
and
function Interface:onFbClick(event)
local target = event:getTarget()
print (target.debugName) -- prints "bob" correctly
print (event.x, event.y) -- prints "nil, nil"
if target:hitTestPoint(event.x, event.y) then -- And then here the error happens -> bad argument #1 to 'hitTestPoint' (number expected, got nil)
event:stopPropagation()
print ("Fb sharing")
end
end |
I don't understand why I can get the target from the event, but not event.x and event.y.
Has it ever happened to you and how did you solve it?
Comments
You want to get x,y coordinate of the place on the fbButton?
event:getTarget() return the button, not the listener function.
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
About the Button class -> Wow, I love it when Gideros already does the work for me (I should have checked the code more).
My mistakes :
- I assumed that *all* click events come with event.x and event.y fields set
- Lack of understanding of what the Button class is doing under the hood
So here is what I had to do :Likes: atilim