1

嗨,我是 Flash 的新手,需要一些代码。我有 3 个 MC 说MC1MC2MC3。我将有 3 个专用按钮,它们将暂停一个 MC 的音乐并将帧位置转移到另一个 MC 并开始播放。例如,如果MC2正在播放并且我按下MC3按钮,我希望它处于MC2(not MC1) 的暂停位置并继续从该帧开始播放,MC3并将视觉效果从 切换MC2MC3。这是一个多语言应用程序,所有 3 个 MC 的帧长度相同。换句话说,我想在语言之间切换。在此先感谢,任何帮助都会很棒。

编辑:到目前为止我有

mtlyrvult.stop();
itlyrvult.stop();

engvult.addEventListener(MouseEvent.CLICK, playMC1); 

function playMC1(e:MouseEvent):void {
    itlyrvult.stop();
    enlyrvult.gotoAndPlay(itlyrvult.currentFrame);
    itlyrvult.gotoAndStop(1);  //frame one is empty
    engvult.mouseEnabled = false;
    itvult.mouseEnabled = true;
}

itvult.addEventListener(MouseEvent.CLICK, playMC2); 

function playMC2(e:MouseEvent):void {
    enlyrvult.stop();
    itlyrvult.gotoAndPlay(enlyrvult.currentFrame);
    enlyrvult.gotoAndStop(1);    //frame one is empty
    itvult.mouseEnabled = false;
    engvult.mouseEnabled = true;
} 

这会从一种语言切换到另一种语言。现在我的客户给了我另一种语言。mtlyrvult. 而且我不知道 AS3 将如何识别正在播放的 mc 以从中获取暂停位置/当前帧。

4

1 回答 1

0

我坚持你的代码(没有类,方法,成员,addChild,......)。我没有使用 Flash 或 SDK 尝试最终草案。

我假设你有:

  • 3 个影片剪辑对象:enlyrvult, itlyrvult, mtlyrvult;
  • 3 InteractiveObject (SimpleButton, MovieClip, ...) 对象: engvult, itvult, mtvult;
  • 当我们从这里开始时,它enlyrvult正在播放(如果不是:enlyrvult.play();enlyrvult.stop();)。

itlyrvult.stop();  // or itlyrvult.gotoAndStop(1); 
mtlyrvult.stop();  // or mtlyrvult.gotoAndStop(1);

engvult.addEventListener(MouseEvent.CLICK, playMC1); 
itvult.addEventListener(MouseEvent.CLICK, playMC2); 
mtvult.addEventListener(MouseEvent.CLICK, playMC3); 

// play enlyrvult
function playMC1(e:MouseEvent):void {
    // stop them
    itlyrvult.stop();
    mtlyrvult.stop();

    // play me
    enlyrvult.gotoAndPlay(mtlyrvult.currentFrame);

    // hide them
    itlyrvult.gotoAndStop(1);    //frame one is empty
    mtlyrvult.gotoAndStop(1);    //frame one is empty

    // My trigger is out, theirs are fine
    engvult.mouseEnabled = false;
    itvult.mouseEnabled = true;
    mtvult.mouseEnabled = true;
}

// play itlyrvult
function playMC2(e:MouseEvent):void {
    // stop them
    enlyrvult.stop();
    mtlyrvult.stop();

    // play me
    itlyrvult.gotoAndPlay(enlyrvult.currentFrame);

    // hide them
    enlyrvult.gotoAndStop(1);    //frame one is empty
    mtlyrvult.gotoAndStop(1);    //frame one is empty

    // My trigger is out, theirs are fine
    itvult.mouseEnabled = false;
    engvult.mouseEnabled = true;
    mtvult.mouseEnabled = true;
} 

// play mtlyrvult
function playMC3(e:MouseEvent):void {
    // stop them
    enlyrvult.stop();
    itlyrvult.stop();

    // play me
    mtlyrvult.gotoAndPlay(itlyrvult.currentFrame);

    // hide them
    enlyrvult.gotoAndStop(1);    //frame one is empty
    itlyrvult.gotoAndStop(1);    //frame one is empty

    // My trigger is out, theirs are fine
    mtvult.mouseEnabled = false;
    engvult.mouseEnabled = true;
    itvult.mouseEnabled = true;
}

或者,你想要多少(300?)...

// add to your import:
import flash.utils.Dictionary;

// in your const/var section
const STARTING_FRAME:int = 1;
var dict = new Dictionary();  // mapping and memory
var currentTrack:MovieClip;   // we will know who's last

initAll();
playTrack(enlyrvult, STARTING_FRAME, engvult);

function clickHandler(e:MouseEvent):void {
    var playheadFrame:int = currentTrack.currentFrame;                      // we remember position
    var trigger:InteractiveObject = (e.currentTarget as InteractiveObject); // who shot me ?
    var nextTrack:MovieClip = (dict[trigger] as MovieClip);                 // who's next ?

    resetAll();  // and again.. (http://en.wikipedia.org/wiki/Sisyphus)
    playTrack(nextTrack, playheadFrame, trigger);
}

function playTrack(mc:MovieClip, fram:int, iObj:InteractiveObject):void {
    currentTrack = mc;
    currentTrack.gotoAndPlay(fram);
    iObj.mouseEnabled = false;
}

function resetAll():void {
   for (var key:InteractiveObject in dict) { key.mouseEnabled = true; }
   for each (var value:MovieClip in dict) { value.gotoAndStop(1); } // diff-> each
} 

function initAll():void {
   dict[engvult] = enlyrvult;
   dict[itvult] = itlyrvult;
   dict[mtvult] = mtlyrvult;
   //dict[avult] = alyrvult; //<- new one like this: dict[trigger]=lyrMC; add as much as you can!

   for (var key:InteractiveObject in dict) {
       key.addEventListener(MouseEvent.CLICK, clickHandler);
   }

   resetAll();
}
于 2013-06-20T02:42:30.173 回答