1

各フレームにムービークリップが含まれる30〜40フレームのプロジェクトがあります。各フレームをスライドと考えてください。ステージの下部には、これらのスライドの機能を制御するボタンがあります(たとえば、再生、一時停止、次へ、前へ、スピードアップ、スローダウン、リフレッシュ)。しかし、私に頭痛の種を与えている2つのボタンは、手動モードと自動モードのボタンです。それらの名前は正確にそれらがどのように聞こえるかであり、各mcが各フレームで再生された後に手動で停止する必要があります。Autoは各フレームを順番に再生する必要があります。私が今設定している方法は、各mcが「finished」と「stopped」のEventDispatchを起動することです。最後にクリックされたボタンに応じて、ステージはイベントをリッスンし、4秒間一時停止(setInterval)してgotoNextFrameするか、ユーザーが次をクリックするまでそのフレームで停止します。スイッチケースを試してみました、

私はかなり初心者なので、優しくしてください。そして、それがこれ以上役立つなら、私はflvをアップロードします。どうもありがとうございました。

//Manual button actions
function manual_onClick(event:MouseEvent)
{
    manual_btn.visible = false;
    auto_btn.visible = true;
    gotoAndStop(currentFrame);
    stage.removeEventListener("finished", mcFinished);
    stage.addEventListener("stopped",stopmc,false,0);


    function stopmc(e:Event):void
    {
        trace("mc stop");
        stage.removeEventListener("stopped",stopmc);
    }
}


//Auto button actions
function auto_onClick(event:MouseEvent)
{
    gotoAndStop(currentFrame + 1);
    manual_btn.visible = true;
    auto_btn.visible = false;
    stage.addEventListener("finished", mcFinished2,false,1);


    function mcFinished2(e:Event):void
    {
        var ID2 = setInterval(goNextFrame2,3000);
        trace("mc complete");
        function goNextFrame2()
        {
            gotoAndStop( currentFrame + 1 );
            clearInterval( ID2 );
            stage.removeEventListener("finished", mcFinished2);
        }
    }
}

および各mcからのdispatchEvent

stop();

dispatchEvent(new Event("finished", true));
dispatchEvent(new Event("stopped", true));

再度、感謝します!スコット

これがスイッチケースの試みです...

function onBtnClicked(evt:MouseEvent):void
{
    var theBtn:DisplayObject = evt.currentTarget as DisplayObject;
    var lastBtn:DisplayObject;


    if (lastBtn)
    {
        lastBtn.addEventListener(MouseEvent.CLICK, onBtnClicked);
    }

    lastBtn = theBtn;

    switch (theBtn)
    {
        case auto_btn :
            //button one actions;
            gotoAndStop(currentFrame + 1);
            manual_btn.visible = true;
            auto_btn.visible = false;
            trace("auto button clicked");

            stage.addEventListener("finished", mcFinished);
            function mcFinished(e:Event):void
            {
                var ID = new setInterval(goNextFrame,3000);
                trace("mc complete");
                function goNextFrame()
                {
                    gotoAndStop( currentFrame + 1 );
                    clearInterval( ID );
                    stage.removeEventListener("finished", mcFinished);
                    stage.addEventListener("finished", mcFinished);
                }
            }


            break;
        case manual_btn :

            manual_btn.visible = false;
            auto_btn.visible = true;
            trace("manual button clicked");

            stage.removeEventListener("finished", mcFinished);
            stage.addEventListener("stopped",stopmc,false,1);


            function stopmc(e:Event):void
            {
                trace("mc stop");
                stage.addEventListener("stopped",stopmc);
                stage.removeEventListener("stopped",stopmc);
            }

            break;
    }
}
4

1 に答える 1

0

ここにいくつかの推奨事項があります。

まず、各クリップの最後に2つの個別のイベント(「終了/停止」)が必要ありません。これらはまったく同じ機能を果たしているからです。1つのイベントを実行し、のような組み込みイベントを使用することをお勧めしEvent.COMPLETEます。したがって、個々のクリップの最後のフレームは次のようになります。

stop();
dispatchEvent(new Event(Event.COMPLETE, true));

個々のクリップの最初のフレームに、これを追加します。

//use these two listeners so that the clip is only listening when it's being displayed on the timeline.
this.addEventListener(Event.ADDED_TO_STAGE,init,false,0,true);
this.addEventListener(Event.REMOVED_FROM_STAGE,unload,false,0,true);

function init(e:Event){
    stage.addEventListener("Play",playMe,false,0,true);
    stage.addEventListener("Pause",pauseMe,false,0,true);
}

function unload(e:Event){
    stage.removeEventListener("Play",playMe,false);
    stage.removeEventListener("Pause",pauseMe,false);
}

function playMe(e:Event){
    play();
}

function pauseMe(e:Event){
    stop();
}

これが私があなたのコードの残りをどのように行うかです:

stop();  //stop the main timeline

manual_btn.addEventListener(MouseEvent.CLICK, onBtnClicked);
auto_btn.addEventListener(MouseEvent.CLICK, onBtnClicked);

var nextTimer:Timer = new Timer(4000,1); //a timer to wait 4 seconds before auto next.
nextTimer.addEventListener(TimerEvent.TIMER, nextSlide); //what the timer should do when it's done

var isAuto:Boolean = true;  //a variable that holds the state of automatically continuing to the next slide. set it's default to either true or false

this.addEventListener(Event.COMPLETE,slideComplete); //listens for any slide complete event

//this function will get run whenever one of your slides is complete.
function slideComplete(e:Event = null):void {
    if(isAuto){
       nextTimer.reset();
       nextTimer.start(); //start the timer
    }
}

function onBtnClicked(evt:MouseEvent):void {
    manual_btn.visible = (evt.currentTarget == manual_btn);
    auto_btn.visible = (evt.currentTarget == auto_btn);

    isAuto = auto_btn.visible;
}

function nextSlide(e:Event = null):void {  //default e to null so you can call this function directly nextSlide(); - have your next button click call this function too
    nextTimer.reset(); //stop/reset the timer 
    nextFrame(); //tell the main timeline to go to the next frame
}

function prevSlide(e:Event = null):void {
    nextTimer.reset(); //reset the timer in case it's running
    prevFrame();
}

function pause(e:Event = null):void {
    nextTimer.reset():
    stage.dispatchEvent(new Event("Pause")); //have your individual clips listen for this event and stop
}

function playSlide(e:Event = null):void {
    nextTimer.reset();
    stage.dispatchEvent(new Event("Play")); //have your individual clips listen for this event and play;
}

すべてのボタンクリックでタイマーをリセットする理由は、自動次への起動が待機しているときに、その4秒のウィンドウで前または次を押した場合です。例:自動次へがオンになり、スライドが終了してから1秒後に前のボタンを押すと、前のスライドに移動します。3秒後にタイマーが起動し、次のフレームに移動します。

于 2012-12-13T21:06:07.537 に答える