Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

NEED HELP - Events and Listeners against Functions
Started by iphone_2010 Nov 18 2010 06:33 PM

1 reply to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

iphone_2010

[GLOBAL: userInfoPane.html]
iphone_2010
  • Enthusiast

  • 92 posts
  • Guests

I have been trying to understand the different between function listeners and table listeners for longtime but i couldn't. I really would like to know what is exactly this and how i can decide which one to be used. Moreover, im very week in OOP programing and this might be the problem.

Im wondering also, what is the ":" and how you use it, for example :-

when you say:-
function bird:touch(even)
-- body
end
AND

function bird (event)
-- body
end

or when you say:-

local listener = function (event)
end
bird:addEventListener( "touch", listener )
uid: 11038 topic_id: 3780 reply_id: 303780


[TOPIC: post.html]
#2

jmp909

[GLOBAL: userInfoPane.html]
jmp909
  • Corona Geek

  • 1,328 posts
  • Corona SDK

the table listener means add that event to that object
eg
-- touch event is added to my text fieldfunction play_txt:touch(event)	print("touch")end-- pass any touch events to play_txt-- since there is a :touch table listener registered -- then it will receive the eventRuntime:addEventListener("touch",play_txt)


a listener means a function is registered for an event, triggered from an object
eg
local listener = function(event)   print(event.name.." occurred on"..tostring(event.target))   print(event.target==play_txt)end  -- play_txt listens to touch events-- call the "listener" function when this occursplay_txt:addEventListener("touch", listener )


uid: 6645 topic_id: 3780 reply_id: 11539



[topic_controls]
[/topic_controls]