Difference between revisions of "Event:getTarget"

From GiderosMobile
(added example)
Line 4: Line 4:
 
=== Description ===
 
=== Description ===
 
Returns the element on which the event listener was registered.
 
Returns the element on which the event listener was registered.
 
 
<source lang="lua">
 
<source lang="lua">
 
(object) = Event:getTarget()
 
(object) = Event:getTarget()
Line 11: Line 10:
 
=== Return values ===
 
=== Return values ===
 
'''Returns''' (object) Target of event.<br/>
 
'''Returns''' (object) Target of event.<br/>
 +
 +
=== Example ===
 +
<source lang="lua">
 +
function ExplosionLayer:addExplosion(x, y)
 +
local explosion
 +
...
 +
explosion = MovieClip.new(timeline)
 +
explosion:addEventListener(Event.COMPLETE, self.onExplosionComplete, self)
 +
...
 +
end
 +
 +
function ExplosionLayer:onExplosionComplete(event)
 +
local explosion = event:getTarget()
 +
explosion:removeFromParent()
 +
self.pool[#self.pool + 1] = explosion
 +
end
 +
</source>
  
 
{{Event}}
 
{{Event}}

Revision as of 07:13, 21 November 2021

Available since: Gideros 2011.6
Class: Event

Description

Returns the element on which the event listener was registered.

(object) = Event:getTarget()

Return values

Returns (object) Target of event.

Example

function ExplosionLayer:addExplosion(x, y)
	local explosion
	...
	explosion = MovieClip.new(timeline)
	explosion:addEventListener(Event.COMPLETE, self.onExplosionComplete, self)
	...
end

function ExplosionLayer:onExplosionComplete(event)
	local explosion = event:getTarget()
	explosion:removeFromParent()
	self.pool[#self.pool + 1] = explosion
end