Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Local function vs class function — Gideros Forum

Local function vs class function

twisttaptwisttap Member
edited April 2013 in General questions
Hello what is the difference between

local function onClick(but)
print("aa", but.name)
end

AND

function main:buttonListener(but)
print("aa", but.name)
end

I have

in my init file I want to use second one (the class method) but it does not work.

function main:init()
_sbtn1:addEventListener("click", onClick, _sbtn1) -- Works with local function well
_sbtn1:addEventListener(Event.MOUSE_DOWN, self.buttonListener, _sbtn1) -- Does not work.

end

BTW, my buttons are created and placed on stage on an another file but they are Global.

Comments

  • atilimatilim Maintainer
    Here, I think self is nil. Therefore you need to write:
    _sbtn1:addEventListener(Event.MOUSE_DOWN, _sbtn1.buttonListener, _sbtn1)
Sign In or Register to comment.