Display List Question

Hey all,

How does one remove a child from the display list, but then put it back, i.e. reset? I’ve found that once the reference is gone and set for garbage collection trying to re-add the child results in a null reference error. For example if I have a bunch of circle instances drawn by the user on the stage, if I add a reset button and removeChild, all well and good, but it can’t come back?!

in attached file, the shapes are being made by ellipses.fla, whose .swf is loaded by FreeDraw.fla. When I hit reset I essentially want to “reload” ellipses.swf. and start over.

Once reset is called, the loader object, “ellipses.swf” is gone from the display list, so drawing is inoperative and calling reset again results in an error.

Any help would be really appreciated!

Thanks!
David

//code for ellipses: This makes the actual shapes.

var circle:Sprite = new Sprite();
var color:Number = Math.random() * 0XFFFFFF;

stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);

function startDrawing(e:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_MOVE, makeShapes);
}
functi
on stopDrawing(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, makeShapes);
}

function makeShapes(e:MouseEvent):void
{
var circle:Sprite = new Sprite();
circle.graphics.beginFill(color);
circle.graphics.drawCircle(20,20,10);
addChild(circle);
circle.x = mouseX;
circle.y = mouseY;
color = Math.random() * 0xFFFFFF;
}

code for FreeDraw: This puts it on the stage and adds reset.

var myLoader:Loader = new Loader();
var myURL:URLRequest = new URLRequest(“ellipses.swf”);
myLoader.load(myURL);
addChild(myLoader);

//reset button on stage.

function reset(event:MouseEvent):void
{
removeChild(myLoader);
}
reset_btn.addEventListener(MouseEvent.CLICK, reset);