I have this function:
function clear(sprite)
for i = 1,sprite:getNumChildren() do
sprite:removeChildAt(i)
end
end |
And I'm getting this error on the removeChildAt line:
main.lua:72: The supplied index is out of bounds.
stack traceback: |
I didn't think that was possible. Are the child index values not always contiguous? If not, then how can I do this? I tried adding a guard but I get the same error:
function clear(sprite)
for i = 1,sprite:getNumChildren() do
if sprite:getChildAt(i) then
sprite:removeChildAt(i)
end
end
end |
Comments
Likes: lyrenbrown
http://howto.oz-apps.com/2011/09/tower-of-babel-no-honoi-maybe.html
This is another solution (most probably the slowest one )
(I was confused in Objective C, because when releasing a view, it would then release child views that were retained by it, so I didn't have to do recursive removal, but it's different in this case?)
Said another way ... if the children of the deleted child don't have any references to them, I believe they will be deleted by lua's garbage collector.
Likes: atilim