带有计时器对象和前进或后退选项的 Flash 幻灯片放映
我刚开始使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不喜欢计时器 - 我会考虑使用 ENTER_FRAME 并使用一个变量来存储下一张幻灯片之前的时间,以便更容易管理。
以下是我的做法。
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..