Display List Question
- May 4, 2009
- 1 reply
- 997 views
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 remove the child, 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.
Any help would be really appreciated!
Thanks!
David
code for ellipses:
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);
}
function 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:
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);
