Hi,
I'm trying to store a reference to a Touch event for later use.
pseudo code
local function pressTimer(self)
print (self.myEvent) -- ok
print (self.myEvent.x) -- ok
print (self.myEvent.y) -- ok
print (self.myEvent:getTarget()) -- #### NIL ####
print (self.myEvent:getType()) -- #### NIL ####
end
self.myEvent = e -- e is my Event
local myTimer:addEventListener(Event.TIMER, pressTimer, self) |
for now I'm using this workaround, but this is not clean and I still can not get the type :
local function pressTimer(self)
self.myEvent.__target = self.myEvent.target
self.myEvent.__type = self.myEvent.type
self.myEvent.params = nil
print (self.myEvent) -- ok
print (self.myEvent.x) -- ok
print (self.myEvent.y) -- ok
print (self.myEvent:getTarget()) -- #### NIL ####
print (self.myEvent:getType()) -- #### OK ####
end
self.myEvent = e -- e is my Event
self.myEvent.target = e:getTarget()
self.myEvent.type = e:getType())
local myTimer:addEventListener(Event.TIMER, pressTimer, self) |
is that expected, or not?
Comments
Most probably it speeds up the garbage collection (imagine mouse moving event where each event object does not get collected as soon as possible)
That said, you should then better keep references to the values you need yourself, rather than keeping weakly referenced object.
Like this:
The thing is that I use a events handler (for several events) later and there I use getType() and getTarget() which is why I was wondering :
I found that getTarget() accesses .__target, how is stored type for getType()?
It seems it's not .__type.