开发者

Flash slide show with timer object and the option to go forward or backwards

I am new to using Flash, but with some helpful YouTube tutorials and various Google searches, I was able to create a slide show that automatically transitions to the next after 6 seconds. I also thought it would be neat if I could give users the ability to go back or forward or jump specifically to a certain slide. But my problem is that after I click a button, the timer seems to be off.

Here is my actionscript code:

import flash.events.MouseEvent;
import flash.utils.*;

// Stop initial picture fading from looping
stop()

// New timer object set to 6 seconds (1000 milliseconds/second)
var myTimer:Timer = new Timer(6000, 1);

myTimer.addEventListener ("timer", timerHandler);
myTimer.reset();
myTimer.start();

function timerHandler(event:TimerEvent): void {
if(currentFrame == 4){
     myTimer.reset();
     myTimer.start();
     gotoAndStop("pajNtaub");
 }else{
     myTimer.reset();
     myTimer.start();
     nextFrame();
     }
}

// Move to next state
function onNextClick(event:MouseEvent):void{
    if(currentFrame == 4){
        myTimer.reset();
        myTimer.start();
        gotoAndStop("pajNtaub");
    }else{
        myTimer.reset();
        myTimer.start();
        nextFrame();
    }
}
forwardArrow.addEventListener(MouseEvent.CLICK, onNextClick);

// Move to previous state
function onPrevClick(event:MouseEvent):void{
    if(currentFrame == 1)开发者_JAVA技巧{
        myTimer.reset();
        myTimer.start();
        gotoAndStop("posHuab");
    }else{
        myTimer.reset();
        myTimer.start();
        prevFrame();
    }
}
backArrow.addEventListener(MouseEvent.CLICK, onPrevClick);

// First button
function play0(event:MouseEvent):void{
    myTimer.reset();
    myTimer.start();
    gotoAndStop("pajNtaub");
}
button0.addEventListener(MouseEvent.CLICK,play0);

// Second button
function play1(event:MouseEvent):void{
    myTimer.reset();
    myTimer.start();
    gotoAndStop("kabTab");
}
button1.addEventListener(MouseEvent.CLICK,play1);

// Third button
function play2(event:MouseEvent):void{
    myTimer.reset();
    myTimer.start();
    gotoAndStop("nroog");
}
button2.addEventListener(MouseEvent.CLICK,play2);

// Fourth button
function play3(event:MouseEvent):void{
    myTimer.reset();
    myTimer.start();
    gotoAndStop("posHuab");
}
button3.addEventListener(MouseEvent.CLICK,play3);


I'm not a fan of timers - I'd look at using ENTER_FRAME and having a variable that stores the time until your next slide so it's easier to manage..

Here's how I would look at doing it..

stop();

// vars
var nextTimer:int = 200;
var maxTimer:int = nextTimer;

// ENTER_FRAME
addEventListener(Event.ENTER_FRAME, _slideshow);
function _slideshow(e:Event):void
{
    nextTimer --;
    if(nextTimer < 1)
    {
        nextSlide();
    }
}


/**
 * Go to the next slide in the slideshow
 */
function nextSlide(e:MouseEvent=null):void
{
    nextTimer = maxTimer;

    if(currentFrame + 1 > totalFrames) gotoAndStop(1);
    else gotoAndStop(currentFrame + 1);
}

/**
 * Go to the previous slide in the slideshow
 */
function prevSlide(e:MouseEvent=null):void
{
    nextTimer = maxTimer;

    if(currentFrame - 1 < 1) gotoAndStop(totalFrames);
    else gotoAndStop(currentFrame - 1);
}


// listeners for next and prev buttons
nextbtn.addEventListener(MouseEvent.CLICK, nextSlide);
prevbtn.addEventListener(MouseEvent.CLICK, prevSlide);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