I need help with something very interesting. I try to remove child from parent or fro stage dinamicly but not just removeChild and I want to destroy entire object. Here is very simple example what I want to do.
public function TestProject()
{
holder = new Sprite();
this.addChild(holder);
object1 = new Sprite();
object1.name = "object1";
object1.graphics.beginFill(0x6daeff);
object1.graphics.drawRect(0,0,100,100);
holder.addChild(object1);
stage.addEventListener(MouseEvent.CLICK,onClick);
}
protected function onClick(event:MouseEvent):void
{
var tmp:DisplayObject = holder.removeChild(object1);
tmp = null;
// holder.removeChild(object1) = null; this give me error.
}
//with this code object1 was removed from stage but object1 is not null. When I debug
object1 = flash.display.Sprite ; etc.
I want to remove child and at the same this child to be null. Any ideas...
To clean up memory you have to destroy all references to your object. In this case:
or
Note: When you'd applied
null
to local variabletmp
you didn't affect theobject1
instance variable.