Flash 图像阵列-不在所有图像中循环
问题-它不是在数组中循环遍历图像,而是直接跳到最后一个图像Flash 图像阵列-不在所有图像中循环,flash,actionscript-3,Flash,Actionscript 3,问题-它不是在数组中循环遍历图像,而是直接跳到最后一个图像 import fl.transitions.Tween; import fl.transitions.easing.*; play_btn.addEventListener(MouseEvent.CLICK, goPlay) var images = new Array(); images[0] = "1.jpg"; images[1] = "2.jpg"; images[2] = "3.jpg"; images[3] = "4.
import fl.transitions.Tween;
import fl.transitions.easing.*;
play_btn.addEventListener(MouseEvent.CLICK, goPlay)
var images = new Array();
images[0] = "1.jpg";
images[1] = "2.jpg";
images[2] = "3.jpg";
images[3] = "4.jpg";
images[4] = "5.jpg";
images[5] = "6.jpg";
images[6] = "7.jpg";
images[7] = "8.jpg";
images[8] = "9.jpg";
images[9] = "10.jpg";
var currentImage:int = 0;
function goPlay(e:MouseEvent):void {
while (currentImage < 10) {
loadWindow.source = images[currentImage];
currentImage++;
var myTween:Tween = new Tween(loadWindow, "alpha", None.easeOut, 1, 0, 3, true)
}
}
导入fl.transitions.Tween;
导入fl.transitions.easing.*;
play_btn.addEventListener(MouseEvent.CLICK,goPlay)
var images=新数组();
图像[0]=“1.jpg”;
图片[1]=“2.jpg”;
图片[2]=“3.jpg”;
图片[3]=“4.jpg”;
图片[4]=“5.jpg”;
图片[5]=“6.jpg”;
图片[6]=“7.jpg”;
图片[7]=“8.jpg”;
图片[8]=“9.jpg”;
图片[9]=“10.jpg”;
var currentImage:int=0;
函数goPlay(e:MouseEvent):无效{
而(当前图像<10){
loadWindow.source=图像[currentImage];
currentImage++;
var myTween:Tween=新Tween(加载窗口,“alpha”,None.easeOut,1,0,3,true)
}
}
这是你的问题
在goPlay上,你循环浏览所有的游戏,并在最后一个游戏结束
基本上你是这样做的
function goPlay(e:MouseEvent) {
loadWindow.source = images[0];
var myTween:Tween = new Tween(loadWindow, "alpha", None.easeOut, 1, 0, 5, true);
loadWindow.source = images[1];
var myTween:Tween = new Tween(loadWindow, "alpha", None.easeOut, 1, 0, 5, true);
loadWindow.source = images[2];
var myTween:Tween = new Tween(loadWindow, "alpha", None.easeOut, 1, 0, 5, true);
etc..
loadWindow.source = images[9];
var myTween:Tween = new Tween(loadWindow, "alpha", None.easeOut, 1, 0, 5, true);
}
变成
function goPlay(e:MouseEvent) {
loadWindow.source = images[9];
var myTween:Tween = new Tween(loadWindow, "alpha", None.easeOut, 1, 0, 5, true);
}
因此,每次单击时,只添加最后一张图像
您需要在函数外部定义变量i
像这样的
var _currentImage:int = 0;
function goPlay(e:MouseEvent) {
currentImage = (currentImage+1)%images.length;
loadWindow.source = images[currentImage];
var myTween:Tween = new Tween(loadWindow, "alpha", None.easeOut, 1, 0, 5, true);
}
希望一切都清楚
如果希望动画自动发生(按下按钮后)
这看起来应该行得通,但我想知道他们是否希望goPlay()按钮像动画一样在图像中循环。而不是每次点击循环浏览图片。是的,它确实需要像一个侧秀一样自动循环*这就是为什么我把它放在一个循环中。循环从来不会在多个帧上执行。在一帧和下一帧之间执行循环。例如,如果有一个循环将对象位置向右移动了1个像素,并且循环运行了550次,则该循环将无法平滑地设置动画。在一帧的时间内,它会立即跳到550像素。。。。那么我需要做些什么才能让它工作呢?我尝试只添加了10个额外的帧,但随后出现了关于空引用的错误。更新了代码,但仍然无法工作
var _currentImage:int = 0;
var myTimer:Timer = new Timer(5000, 0); // 5 seconds
myTimer.addEventListener(TimerEvent.TIMER, switchPics);
function goPlay(e:MouseEvent) {
myTimer.start();
}
function goStop(e:MouseEvent) {
myTimer.stop();
}
function switchPics(event:TimerEvent):void {
currentImage = (currentImage+1)%images.length;
loadWindow.source = images[currentImage];
var myTween:Tween = new Tween(loadWindow, "alpha", None.easeOut, 1, 0, 5, true);
}