Flash CS3 - XML - Photo Viewer








Download PhotoViewer.zip, 588 KB

PhotoViewer.as

ActionScript Code:

// Developed by Anil kumar N D
// anilkumarnd@gmail.com
// ActionScript 3.0
// 29-April-2009
// http://flash-workshop.blogspot.com/

package {

import flash.display.MovieClip;
import flash.display.Shape;
import flash.display.Loader;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
import flash.events.ProgressEvent;
import fl.transitions.*;
import fl.transitions.easing.*;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.net.URLLoader;

public class PhotoViewer extends MovieClip {

var mc_mask:MovieClip = new MovieClip();

var photoTimer:Timer=new Timer(3000);

var i:uint=0;

var uint_rndUInt:uint=0;

var arr_type:Array=new Array(Blinds,Fade,Fly,Iris,Photo,PixelDissolve,Rotate,Squeeze,Wipe,Zoom);

var arr_imagesURLs:Array = new Array();

var arr_images:Array = new Array();

var shp_mainLine:Shape;

var shp_statusLine:Shape;

var txt_status:TextField;

var txt_fileStatus:TextField;

var xmlData:XML= new XML();

var xmlLoader:URLLoader = new URLLoader();

public function PhotoViewer():void {

stage.frameRate=30;

photoTimer.addEventListener("timer", timerHandler);

xmlLoader=new URLLoader(new URLRequest("images.xml"));

xmlLoader.addEventListener(Event.COMPLETE,gotXML);

 

}

function gotXML(evt:Event):void {

xmlLoader.removeEventListener(Event.COMPLETE,gotXML);

xmlData=XML(xmlLoader.data);

for each (var item:XML in xmlData..image) {

arr_imagesURLs.push(item);

}

createStatusBar();

loadImages();

}

function loadImages():void {

txt_fileStatus.text="Loading \""+arr_imagesURLs[i]+"\"";

var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);

loader.load(new URLRequest("images/"+arr_imagesURLs[i++]));

}

function progressHandler(IN_Event:ProgressEvent):void {

var percent:Number=IN_Event.bytesLoaded*100/IN_Event.bytesTotal;

shp_statusLine.scaleX=percent/100;

txt_status.text=Math.round(percent)+" %";

}

function completeHandler(IN_Event:Event):void {

var mc_image:MovieClip = new MovieClip();

IN_Event.target.content.x=- IN_Event.target.content.width/2;

IN_Event.target.content.y=- IN_Event.target.content.height/2;

mc_image.addChild(IN_Event.target.content);

mc_image.visible=false;

addChild(mc_image);

arr_images.push(mc_image);

if (i<arr_imagesURLs.length) {

loadImages();

} else {

removeChild(shp_mainLine);

removeChild(shp_statusLine);

removeChild(txt_status);

removeChild(txt_fileStatus);

uint_rndUInt=randomInRange(0,arr_images.length-1);

arr_images[uint_rndUInt].x=arr_images[uint_rndUInt].width/2;

arr_images[uint_rndUInt].y=arr_images[uint_rndUInt].height/2;

TransitionManager.start(arr_images[uint_rndUInt], {type:arr_type[randomInRange(0,arr_type.length-1)], direction:Transition.IN, duration:1, easing:None.easeNone});

photoTimer.start();

}

}

public function timerHandler(event:TimerEvent):void {

while (uint_rndUInt == (uint_rndUInt=randomInRange(0,arr_images.length-1))) {

}

arr_images[uint_rndUInt].x=arr_images[uint_rndUInt].width/2;

arr_images[uint_rndUInt].y=arr_images[uint_rndUInt].height/2;

this.setChildIndex(arr_images[uint_rndUInt],this.numChildren-1);

TransitionManager.start(arr_images[uint_rndUInt], {type:arr_type[randomInRange(0,arr_type.length-1)], direction:Transition.IN, duration:1, easing:None.easeNone});

}

 

 

/**************************************************************************************************

This function returns a random number between min and max number

**************************************************************************************************/

function randomInRange(min:Number,max:Number):Number {

var scale:Number=max- (--min);

return Math.ceil(Math.random() * scale + min);

}

 

function createStatusBar():void {

shp_mainLine = new Shape();

shp_mainLine.graphics.lineStyle(8,0x00CC00);

shp_mainLine.graphics.lineTo(200,0);

shp_mainLine.x = (stage.stageWidth/2)-(shp_mainLine.width/2);

shp_mainLine.y = (stage.stageHeight/2);

shp_statusLine = new Shape();

shp_statusLine.graphics.lineStyle(1,0xFFFFFF);

shp_statusLine.graphics.lineTo(200,0);

shp_statusLine.scaleX=.01;

shp_statusLine.x=(stage.stageWidth/2)-(shp_mainLine.width/2);

shp_statusLine.y=(stage.stageHeight/2);

txt_status = new TextField();

txt_status.autoSize=TextFieldAutoSize.CENTER;

txt_status.selectable=false;

txt_status.textColor=0x000000;

txt_status.y=shp_mainLine.y+10;

txt_status.x=shp_mainLine.x + (shp_mainLine.width/2);

 

txt_fileStatus = new TextField();

txt_fileStatus.autoSize=TextFieldAutoSize.CENTER;

txt_fileStatus.selectable=false;

txt_fileStatus.textColor=0x000000;

txt_fileStatus.y=shp_mainLine.y-30;

txt_fileStatus.x=shp_mainLine.x + (shp_mainLine.width/2);

addChild(shp_mainLine);

addChild(shp_statusLine);

addChild(txt_status);

addChild(txt_fileStatus);
}

}
}





Comments

Unknown said…
great job pal keep it up
Anonymous said…
Thanks for the download link. I liked your image viewer. It's really clean.
flash website developer

Popular posts from this blog

AS3 - Access objects from external SWF files

Flash CS3 - XML Guestbook (AS3)

Flash CS4 - 3D Rotating Menu