带有计时器对象和前进或后退选项的 Flash 幻灯片放映

发布于 2024-11-04 23:40:36 字数 2080 浏览 1 评论 0原文

我刚开始使用 Flash,但通过一些有用的 YouTube 教程和各种 Google 搜索,我能够创建一个幻灯片放映,并在 6 秒后自动转换到下一个。我还认为,如果我能让用户能够后退、前进或专门跳转到某个幻灯片,那就太好了。但我的问题是,点击按钮后,计时器似乎关闭了。

这是我的动作脚本代码:

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){
        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 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){
        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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_蜘蛛 2024-11-11 23:40:36

我不喜欢计时器 - 我会考虑使用 ENTER_FRAME 并使用一个变量来存储下一张幻灯片之前的时间,以便更容易管理。

以下是我的做法。

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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文