this stop var host String http localhost fotogalereya var xmlUrl Strin

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
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
*/