事件侦听器功能不会停止工作

eventlistener functions doesnot stop workning

我制作了一个内容,其中在一帧中我有 10 个电影片段(5 对颜色)平均分为两个 columns.I 在舞台上添加了三个事件侦听器 mousedown、mouseup、mouse move。我已经从一个影片剪辑到另一个影片剪辑绘制线条,以将一列影片剪辑与另一列相同的影片剪辑相匹配。我将代码添加到时间轴但是当我使用 [=18= 转到下一帧或上一帧(那里有另一个活动)时] 按钮显示警告:

Cannot access a property or method of a null object reference. at CL3_Sc_Pat12_SL05_fla::MainTimeline/mMove()
this waring is not showing for mousedown() mouseup().i have used same next and same previous button for 3 frames.and for frame jumping i numbered each frame as frame no 1,2,3.if frameno == 3 goto frame 2 if frameno== 2 goto frame 1 thus it works..frame jumping code is in 1st frame..

这是我的代码:

stage.addEventListener(MouseEvent.MOUSE_DOWN, mDown);    
stage.addEventListener(MouseEvent.MOUSE_UP, mUp);    
stage.addEventListener(MouseEvent.MOUSE_MOVE, mMove);

function mDown(event:MouseEvent):void
{
    mouseHolding = true;    
    clickedX = mouseX;    
    clickedY = mouseY;     
    myDrawing.graphics.moveTo(mouseX, mouseY);
    Line_draw.graphics.moveTo(mouseX, mouseY);

    if (pencil.hitTestObject(box1))   //box of 1st column
    {                   
        trace("box1 value is: "+chk_val_1);
    }
}

function mUp(MouseEvent):void
{
    myDrawing.graphics.lineTo(mouseX, mouseY);
    mouseHolding = false;   

    if (pencil.hitTestObject(hit_box1)) ////box of 2nd column
    {
        trace(boxes have same color);
        Line_draw.graphics.lineTo(mouseX, mouseY);
    } 
}

function mMove(MouseEvent):void
{   
    if (mouseHolding && mouseY < 510 )    
    {    
        clearTemp();    
        Line_draw.graphics.lineTo(mouseX, mouseY);    
    }
}

function clearTemp():void
{
    Line_draw.graphics.clear();
    Line_draw.graphics.lineStyle(6,0x0066CC,1);
    Line_draw.graphics.moveTo(clickedX, clickedY);
}

function nxt_click(event:MouseEvent)
{
    gotoAndPlay(3);     
}
function prev_click(event:MouseEvent)
{
    gotoAndPlay(1);     
}

我的代码运行完美,但我想知道为什么这个警告一次又一次出现?

您需要在 "anim4" 框架中绘制箭头(线),因此在此框架之外您必须禁用此功能并删除为此创建的所有舞台侦听器,因此您可以这样做:

function nxt_click(event:MouseEvent)
{   
    if(){
        // your other instructions
    }
    // your other instructions

    else if (my_frame == 4)
    {
        stage.removeEventListener(MouseEvent.MOUSE_DOWN, mDown);
        stage.removeEventListener(MouseEvent.MOUSE_UP, mUp);
        stage.removeEventListener(MouseEvent.MOUSE_MOVE, mMove); 
        gotoAndPlay("anim5");       
    }
}

在按下上一个按钮退出 "anim4" 帧时,您应该做同样的事情。

希望能帮到你。