0

我有 5 层,每层都有符号:a、b、c、d 和 e。当您将鼠标悬停在 b 上时,我正在尝试研究如何将以下操作应用于 a、c、d 和 e。

还有其他类似于 'gotoAndStop(0); 的动作吗?' 不是立即转到第 0 帧,而是按原路返回?

链接到 .Fla http://www.fileden.com/files/2012/11/27/3370853/Untitled-2.fla

stop();

stage.addEventListener(MouseEvent.MOUSE_OVER, playMovie); function playMovie(event) { play(); }
stage.addEventListener(MouseEvent.MOUSE_OUT, stopMovie); function stopMovie(event) { gotoAndStop(0); }


stop();

谢谢

4

1 回答 1

1

编辑

查看您的 .fla 后,以下是缺少/放错位置的内容:

  1. Flash 中的层除了 z 顺序/深度之外没有任何意义。您不能在代码中操作图层。您的所有动画都在同一时间线上,因此它们将始终一起播放。如果您希望单个项目在没有其他项目的情况下进行动画处理,则必须在其自己的时间轴上制作动画(不仅仅是它唯一的图层)。您可以通过双击访问您自己的符号时间线 - 在那里制作您的动画。

  2. 要引用舞台上的项目,您需要给它们一个实例名称。您可以通过单击舞台上的项目来执行此操作,然后在属性面板中,您可以在其中输入实例名称的字段。为了使下面的代码正常工作,您需要分别给它们一个实例名称“a”、“b”、“c”、“d”、“e”。这与库中的符号名称不同(尽管它可以是相同的名称)。


你可以这样做的一种方法:

var btns:Vector.<MovieClip> = new Vector.<MovieClip>(); //create an array of all your buttons
btns.push(a,b,c,d,e); //add your buttons to the array

for each(var btn:MovieClip in btns){
    btn.addEventListener(MouseEvent.MOUSE_OVER, btnMouseOver);  // listen for mouse over on each of the buttons
    btn.addEventListener(MouseEvent.MOUSE_OUT, btnMouseOut);
}

function btnMouseOver(e:Event):void {
    for each(var btn:MovieClip in btns){ //loop through all your buttons
        if(btn != e.currentTarget){ //if the current one in the loop isn't the one that was clicked
            btn.play();

            try{
                btn.removeEventListener(Event.ENTER_FRAME,moveBackwards); //this will stop the backwards animation if running.  it's in a try block because it will error if not running
            }catch(err:Error){};
        }
    }
}

function btnMouseOut(e:Event):void {
    for each(var btn:MovieClip in btns){ //loop through all your buttons
        if(btn != e.currentTarget){ //if the current one in the loop isn't the one that was clicked
            goBackwards(btn);
        }
    }
}

没有很好的方法可以向后播放时间线,但是有办法做到这一点。一种这样的方式:

//a function you can call and pass in the item/timeline you want played backwards
function goBackwards(item:MovieClip):void {
    item.stop(); //make sure the item isn't playing before starting frame handler below
    item.addEventListener(Event.ENTER_FRAME, moveBackwards); //add a frame handler that will run the moveBackwards function once every frame
}

//this function will move something one frame back everytime it's called
function moveBackwards(e:Event):void {
    var m:MovieClip = e.currentTarget as MovieClip; //get the movie clip that fired the event
    if(m.currentFrame > 1){ //check to see if it's already back to the start
        m.prevFrame();  //if not move it one frame back
    }else{
        m.removeEventListener(Event.ENTER_FRAME,moveBackwards); //if it is (at the start), remove the enter frame listener so this function doesn't run anymore
    }
}
于 2012-11-27T21:06:53.403 回答