|
文档类:
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.Bitmap;
public class Image extends Sprite {
private var imgLod:Array;//保存所有图片
private var imgA:Bitmap;
private var imgB:Bitmap;
private var numImg:uint=10;//图像个数
var a:int;
public function Image():void {
init();
}
private function init():void {
imgLod=new Array();
for (var i:uint=1; i<=numImg; i++) {
var nameStr:String=i.toString();
if (nameStr.length==1) {
nameStr="0"+nameStr;
}
nameStr="images/"+nameStr+".jpg";
var loaderoader = new Loader();
var request_url:URLRequest = new URLRequest(nameStr);
loader.load(request_url);
//imgLod.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeListener);
}
}
private function completeListener(e:Event):void {
imgLod.push(e.target.content);
a++;
if (a==numImg) {
a=0;
imgA=imgLod[a];
imgB=imgLod[a+1];
addChild(imgA);
addChild(imgB);
imgB.x=-imgB.width;
a++;
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
}
private function onEnterFrame(e:Event):void {
//定义缓动
var dx:Number=imgA.x-imgB.x;
var vx:Number=dx*0.5;
imgB.x+=vx;
//检查是否到位
if (imgB.x<1 && imgB.x>=0) {
//检测是否应该循环
if(a>=9){
a=0;
}
addChild(imgA);
imgA=imgB;
imgA.x=imgA.y=0;
addChild(imgA);
a++;
imgB=imgLod[a];
imgB.x=-imgB.width;
addChild(imgB);
}
}
}
}
|
|