Difference between revisions of "EventDispatcher:removeEventListener"
From GiderosMobile
m (formatting) |
|||
| (2 intermediate revisions by one other user not shown) | |||
| Line 4: | Line 4: | ||
=== Description === | === Description === | ||
Removes a listener from the [[EventDispatcher]] object. | Removes a listener from the [[EventDispatcher]] object. | ||
| − | < | + | <syntaxhighlight lang="lua"> |
EventDispatcher:removeEventListener(type,listener,data) | EventDispatcher:removeEventListener(type,listener,data) | ||
| − | </ | + | </syntaxhighlight> |
'''removeEventListener()''' function expects the same arguments than the '''addEventListener()''' to remove the event. | '''removeEventListener()''' function expects the same arguments than the '''addEventListener()''' to remove the event. | ||
| Line 16: | Line 16: | ||
'''listener''': (function) the listener object to remove<br/> | '''listener''': (function) the listener object to remove<br/> | ||
'''data''': (any) the data parameter that is used while registering the event<br/> | '''data''': (any) the data parameter that is used while registering the event<br/> | ||
| + | |||
| + | === Example === | ||
| + | <syntaxhighlight lang="lua"> | ||
| + | function Scene:init() | ||
| + | -- scene | ||
| + | -- audio | ||
| + | -- ... | ||
| + | -- event listeners: | ||
| + | self:addEventListener(Event.ENTER_FRAME, self.update, self) | ||
| + | -- ... | ||
| + | end | ||
| + | |||
| + | -- ... | ||
| + | |||
| + | function Scene:someStuff() | ||
| + | -- ... | ||
| + | self:removeEventListener(Event.ENTER_FRAME, self.update, self) | ||
| + | -- ... | ||
| + | end | ||
| + | </syntaxhighlight> | ||
{{EventDispatcher}} | {{EventDispatcher}} | ||
Latest revision as of 19:40, 4 December 2025
Available since: Gideros 2011.6
Class: EventDispatcher
Description
Removes a listener from the EventDispatcher object.
EventDispatcher:removeEventListener(type,listener,data)
removeEventListener() function expects the same arguments than the addEventListener() to remove the event.
If there is no matching listener registered, a call to this function has no effect.
Parameters
type: (string) the type of event
listener: (function) the listener object to remove
data: (any) the data parameter that is used while registering the event
Example
function Scene:init()
-- scene
-- audio
-- ...
-- event listeners:
self:addEventListener(Event.ENTER_FRAME, self.update, self)
-- ...
end
-- ...
function Scene:someStuff()
-- ...
self:removeEventListener(Event.ENTER_FRAME, self.update, self)
-- ...
end