Reputation: 455
I've a container called mc, inside of him I generate a grid of movieclips in order to make a wall of options. When I select one of this option, this message appears:
Error #2025: The supplied DisplayObject must be a child of the caller..
The code is:
In the Class iniciarApp I've this: var mc:MovieClip = new MovieClip(); var grilla:Grilla = new Grilla(); mc.x = 0; mc.y = 0; mc.name = "square"; addChild(mc); grilla.name = "grilla"; grilla.x = mc.x; grilla.y = mc.y; mc.addChild(grilla); ---------- in Grilla.as: public class Grilla extends MovieClip { private var boxNum:int = 48; private var cols:int = 6; private var rows:int = Math.ceil(boxNum / cols); private var boxCount:int = 0; public function Grilla(){ for (var py:int = 0; py < rows; py++) { for (var px:int = 0; px < cols; px++) { var caja:clip = new clip(); caja.x = -115 + caja.width * px; caja.y = -150 + caja.height * py; caja.name = "opcion" + (py + 1); caja.mouseChildren = false; var contentText = new TextField(); var formato = new TextFormat(); formato.size = 14; contentText.defaultTextFormat = formato; contentText.width = 36; contentText.height = 34; contentText.x = -10; contentText.y = -10; for (var u:uint = 0; u < boxNum; u++) { contentText.text = "" + u; } addChild(caja); caja.addChild(contentText); if (boxCount < boxNum) { caja.buttonMode = true; caja.addEventListener(MouseEvent.CLICK, seleccionarOpcion); } boxCount++; } } var barra:score = new score(); barra.x = 80; barra.y = -200; barra.puntajeTXT.text = "hola"; addChild(barra); } private function seleccionarOpcion(m:MouseEvent):void { TweenMax.to(MovieClip(m.target), 0.5, {scaleY: -1}); m.target.removeEventListener(MouseEvent.CLICK, seleccionarOpcion); m.target.buttonMode = false; var opcionABuscar:String; opcionABuscar = m.currentTarget.name; var opt:String = opcionABuscar.substring(6); **[HERE] i need to remove the instance of grilla created in the other class** **m.currentTarget.parent.parent.removeChild(grilla);** << this is not working var trivia:generarTrivia = new generarTrivia(opt); trivia.x = 0; trivia.y = 0; trivia.name = "trivia"; addChild(trivia); } }
Upvotes: 0
Views: 685
Reputation: 793
It's not clear from the code above what the object "grilla" actually is referring to.
If you are trying to remove grilla, you could just write:
grilla.parent.removeChild(grilla);
I'm not sure if that's what you're trying to do. If you're trying to remove the object you just clicked, try:
m.currentTarget.parent.removeChild(m.currentTarget);
Update: Ok, I see what you are trying to do now.
You'll want to use the keyword "this" to refer to the current instance of "grilla".
Try this:
this.parent.removeChild(this);
Upvotes: 0
Reputation: 111
Try parent.removeChild(this);
Although it's not the most clean way to do it. You'd be better off dispatching an event that iniciarApp will listen to.
Upvotes: 0