Advertisement
lvs

Fix finalize event for groups

lvs
Jan 26th, 2014
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.88 KB | None | 0 0
  1. local function finalize(g)
  2.     for i = 1, g.numChildren do
  3.         if g[i]._tableListeners and g[i]._tableListeners.finalize then
  4.             for j = 1, #g[i]._tableListeners.finalize do
  5.                 g[i]._tableListeners.finalize[j]:dispatchEvent{name = 'finalize', target = g[i]}
  6.             end
  7.         end
  8.         if g[i]._functionListeners and g[i]._functionListeners.finalize then
  9.             for j = 1, #g[i]._functionListeners.finalize do
  10.                 g[i]._functionListeners.finalize[j]({name = 'finalize', target = g[i]})
  11.             end
  12.         end
  13.         if g[i].insert then
  14.             finalize(g[i])
  15.         end
  16.     end
  17. end
  18. local newGroup = display.newGroup
  19. function display.newGroup()
  20.     local g = newGroup()
  21.     local removeSelf = g.removeSelf
  22.     g.removeSelf = function()
  23.             finalize(g)
  24.             removeSelf(g)
  25.         end
  26.     return g
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement