-1

使用 MovieClip (root) 制作滑动按钮功能时遇到问题。

addEventListener (Event.ENTER_FRAME, onenterFrameHandler);

当给定一个命令按钮时..addEventListener (MouseEvent.CLICK, fl_ClickToGoToScene_20);当我单击按钮时,我得到输出

TypeError:错误#1009:无法访问空对象引用的属性或方法。在 index_fla::MainTimeline/onenterFrameHandler()

这是我的代码:

var myVar:Boolean;
MovieClip(root).addEventListener(Event.ENTER_FRAME,onenterFrameHandler);
MovieClip(root).addEventListener(MouseEvent.CLICK, mouseClickHandler);

function onenterFrameHandler(event:Event):void
{
if (MovieClip(root).mouseY < 500)
    {
      myVar=false;
    }
if (MovieClip(root).mouseY > 500)
    {
       myVar=true;
    }

if (MovieClip(root).mouseX > 1266 && myVar==true)
{
imgbar.nextFrame();
} else {
    imgbar.play();
}
if (MovieClip(root).mouseX < 100 && myVar==true)
{
imgbar.prevFrame();
} else {
    imgbar.play();
}
    if (MovieClip(root).mouseX > 100 && mouseX < 1266 && myVar==true)
    {
        imgbar.stop();
    }
}

在按钮层中,我填写代码来命令我的按钮/电影剪辑;

    btn1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene);

function fl_ClickToGoToScene(event:MouseEvent):void
{
    MovieClip(this.root).gotoAndPlay(80, "Scene 2");
}

请帮我

4

2 回答 2

0

在场景“场景 2”中,您的部分或全部影片剪辑不再出现在舞台上。因此, ENTER_FRAME 处理程序无法再找到imgbar,这会导致错误。要摆脱它,请imgbar像上一个场景一样包含剪辑(具有相同的舞台名称!),或者如果imgbar不再存在,则删除 ENTER_FRAME 侦听器:

function onenterFrameHandler(event:Event):void
{
    if (!imgbar) root.removeEventListener(Event.ENTER_FRAME,onenterFrameHandler);
     // the rest stays the same
}
于 2012-05-26T12:50:26.610 回答
0

function onenterFrameHandler(event:Event):void
{
    if (!imgbar) root.removeEventListener(Event.ENTER_FRAME,onenterFrameHandler);
     // the rest stays the same
}

是的,我发现它几乎没有修改,感谢您的建议,weltraumpirat,这是最终代码:

    var myVar:Boolean=false;
    MovieClip(root).addEventListener(Event.ENTER_FRAME,onenterFrameHandler);
    MovieClip(root).addEventListener(MouseEvent.CLICK,fl_ClickToGoToAndStopAtFrame_28);


function onenterFrameHandler(event:Event):void
{
if (MovieClip(root).mouseY < 500)
    {
      myVar=false;
    }
if (MovieClip(root).mouseY > 500)
    {
       myVar=true;
    }

if (MovieClip(root).mouseX > 1266 && myVar==true)
{
imgbar.nextFrame();
} else {
    imgbar.play();
}
if (MovieClip(root).mouseX < 100 && myVar==true)
{
imgbar.prevFrame();
} else {
    imgbar.play();
}
    if (MovieClip(root).mouseX > 100 && mouseX < 1266 && myVar==true)
    {
        imgbar.stop();
    }
    if (!imgbar)root.removeEventListener(Event.ENTER_FRAME,onenterFrameHandler);
}

function fl_ClickToGoToAndStopAtFrame_28(event:MouseEvent):void
{
    MovieClip(root).removeEventListener(Event.ENTER_FRAME, onenterFrameHandler);

}
于 2012-05-27T18:32:57.360 回答