当MOUSE_OVER播放Movieclip的帧时

时间:2015-05-20 22:41:56

标签: actionscript-3 flash mouseevent mouseover

我有一张不同国家的地图。当我将鼠标悬停在其中一个国家/地区时,我希望它能够播放动画片段的特定帧。我为每个国家制作了一个动画片段,有2帧。 1.框架就像它出现在地图上的国家图片。第2帧是名称超过它的国家/地区。第二帧包含一个stop();这是我的代码:

rømskog.addEventListener(MouseEvent.MOUSE_OVER,mover);
halden.addEventListener(MouseEvent.MOUSE_OVER,mover);
askim.addEventListener(MouseEvent.MOUSE_OVER,mover);
rømskog.addEventListener(MouseEvent.MOUSE_OUT,outer);
halden.addEventListener(MouseEvent.MOUSE_OUT,outer);
askim.addEventListener(MouseEvent.MOUSE_OUT,outer);

function mover(e:MouseEvent):void {
   gotoAndPlay(2);
}

function outer(e:MouseEvent):void {
   gotoAndPlay(1);
}

我知道这段代码不正确,但我正在努力解决这个问题。我的movieclip也是自动启动的,因为这个国家的名字从一开始就是可见的。如果有人能以最简单的方式向我学习,我会非常高兴!

1 个答案:

答案 0 :(得分:0)

您当前的代码将在主时间轴上执行gotoAndPlay。你需要让国家电影剪辑时间线转到相应的框架。

你需要做的就是修改你的两个功能:

function mover(e:MouseEvent):void {
   //e.currentTarget is a reference to the object that was clicked.  To avoid a compiler warning, we tell flash it's a movie clip.
   MovieClip(e.currentTarget).gotoAndStop(2); //if you don't want to actually play the timeline, use gotoAndStop
}

function outer(e:MouseEvent):void {
   //since this code is in the main timeline, doing gotoAndPlay will apply to it, not the object clicked

   //so like above, we tell the current target of the event to gotoAndPlay
   MovieClip(e.currentTarget).gotoAndStop(1);
}