var imageTimer:Timer = new Timer(10000);
imageTimer.addEventListener(TimerEvent.TIMER, onNewImage);
imageTimer.start();
var imageCount:int = -1;
function onNewImage(e:Event):void {
//trace("load New Image");
if (imageCount < images.length-1) {
imageCount++;
} else {
imageCount = 0;
}
var nextImageURL:String = images[imageCount].url;
var nextImageTEXT:String = images[imageCount].name;
var imageLoader:Loader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoad);
imageLoader.load(new URLRequest(nextImageURL));
function onImageLoad(evt:Event):void {
var loader:Bitmap = Bitmap(evt.target.content);
var resizeHeight:uint = 250;
var resizeWidth:uint = 375;
//Resize the images
if (loader.width > loader.height) {
// RESIZE WIDTH
var diff:Number = loader.width - resizeWidth;
//trace("diff: "+diff);
var perc:Number = (loader.width - diff )/loader.width*100;
//trace("perc: "+perc);
loader.scaleX = loader.scaleY = perc/100;
//Position Y
loader.y = resizeHeight/2 - loader.height/2;
} else if (loader.width < loader.height) {
// RESIZE HEIGHT
var ddiff:Number = loader.height - resizeHeight;
//trace("ddiff: "+ddiff);
var pperc:Number = (loader.height - ddiff )/loader.height*100;
//trace("pperc: "+pperc);
loader.scaleX = loader.scaleY = pperc/100;
//Position X
loader.x = resizeWidth/2 - loader.width/2;
}
imagePlayer.imageHolder.addChild(loader);
imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onImageLoad);
if (imagePlayer.imageHolder.numChildren >= 2) {
var bo:Object = imagePlayer.imageHolder.getChildAt(1);
var oldbo:Object = imagePlayer.imageHolder.getChildAt(0);
//trace(bo);
bo.alpha = 0;
Tweener.addTween(bo, {alpha:1, time:1, transition:"linear", onComplete:remove});
//if (imagePlayer.imageHolder.numChildren != 1) {
Tweener.addTween(oldbo, {alpha:0, time:1, transition:"linear"});
function remove():void {
imagePlayer.image_txt.text = nextImageTEXT;
if (imagePlayer.imageHolder.numChildren != 0) {
imagePlayer.imageHolder.removeChildAt(0);
}
}
}
}
}
|