Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
removeChild from stage — Gideros Forum

removeChild from stage

jack0088jack0088 Member
edited March 2012 in General questions
I have several Sprites inside
stage.__children["userdata ..."]
and they are nested in each other... like groups that are holding its children. Also there are Self.References added to
stage["name_xyz"]
that are pointing to each "group" and to each nested "child" inside such a group.

I want to have the ability to delete my groups and the children - remove them from memory and the stage object.
Can I do this somehow through the Self.References?
eg.
stage:removeChild( stage.RECT )
? When I try to do this this (and I tried a lot other things too) then I get error: The supplied Sprite must be a child of the caller.
stack traceback


Here is the content of stage object:
Value = {
|  userdata: 0x101d6d420 = {
|  |  __parent = {} -- Value (self reference)
|  |  Ebene_1 = {
|  |  |  __parent = {} -- Value.userdata: 0x101d6d420 (self reference)
|  |  |  __children = {
|  |  |  |  userdata: 0x101ddc960 = {
|  |  |  |  |  __parent = {} -- Value.userdata: 0x101d6d420.Ebene_1 (self reference)
|  |  |  |  |  Obj2 = {
|  |  |  |  |  |  __parent = {} -- Value.userdata: 0x101d6d420.Ebene_1.__children.userdata: 0x101ddc960 (self reference)
|  |  |  |  |  |  __children = {
|  |  |  |  |  |  |  userdata: 0x101d2e2c0 = {
|  |  |  |  |  |  |  |  __userdata = "userdata: 0x10625a928"
|  |  |  |  |  |  |  |  __parent = {} -- Value.userdata: 0x101d6d420.Ebene_1.__children.userdata: 0x101ddc960.Obj2 (self reference)
|  |  |  |  |  |  |  }
|  |  |  |  |  |  }
|  |  |  |  |  |  __userdata = "userdata: 0x10625a3c8"
|  |  |  |  |  }
|  |  |  |  |  __userdata = "userdata: 0x10622ed68"
|  |  |  |  |  Obj1 = {
|  |  |  |  |  |  __parent = {} -- Value.userdata: 0x101d6d420.Ebene_1.__children.userdata: 0x101ddc960 (self reference)
|  |  |  |  |  |  __children = {
|  |  |  |  |  |  |  userdata: 0x101d2b1c0 = {
|  |  |  |  |  |  |  |  __userdata = "userdata: 0x10622cb08"
|  |  |  |  |  |  |  |  __parent = {} -- Value.userdata: 0x101d6d420.Ebene_1.__children.userdata: 0x101ddc960.Obj1 (self reference)
|  |  |  |  |  |  |  }
|  |  |  |  |  |  }
|  |  |  |  |  |  __userdata = "userdata: 0x10623ca88"
|  |  |  |  |  }
|  |  |  |  |  __children = {
|  |  |  |  |  |  userdata: 0x101d23f50 = {} -- Value.userdata: 0x101d6d420.Ebene_1.__children.userdata: 0x101ddc960.Obj1 (self reference)
|  |  |  |  |  |  userdata: 0x101d2e1b0 = {} -- Value.userdata: 0x101d6d420.Ebene_1.__children.userdata: 0x101ddc960.Obj2 (self reference)
|  |  |  |  |  }
|  |  |  |  }
|  |  |  }
|  |  |  __userdata = "userdata: 0x10623e398"
|  |  |  RECT = {} -- Value.userdata: 0x101d6d420.Ebene_1.__children.userdata: 0x101ddc960 (self reference)
|  |  }
|  |  __userdata = "userdata: 0x10623e358"
|  |  __children = {
|  |  |  userdata: 0x101d2b470 = {} -- Value.userdata: 0x101d6d420.Ebene_1 (self reference)
|  |  }
|  }
|  Obj2 = {} -- Value.userdata: 0x101d6d420.Ebene_1.__children.userdata: 0x101ddc960.Obj2 (self reference)
|  __userdata = "userdata: 0x106225d28"
|  Obj1 = {} -- Value.userdata: 0x101d6d420.Ebene_1.__children.userdata: 0x101ddc960.Obj1 (self reference)
|  Ebene_1 = {} -- Value.userdata: 0x101d6d420.Ebene_1 (self reference)
|  RECT = {} -- Value.userdata: 0x101d6d420.Ebene_1.__children.userdata: 0x101ddc960 (self reference)
|  __children = {
|  |  userdata: 0x101d6d420 = {} -- Value.userdata: 0x101d6d420 (self reference)
|  }
}
the structure is actually like:
stage
     Ebene_1
          RECT
               Obj1
               Obj2
     Ebene_1 <- Self.Reference
     RECT      <- Self.Reference
     Obj1      <- Self.Reference
     Obj2      <- Self.Reference
