this.stop();
var host:String = "http://localhost/fotogalereya/";
var xmlUrl:String = "file.xml";
var loader:URLLoader = new URLLoader();
var imageLoader:Loader = new Loader();
var largeImageLoader:Loader = new Loader();
var xml:XML;
// Images
var imgThumb:Array = new Array();
var thumbnails:Array = new Array();
var imgNormal:Array = new Array();
var imgNormalCurrent:Number = 0;
var imgLarge:Array = new Array();
var imgLargeCurrent:Number = 0;
var descriptions:Array = new Array();
/*
* Configuring Listeners
*/
this.loader.addEventListener(Event.COMPLETE, this.xmlLoaded);
this.imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.imageLoaded);
this.largeImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.largeImageLoaded);
this.largeImageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, this.largeImageLoading);
// Loading XML data
this.loader.load(new URLRequest(this.host + this.xmlUrl));
// UI correcting
this.percentText.visible = false;
this.descText.visible = false;
/*
*
*/
function xmlLoaded(e:Event):void {
this.xml = new XML(e.target.data);
// Loading image thumbnails
if (this.xml.child("photo").length() > 0) {
this.loadThumbnails();
}
}
function loadThumbnails():void {
if (this.descriptions.length < this.xml.child("photo").length()) {
this.imageLoader.load(new URLRequest(
this.host + this.xml.child("photo")[this.descriptions.length].thumb +
'?t=' + (new Date().time.toString())
));
} else {
this.mvThumb.thumbContainer.thumbnail.visible = false;
for (var i:Number = 0; i < this.imgThumb.length; i++) {
this.thumbnails[i].addChild(this.imgThumb[i]);
this.imgThumb[i].x = 1;
this.imgThumb[i].y = 1;
this.thumbnails[i].addEventListener(MouseEvent.MOUSE_OVER, this.showPopup);
this.thumbnails[i].addEventListener(MouseEvent.MOUSE_OUT, this.hidePopup);
this.thumbnails[i].addEventListener(MouseEvent.CLICK, this.thumbClick);
}
this.imageLoader = new Loader();
this.imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.normalImageLoaded);
}
}
function imageLoaded(e:Event):void {
var i:Number = this.imgThumb.length;
this.thumbnails.push(new Thumbnail());
this.mvThumb.thumbContainer.addChild(this.thumbnails[i]);
this.thumbnails[i].x = 10 + i * (this.thumbnails[i].width + 5);
this.thumbnails[i].y = this.mvThumb.thumbContainer.thumbnail.y;
this.thumbnails[i].index = i;
this.descriptions.push(
this.xml.child("photo")[i].description
);
this.imgThumb.push(e.target.content);
this.loadThumbnails();
}
function normalImageLoaded(e:Event):void {
var str:String = e.target.url;
var tmpContainer:DisplayObject = e.target.content;
this.imageLoader.unload();
str = str.substr(this.host.length);
str = str.substr(0, str.lastIndexOf("?"));
for (var i:Number = 0; i < this.xml.child("photo").length(); i++) {
if (str == this.xml.child("photo")[i].normal) {
this.imgNormal[i] = tmpContainer;
this.mvThumb.normalImage.addChild(this.imgNormal[i]);
this.imgNormal[i].x = - this.imgNormal[i].width / 2;
this.imgNormal[i].y = -126;
break;
}
}
}
function showPopup(e:MouseEvent):void {
this.mvThumb.normalImage.x = e.target.x + e.target.width / 2;
this.mvThumb.normalImage.visible = true;
if (this.imgNormal[e.target.index] == undefined) {
if (this.imgNormal[this.imgNormalCurrent] != undefined) {
this.imgNormal[this.imgNormalCurrent].visible = false;
}
this.imgNormalCurrent = e.target.index;
this.imageLoader.load(new URLRequest(
this.host + this.xml.child("photo")[e.target.index].normal +
'?t=' + (new Date().time.toString())
));
} else {
if (this.imgNormal[this.imgNormalCurrent] != undefined) {
this.imgNormal[this.imgNormalCurrent].visible = false;
this.imgNormalCurrent = e.target.index;
this.imgNormal[this.imgNormalCurrent].visible = true;
}
this.imgNormalCurrent = e.target.index;
this.imgNormal[this.imgNormalCurrent].visible = true;
}
}
function hidePopup(e:MouseEvent):void {
this.mvThumb.normalImage.visible = false;
}
function largeImageLoaded(e:Event):void {
var str:String = e.target.url;
var tmpContainer:DisplayObject = e.target.content;
this.largeImageLoader.unload();
this.percentText.visible = false;
str = str.substr(this.host.length);
str = str.substr(0, str.lastIndexOf("?"));
for (var i:Number = 0; i < this.xml.child("photo").length(); i++) {
if (str == this.xml.child("photo")[i].large) {
this.imgLarge[i] = tmpContainer;
this.largeImage.addChild(this.imgLarge[i]);
this.imgLarge[i].x = - this.imgLarge[i].width / 2;
this.imgLarge[i].y = -126;
break;
}
}
}
function thumbClick(e:Event):void {
if (this.imgLarge[e.target.index] == undefined) {
if (this.imgLarge[this.imgLargeCurrent] != undefined) {
this.imgLarge[this.imgLargeCurrent].visible = false;
}
this.imgLargeCurrent = e.target.index;
this.largeImageLoader.load(new URLRequest(
this.host + this.xml.child("photo")[e.target.index].large +
'?t=' + (new Date().time.toString())
));
this.percentText.text = "0%";
this.percentText.visible = true;
} else {
if (this.imgLarge[this.imgLargeCurrent] != undefined) {
this.imgLarge[this.imgLargeCurrent].visible = false;
this.imgLargeCurrent = e.target.index;
this.imgLarge[this.imgLargeCurrent].visible = true;
}
this.imgLargeCurrent = e.target.index;
this.imgLarge[this.imgLargeCurrent].visible = true;
}
}
function largeImageLoading(event: ProgressEvent):void {
var percent:Number = event.bytesLoaded / event.bytesTotal * 100;
this.percentText.text = percent.toString() + "%";
}
/*
* Functions
*/