Flash CS5.5中的错误#2007

时间:2013-12-16 05:53:51

标签: actionscript-3 flash puzzle

我目前正在学习使用Flash CS5.5和AS3.0创建益智游戏。我在不同的场景中创造了这个谜题。但是,当我测试电影(Ctrl + Enter)时,它会说;

TypeError: Error #2007: Parameter hitTestObject must be non-null.
    at flash.display::DisplayObject/_hitTest()
    at flash.display::DisplayObject/hitTestObject()
    at RECOVER_MAIN__fla::MainTimeline/Ent2Frame()

这意味着什么?我该如何解决这个错误? AS3.0我的谜题如下图所示。谢谢。

拼图1(6件):

import flash.events.MouseEvent;

stage.addEventListener(Event.ADDED_TO_STAGE,Ent1Frame);

function Ent1Frame(e:Event):void
{
    //piece1
    PQ1piece1_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP1)
    function DragP1(event:MouseEvent):void
    {
        PQ1piece1_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP1)
    function DropP1(event:MouseEvent):void
    {
        PQ1piece1_mc.stopDrag();
    }

    if(Targ1_mc.hitTestObject(PQ1piece1_mc.Tar1_mc))
    {
        PQ1piece1_mc.x = 149.65;
        PQ1piece1_mc.y = 150.30;
    }

    //piece2
    PQ1piece2_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP2)
    function DragP2(event:MouseEvent):void
    {
        PQ1piece2_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP2)
    function DropP2(event:MouseEvent):void
    {
        PQ1piece2_mc.stopDrag();
    }

    if(Targ2_mc.hitTestObject(PQ1piece2_mc.Tar2_mc))
    {
        PQ1piece2_mc.x = 283.15;
        PQ1piece2_mc.y = 150.30;
    }

    //piece3_mc
    PQ1piece3_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP3)
    function DragP3(event:MouseEvent):void
    {
        PQ1piece3_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP3)
    function DropP3(event:MouseEvent):void
    {
        PQ1piece3_mc.stopDrag();
    }

    if(Targ3_mc.hitTestObject(PQ1piece3_mc.Tar3_mc))
    {
        PQ1piece3_mc.x = 416.65;
        PQ1piece3_mc.y = 150.30;
    }

    //PQ1piece4_mc
    PQ1piece4_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP4)
    function DragP4(event:MouseEvent):void
    {
        PQ1piece4_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP4)
    function DropP4(event:MouseEvent):void
    {
        PQ1piece4_mc.stopDrag();
    }

    if(Targ4_mc.hitTestObject(PQ1piece4_mc.Tar4_mc))
    {
        PQ1piece4_mc.x = 149.65;
        PQ1piece4_mc.y = 350.30;
    }

    //PQ1piece5_mc
    PQ1piece5_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP5)
    function DragP5(event:MouseEvent):void
    {
        PQ1piece5_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP5)
    function DropP5(event:MouseEvent):void
    {
        PQ1piece5_mc.stopDrag();
    }

    if(Targ5_mc.hitTestObject(PQ1piece5_mc.Tar5_mc))
    {
        PQ1piece5_mc.x = 283.15;
        PQ1piece5_mc.y = 350.30;
    }

    //PQ1piece6_mc
    PQ1piece6_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP6)
    function DragP6(event:MouseEvent):void
    {
        PQ1piece6_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP6)
    function DropP6(event:MouseEvent):void
    {
        PQ1piece6_mc.stopDrag();
    }

    if(Targ6_mc.hitTestObject(PQ1piece6_mc.Tar6_mc))
    {
        PQ1piece6_mc.x = 415.35;
        PQ1piece6_mc.y = 348.80;
    }
}

拼图2(16件):

import flash.events.MouseEvent;

stage.addEventListener(Event.ENTER_FRAME,Ent2Frame);

