你能告诉我我的错吗?这是关于是否嵌套(flash cs6 as3)

Can you tell me my fault? it's about if nested (flash cs6 as3)

我已经检查过了,还是出错了?这是评论:

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller. at flash.display::DisplayObjectContainer/removeChild() at gamebalapanoret_fla::MainTimeline/batas()

我要制作if nested

when score amount of 2 then make var jwbn.and than jwbn remove when hittest batas_mc。虽然我低谷 removelistener 它不起作用。但是当我输入 removelistener 时出现错误。你能告诉我我的错在哪里吗? 这是我的代码:


//membuat object batu
var Batumc:batu_mc = new batu_mc(); // creates a instance of the movieclip, i.e, an object
var Batumc1:batu_mc = new batu_mc();

        addChild(Batumc);       
        addChild(Batumc1);


        Batumc.x = 350;
        Batumc.y = 50;

        Batumc1.x = 500;
        Batumc1.y = 50;

//batas batu
var BatasBatu = Batumc.width/12;


rumput1_mc.addEventListener(Event.ENTER_FRAME, rumput);
    function rumput(e:Event):void{
        //batas gerak pemain
        while (rumput1_mc.hitTestPoint(pemain.x+jarakKanan, pemain.y, true)) {
            pemain.x++;
        }
        while (rumput1_mc.hitTestPoint(pemain.x-jarakKiri, pemain.y, true)) {
            pemain.x--;
        }
        jwbn.y += kecepatanJawab;
    }


//var jwbn
var jwbn:jwb = new jwb();
var BatasJwb = jwbn.width/6;



batas_mc.addEventListener(Event.ENTER_FRAME, batas);
    function batas(e:Event):void{       
        if(batas_mc.hitTestPoint(Batumc.x, Batumc.y+BatasBatu, true)) {
            //menghitung banyak tumbukan
            score += 1;
            point.text = score.toString();

            if(score % 2 == 0){         


            //model soal
            Soal_mc.angka1.text = mtk1.toString();
            Soal_mc.op.text = "+";
            Soal_mc.angka2.text = mtk2.toString();

            //soal muncul
            TweenLite.to(Soal_mc, 1, {x:350 ,y:180, alpha:1, ease:Expo.easeOut});


            //jawaban muncul
            addChild(jwbn);
            jwbn.x = 350;
            jwbn.y = 50;


            }


            removeChild(Batumc);
            removeChild(Batumc1);

            addChild(Batumc);
            addChild(Batumc1);

            Batumc.x = 350;
            Batumc.y = 50;

            Batumc1.x = 500;
            Batumc1.y = 50;


        }

        if(batas_mc.hitTestPoint(jwbn.x, jwbn.y+BatasJwb, true)) {
                removeChild(jwbn);
            }

        if(pemain.hitTestObject(Batumc)){
            Batumc.y -= kecepatanRintangan;
            pemain.gotoAndPlay("jatuh");
            Batumc1.y -= kecepatanRintangan;

            removeChild(Batumc);
            removeChild(Batumc1);
            rumput1_mc.removeEventListener(Event.ENTER_FRAME, rumput);
            pemain.removeEventListener(Event.ENTER_FRAME, eframe);
            stage.removeEventListener(KeyboardEvent.KEY_UP, buttonUp);
            stage.removeEventListener(KeyboardEvent.KEY_DOWN, buttonpress);
            batas_mc.removeEventListener(Event.ENTER_FRAME, batas);
            bt_home.removeEventListener(MouseEvent.CLICK, backhome);
            Soal_mc.removeEventListener(Event.ENTER_FRAME, soal);
            gotoAndStop("kalah","lose");

        }
        else if(pemain.hitTestObject(Batumc1)){
            Batumc.y -= kecepatanRintangan;
            pemain.gotoAndPlay("jatuh");
            Batumc1.y -= kecepatanRintangan;

            removeChild(Batumc);
            removeChild(Batumc1);
            rumput1_mc.removeEventListener(Event.ENTER_FRAME, rumput);
            pemain.removeEventListener(Event.ENTER_FRAME, eframe);
            stage.removeEventListener(KeyboardEvent.KEY_UP, buttonUp);
            stage.removeEventListener(KeyboardEvent.KEY_DOWN, buttonpress);
            batas_mc.removeEventListener(Event.ENTER_FRAME, batas);
            bt_home.removeEventListener(MouseEvent.CLICK, backhome);
            Soal_mc.removeEventListener(Event.ENTER_FRAME, soal);
            gotoAndStop("kalah","lose");            
        }

    }


"The supplied DisplayObject must be a child of the caller."

查看您的代码:(缩短)...

batas_mc.addEventListener(Event.ENTER_FRAME, batas);

function batas(e:Event):void
{
    removeChild(Batumc);
}

所以 batas_mc 是你现在告诉 removeChild(Batumc);batas 函数的调用者,但问题是你从未说过 batas_mc.addChild(Batumc);batas_mc 无法删除它没有的东西( 例如: 不是 contained/added 在那个 MC 中)。

可能的解决方案:(未经测试)...

替换

batas_mc.addEventListener(Event.ENTER_FRAME, batas);

使用下面的代码(将事件侦听器添加到舞台本身而不是 batas_mc)。

addEventListener(Event.ENTER_FRAME, batas);
//stage.addEventListener(Event.ENTER_FRAME, batas); //# or try this