Skip to main content
May 1, 2010
Question

problem removing nested sprites

  • May 1, 2010
  • 1 reply
  • 414 views

I'm having two problems. First off I'm trying to remove container0 on roll out, but I can't remove it from the outView function because it doesn't recognize it.

Second these functions load another image on top of the thumb0 and it disappears right away. I don't know why and I'm trying to stop it from loading 2 instances

var container0:Sprite;

var loader0:Loader;

var boolean0:Boolean = false;

thumb0_mc.addEventListener(MouseEvent.ROLL_OVER,preview0,false,0,true);

thumb0_mc.addEventListener(MouseEvent.ROLL_OUT,outView0,false,0,true);
function preview0(e:MouseEvent):void {
     loader0 = new Loader();
     loader0.load(new URLRequest("Images/Previews/Australia.jpg"));
     loader0.contentLoaderInfo.addEventListener(Event.COMPLETE,show0,false,0,true);
}
function show0(e:Event):void {
     container0 = new Sprite();
     stage.addChild(container0);
     var newLoader:Loader = Loader(e.target.loader);
     container0.addChild(newLoader);
     container0.width = 187;
     container0.height = 200;
     container0.addEventListener(Event.ENTER_FRAME,displayPreview,false,0,true);
     if (boolean0 == true) {
          stage.removeChild(container0);
     }
}
function displayPreview(e:Event):void {
     e.target.x = thumb0_mc.x + 150;
     e.target.y = thumb0_mc.y - 50;
}
function outView0(e:MouseEvent):void {
     boolean0 = true;
}

This topic has been closed for replies.

1 reply

Cancerinform
Inspiring
May 1, 2010

Several points:

1. Why do you add container0 to the stage instead just to the timeline?

2. Have you tested if the boolean0 is true?

3. You don't need to always write all the parameters in an addeventlistener function, only the event and the listener function, since the other parameters are already given unless you want to change them.

May 1, 2010

>>3. You don't need to always write all the parameters in an addeventlistener function, only the event and the listener function, since the other parameters are already given unless you want to change them.

FYI, but it is best practice to always use all parameters since you want the last parameter - weak reference - to be true, which defaults to false.