But when adding Self.References the whole stage object looks weird... I use this function for adding:
function selfreferencing( t )
     for k,v in pairs( t ) do
          if string.find(tostring(k), "^[^\_]") then
                stage[k] = v
		selfreferencing( v )
	   end
     end
end
selfreferencing( stage.__children )
Owltwins. Smart design and creative code.
»Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!

Comments

  • atilimatilim Maintainer
    edited March 2012
    Hi,

    I don't understand exactly but if you want to remove RECT from its parent you should call:
    RECT:getParent():removeChild(RECT)
    or more easily:
    RECT:removeFromParent()
    In your case, the line:
    stage:removeChild(stage.RECT)
    doesn't work because RECT's parent is Ebene_1, it's not stage.

    Likes: GGGRRR123

    +1 -1 (+1 / -0 )Share on Facebook
  • jack0088jack0088 Member
    edited March 2012
    Not only from the parent. I want remove it completely from stage hierarchy.
    I want remove RECT from its parent, from stage and also everything that was inside RECT.
    Your suggestion removes the object from screen. I cannot longer see it. but it is still in the memory and in the stage hierarchy... How to remove everything at all?

    this is whats left inside stage hierarchy:
    Value = {
    |  Obj2 = {
    |  |  __parent = {
    |  |  |  Obj2 = {} -- Value.Obj2 (self reference)
    |  |  |  __userdata = "userdata: 0x10622edb8"
    |  |  |  Obj1 = {
    |  |  |  |  __parent = {} -- Value.Obj2.__parent (self reference)
    |  |  |  |  __children = {
    |  |  |  |  |  userdata: 0x104e73d60 = {
    |  |  |  |  |  |  __userdata = "userdata: 0x10623cf78"
    |  |  |  |  |  |  __parent = {} -- Value.Obj2.__parent.Obj1 (self reference)
    |  |  |  |  |  }
    |  |  |  |  }
    |  |  |  |  __userdata = "userdata: 0x10623cac8"
    |  |  |  }
    |  |  |  __children = {
    |  |  |  |  userdata: 0x104e715a0 = {} -- Value.Obj2.__parent.Obj1 (self reference)
    |  |  |  |  userdata: 0x104e78fa0 = {} -- Value.Obj2 (self reference)
    |  |  |  }
    |  |  }
    |  |  __children = {
    |  |  |  userdata: 0x104e81820 = {
    |  |  |  |  __userdata = "userdata: 0x10625a9c8"
    |  |  |  |  __parent = {} -- Value.Obj2 (self reference)
    |  |  |  }
    |  |  }
    |  |  __userdata = "userdata: 0x10625a468"
    |  }
    |  __userdata = "userdata: 0x106225d28"
    |  Obj1 = {} -- Value.Obj2.__parent.Obj1 (self reference)
    |  RECT = {} -- Value.Obj2.__parent (self reference)
    |  Ebene_1 = {
    |  |  __parent = {
    |  |  |  __parent = {} -- Value (self reference)
    |  |  |  Ebene_1 = {} -- Value.Ebene_1 (self reference)
    |  |  |  __userdata = "userdata: 0x10623e3a8"
    |  |  |  __children = {
    |  |  |  |  userdata: 0x104e84880 = {} -- Value.Ebene_1 (self reference)
    |  |  |  }
    |  |  }
    |  |  __children = {}
    |  |  __userdata = "userdata: 0x10623e3e8"
    |  |  RECT = {} -- Value.Obj2.__parent (self reference)
    |  }
    |  userdata: 0x104e76ad0 = {} -- Value.Ebene_1.__parent (self reference)
    |  __children = {
    |  |  userdata: 0x104e76ad0 = {} -- Value.Ebene_1.__parent (self reference)
    |  }
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
  • atilimatilim Maintainer
    edited March 2012
    In your case you should do
    stage.RECT:removeFromParent()
    stage.RECT = nil
    collectgarbage()
    If RECT's children cannot be reached from a global variable, RECT and all of its children will be deleted from memory.

    Edit: After you call stage.RECT:removeFromParent(), RECT is not at the stage hierarchy anymore.
  • I've also tries something similar to this:
    And hoped it would remove RECT and every Sprite nested inside it (Obj1, Obj2).
    function del( t, key )
    	for k,v in pairs( t ) do
    			if tostring(k) == key then
    				local p = v.__parent
     
    				t[k] = nil
     
    				del( p, key )
    			end
    	end
    end
    del(stage, "RECT")
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
  • still no success. it removes the self.refenrence but not all completely. see stage content:
    Value = {
    |  userdata: 0x101d6d420 = {
    |  |  __parent = {} -- Value (self reference)
    |  |  Ebene_1 = {
    |  |  |  __parent = {} -- Value.userdata: 0x101d6d420 (self reference)
    |  |  |  __children = {}
    |  |  |  __userdata = "userdata: 0x10623e3e8"
    |  |  |  RECT = {
    |  |  |  |  Obj2 = {
    |  |  |  |  |  __parent = {} -- Value.userdata: 0x101d6d420.Ebene_1.RECT (self reference)
    |  |  |  |  |  __children = {
    |  |  |  |  |  |  userdata: 0x101d23ef0 = {
    |  |  |  |  |  |  |  __userdata = "userdata: 0x10625a9c8"
    |  |  |  |  |  |  |  __parent = {} -- Value.userdata: 0x101d6d420.Ebene_1.RECT.Obj2 (self reference)
    |  |  |  |  |  |  }
    |  |  |  |  |  }
    |  |  |  |  |  __userdata = "userdata: 0x10625a468"
    |  |  |  |  }
    |  |  |  |  __userdata = "userdata: 0x10622edb8"
    |  |  |  |  Obj1 = {
    |  |  |  |  |  __parent = {} -- Value.userdata: 0x101d6d420.Ebene_1.RECT (self reference)
    |  |  |  |  |  __children = {
    |  |  |  |  |  |  userdata: 0x101d2a890 = {
    |  |  |  |  |  |  |  __userdata = "userdata: 0x10623cf78"
    |  |  |  |  |  |  |  __parent = {} -- Value.userdata: 0x101d6d420.Ebene_1.RECT.Obj1 (self reference)
    |  |  |  |  |  |  }
    |  |  |  |  |  }
    |  |  |  |  |  __userdata = "userdata: 0x10623cac8"
    |  |  |  |  }
    |  |  |  |  __children = {
    |  |  |  |  |  userdata: 0x101d81bd0 = {} -- Value.userdata: 0x101d6d420.Ebene_1.RECT.Obj1 (self reference)
    |  |  |  |  |  userdata: 0x101df3340 = {} -- Value.userdata: 0x101d6d420.Ebene_1.RECT.Obj2 (self reference)
    |  |  |  |  }
    |  |  |  }
    |  |  }
    |  |  __userdata = "userdata: 0x10623e3a8"
    |  |  __children = {
    |  |  |  userdata: 0x101d8c2a0 = {} -- Value.userdata: 0x101d6d420.Ebene_1 (self reference)
    |  |  }
    |  }
    |  Obj2 = {} -- Value.userdata: 0x101d6d420.Ebene_1.RECT.Obj2 (self reference)
    |  __userdata = "userdata: 0x106225d28"
    |  Obj1 = {} -- Value.userdata: 0x101d6d420.Ebene_1.RECT.Obj1 (self reference)
    |  Ebene_1 = {} -- Value.userdata: 0x101d6d420.Ebene_1 (self reference)
    |  __children = {
    |  |  userdata: 0x101d6d420 = {} -- Value.userdata: 0x101d6d420 (self reference)
    |  }
    }
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
  • can I send you the script, so you can check this quick? please atilim!
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
  • atilimatilim Maintainer
    edited March 2012
    and as a side note, the fields starting with "__" shouldn't be used or changed. they are internal to Gideros.
  • email..
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
Sign In or Register to comment.