function Ent2Frame(e:Event):void
{
    //piece1
    PQ2piece1_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP7)
    function DragP7(event:MouseEvent):void
    {
        PQ2piece1_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP7)
    function DropP7(event:MouseEvent):void
    {
        PQ2piece1_mc.stopDrag();
    }

    if(Targ7_mc.hitTestObject(PQ2piece1_mc.Tar7_mc))
    {
        PQ2piece1_mc.x = 132.20;
        PQ2piece1_mc.y = 99.05;
    }

    //piece2
    PQ2piece2_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP8)
    function DragP8(event:MouseEvent):void
    {
        PQ2piece2_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP8)
    function DropP8(event:MouseEvent):void
    {
        PQ2piece2_mc.stopDrag();
    }

    if(Targ8_mc.hitTestObject(PQ2piece2_mc.Tar8_mc))
    {
        PQ2piece2_mc.x = 232.20;
        PQ2piece2_mc.y = 99.05;
    }

    //piece3_mc
    PQ2piece3_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP9)
    function DragP9(event:MouseEvent):void
    {
        PQ2piece3_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP9)
    function DropP9(event:MouseEvent):void
    {
        PQ2piece3_mc.stopDrag();
    }

    if(Targ9_mc.hitTestObject(PQ2piece3_mc.Tar9_mc))
    {
        PQ2piece3_mc.x = 332.20;
        PQ2piece3_mc.y = 99.05;
    }

    //PQ1piece4_mc
    PQ2piece4_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP10)
    function DragP10(event:MouseEvent):void
    {
        PQ2piece4_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP10)
    function DropP10(event:MouseEvent):void
    {
        PQ2piece4_mc.stopDrag();
    }

    if(Targ10_mc.hitTestObject(PQ2piece4_mc.Tar10_mc))
    {
        PQ2piece4_mc.x = 432.30;
        PQ2piece4_mc.y = 99.05;
    }

    //piece5_mc
    PQ2piece5_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP11)
    function DragP11(event:MouseEvent):void
    {
        PQ2piece5_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP11)
    function DropP11(event:MouseEvent):void
    {
        PQ2piece5_mc.stopDrag();
    }

    if(Targ11_mc.hitTestObject(PQ2piece5_mc.Tar11_mc))
    {
        PQ2piece5_mc.x = 132.20;
        PQ2piece5_mc.y = 199.05;
    }

    //PQ1piece6_mc
    PQ2piece6_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP12)
    function DragP12(event:MouseEvent):void
    {
        PQ2piece6_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP12)
    function DropP12(event:MouseEvent):void
    {
        PQ2piece6_mc.stopDrag();
    }

    if(Targ12_mc.hitTestObject(PQ2piece6_mc.Tar12_mc))
    {
        PQ2piece6_mc.x = 232.20;
        PQ2piece6_mc.y = 199.05;
    }

    //piece7_mc
    PQ2piece7_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP13)
    function DragP13(event:MouseEvent):void
    {
        PQ2piece7_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP13)
    function DropP13(event:MouseEvent):void
    {
        PQ2piece7_mc.stopDrag();
    }

    if(Targ13_mc.hitTestObject(PQ2piece7_mc.Tar13_mc))
    {
        PQ2piece7_mc.x = 332.20;
        PQ2piece7_mc.y = 199.05;
    }

    //piece8_mc
    PQ2piece8_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP14)
    function DragP14(event:MouseEvent):void
    {
        PQ2piece8_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP14)
    function DropP14(event:MouseEvent):void
    {
        PQ2piece8_mc.stopDrag();
    }

    if(Targ14_mc.hitTestObject(PQ2piece8_mc.Tar14_mc))
    {
        PQ2piece8_mc.x = 432.20;
        PQ2piece8_mc.y = 199.05;
    }

    //piece9_mc
    PQ2piece9_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP15)
    function DragP15(event:MouseEvent):void
    {
        PQ2piece9_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP15)
    function DropP15(event:MouseEvent):void
    {
        PQ2piece9_mc.stopDrag();
    }

    if(Targ15_mc.hitTestObject(PQ2piece9_mc.Tar15_mc))
    {
        PQ2piece9_mc.x = 132.20;
        PQ2piece9_mc.y = 299.05;
    }

    //piece10_mc
    PQ2piece10_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP16)
    function DragP16(event:MouseEvent):void
    {
        PQ2piece10_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP16)
    function DropP16(event:MouseEvent):void
    {
        PQ2piece10_mc.stopDrag();
    }

    if(Targ16_mc.hitTestObject(PQ2piece10_mc.Tar16_mc))
    {
        PQ2piece10_mc.x = 232.20;
        PQ2piece10_mc.y = 299.05;
    }

    //piece11_mc
    PQ2piece11_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP17)
    function DragP17(event:MouseEvent):void
    {
        PQ2piece11_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP17)
    function DropP17(event:MouseEvent):void
    {
        PQ2piece11_mc.stopDrag();
    }

    if(Targ17_mc.hitTestObject(PQ2piece11_mc.Tar17_mc))
    {
        PQ2piece11_mc.x = 332.20;
        PQ2piece11_mc.y = 299.05;
    }

    //piece12_mc
    PQ2piece12_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP18)
    function DragP18(event:MouseEvent):void
    {
        PQ2piece12_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP18)
    function DropP18(event:MouseEvent):void
    {
        PQ2piece12_mc.stopDrag();
    }

    if(Targ18_mc.hitTestObject(PQ2piece12_mc.Tar18_mc))
    {
        PQ2piece12_mc.x = 432.20;
        PQ2piece12_mc.y = 299.05;
    }

    //piece13_mc
    PQ2piece13_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP19)
    function DragP19(event:MouseEvent):void
    {
        PQ2piece13_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP19)
    function DropP19(event:MouseEvent):void
    {
        PQ2piece13_mc.stopDrag();
    }

    if(Targ19_mc.hitTestObject(PQ2piece13_mc.Tar19_mc))
    {
        PQ2piece13_mc.x = 132.20;
        PQ2piece13_mc.y = 398.40;
    }

    //piece14_mc
    PQ2piece14_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP20)
    function DragP20(event:MouseEvent):void
    {
        PQ2piece14_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP20)
    function DropP20(event:MouseEvent):void
    {
        PQ2piece14_mc.stopDrag();
    }

    if(Targ20_mc.hitTestObject(PQ2piece14_mc.Tar20_mc))
    {
        PQ2piece14_mc.x = 232.20;
        PQ2piece14_mc.y = 398.40;
    }

    //piece15_mc
    PQ2piece15_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP21)
    function DragP21(event:MouseEvent):void
    {
        PQ2piece15_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP21)
    function DropP21(event:MouseEvent):void
    {
        PQ2piece15_mc.stopDrag();
    }

    if(Targ21_mc.hitTestObject(PQ2piece15_mc.Tar21_mc))
    {
        PQ2piece15_mc.x = 332.20;
        PQ2piece15_mc.y = 398.40;
    }

    //piece16_mc
    PQ2piece16_mc.addEventListener(MouseEvent.MOUSE_DOWN,DragP22)
    function DragP22(event:MouseEvent):void
    {
        PQ2piece16_mc.startDrag();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP,DropP22)
    function DropP22(event:MouseEvent):void
    {
        PQ2piece16_mc.stopDrag();
    }

    if(Targ22_mc.hitTestObject(PQ2piece16_mc.Tar22_mc))
    {
        PQ2piece16_mc.x = 432.20;
        PQ2piece16_mc.y = 398.40;
    }
}

1 个答案:

答案 0 :(得分:2)

如果你谷歌关于错误2007,你可以看到当你尝试访问父容器中不存在的chil时,displayobject容器会抛出此错误。

使用调试影片(ctrl + shift + enter)代替测试影片(ctrl + enter),这样就可以看到出现问题的行以及有关问题的更多信息。

当你有你的行时,只需检查你尝试传入的孩子的hitTestObject参数是否存在,这可能只是输入错误。