Since groups are just a fancy name for a table, you can try this (let me know if it works for you as I’ve never personally done this in a real-life scenario):
[blockcode]
local parentGroup = z.parent
for i=1,parentGroup.numChildren,1 do
if parentGroup[i] == z then
table.remove( parentGroup, i )
end
end
groupLayer02:insert( z )
[/blockcode]
The first block of code will iterate through all children of z’s parent group, and once it finds z, it’ll remove it from the table (parent).
The last line of code insert’s z into the new group you want it to be in.
The reason why your code wouldn’t work is because the remove() function (not table.remove(), but object:remove()) will actually destroy a display object, not just remove it’s index from it’s position in a group.
Your line:
[blockcode]
z.parent:remove(z)
[/blockcode]
…was actually destroying the z object, which is why you were getting the error (proxy expected, got nil). Basically, it was expecting an object when you called insert() and got nothing. [import]uid: 52430 topic_id: 8970 reply_id: 32751[/import]