提供的 DisplayObject 必须是调用者的子对象
我有一个名为 mc 的容器,在他内部我生成了一个电影剪辑网格,以便制作一堵选项墙。当我选择此选项之一时,会出现以下消息:
错误#2025:提供的 DisplayObject 必须是 来电者..
代码是:
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); } }
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); } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试parent.removeChild(this);
尽管这不是最干净的方法。您最好调度 iniciarApp 将侦听的事件。
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.
从上面的代码中并不清楚对象“grilla”实际上指的是什么。
如果你想删除格栅,你可以写:
我不确定这是否是你想要做的。如果您尝试删除刚刚单击的对象,请尝试:
更新:好的,我明白您现在正在尝试执行的操作。
您需要使用关键字“this”来引用“grilla”的当前实例。
试试这个:
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:
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:
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: