提供的 DisplayObject 必须是调用者的子对象

发布于 2025-01-08 16:35:25 字数 2711 浏览 0 评论 0原文

我有一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苍风燃霜 2025-01-15 16:35:25

尝试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.

最美的太阳 2025-01-15 16:35:25

从上面的代码中并不清楚对象“grilla”实际上指的是什么。

如果你想删除格栅,你可以写:

grilla.parent.removeChild(grilla);

我不确定这是否是你想要做的。如果您尝试删除刚刚单击的对象,请尝试:

m.currentTarget.parent.removeChild(m.currentTarget);

更新:好的,我明白您现在正在尝试执行的操作。

您需要使用关键字“this”来引用“grilla”的当前实例。

试试这个:

this.parent.removeChild(this);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文