1

我有一个项目,它有 30-40 帧,每帧都有影片剪辑。把每一帧想象成一张幻灯片。舞台底部有控制这些幻灯片功能的按钮(例如播放、暂停、下一个、上一个、加速、减速和刷新)。但是,让我头疼的两个按钮是手动模式和自动模式按钮。他们的名字正是他们的声音,手动应该在每个 mc 在每一帧播放后停止。自动应该按顺序播放每一帧。我现在设置它的方式是每个 mc 触发一个“完成”和“停止”的 EventDispatch。根据最后单击的按钮,舞台将侦听事件并暂停 4 秒 (setInterval) 并转到NextFrame,或者在该帧上停止,直到用户单击下一步。我试过一个开关盒,

我是新手,所以要温柔。如果有帮助,我会上传 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

这里有一些建议。

首先,您不需要在每个剪辑的末尾有两个单独的事件(“完成/停止”),因为它们提供完全相同的功能。我建议只做一个事件并使用内置事件,如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 回答