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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
| import caurina.transitions.*;//библиотека для анимации
var arr_bigImg:Array = new Array();
var folder:String = "gallery/";
var speed:Number = 2;
var spacing:Number = 10;
var previous_button:Boolean = true;
var next_button:Boolean = true;
var tween_duration:Number = 0.6;
var bar_status:int = 0;
var pic_info_x:Number;
var pic_info_y:Number;
var first_time:Boolean = true;
var xml_loaded:Boolean = false;
var i:Number;
var next_pic_no:Number = 0;
var current_pic_no:Number = 0;
var total_items:Number;
var pic_loader:Loader;
var style:StyleSheet = new StyleSheet();
var xml:XML;
var photo_list:Array = new Array();
var mc:MovieClip = new MovieClip();
var photo_bm:Bitmap;
var pic:MovieClip = new MovieClip();
var photo_property:MovieClip = new MovieClip();
gallery.previous.stop();
gallery.next.stop();
mouseevent_roll_down(gallery.previous);
mouseevent_roll_down(gallery.next);
gallery.previous.visible = false;
gallery.next.visible = false;
function mouseevent_roll_down (button:MovieClip):void //вешает события ROLL_OUT, ROLL_OVER, MOUSE_DOWN, MOUSE_UP на кнопки
{
button.addEventListener(MouseEvent.MOUSE_DOWN, down);
function down(e:MouseEvent):void
{
button.gotoAndStop(3);
}
button.addEventListener(MouseEvent.MOUSE_UP, up);
function up(e:MouseEvent):void
{
button.gotoAndStop(2);
}
button.addEventListener(MouseEvent.ROLL_OVER, over);
function over(e:MouseEvent):void
{
button.gotoAndStop(2);
}
button.addEventListener(MouseEvent.ROLL_OUT, over1);
function over1(e:MouseEvent):void
{
button.gotoAndStop(1);
}
}
load_gallery("gallery.xml");
function load_gallery(xml_file:String):void
{
if( xml_loaded )
return;
var xml_loader:URLLoader = new URLLoader();
xml_loader.load( new URLRequest( xml_file ) );
xml_loader.addEventListener(Event.COMPLETE, create_gallery);
xml_loaded = true;
}
function create_gallery(e:Event):void
{
xml = new XML(e.target.data);
total_items = xml.photo.length();
if( xml.config.@folder.toString() != "" )
folder = xml.config.@folder.toString();
if( xml.config.@scroll_speed.toString() != "" )
speed = xml.config.@scroll_speed.toString();
if( xml.config.@tween_duration.toString() != "" )
tween_duration = parseFloat( xml.config.@tween_duration.toString() );
if (total_items<2)
{
previous_button = false;
next_button = false;
}
if( speed > 10 || speed < 1 ) speed = 5;
for( i = 0; i < total_items; i++ )
{
photo_list.push({filename: xml.photo[i].filename.toString()});
}
load_photo();
}
function load_photo():void//после разбора xml приступаем к созданию самой галлереи
{
close_loader();
var pic_request:URLRequest = new URLRequest( folder + photo_list[next_pic_no].filename );
pic_loader = new Loader();
pic_loader.load(pic_request);
pic_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, on_photo_progress);
pic_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, on_photo_loaded);
/*gallery.loading_photo.text = "загрузка изображения...";
gallery.loading_photo.visible = true;
gallery.loading_photo_bg.visible = true;*/
if( first_time )
{
photo_property.addChild(pic);
gallery.addChild(photo_property);
/*gallery.addChild( gallery.loading_photo_bg );
gallery.addChild( gallery.loading_photo ); */
}
}
function close_loader():void
{
try
{
pic_loader.close();
pic_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, on_photo_progress);
pic_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, on_photo_loaded);
}
catch( e:Error ){}
}
function on_photo_progress(e:ProgressEvent):void//прогресс загрузки изображания
{
var percent:Number = Math.round( e.bytesLoaded / e.bytesTotal * 100 );
var filesize:Number = Math.round( e.bytesTotal / 1024 );
/*gallery.loading_photo.text = "Загрузка " + photo_list[ next_pic_no ].tooltip +
"... " + percent + "% (" + filesize + "KB)";
gallery.loading_photo_bg.width = gallery.loading_photo.width + 5;*/
}
var X1:Number = 0;
var Y1:Number = 0;
function on_photo_loaded(e:Event):void
{
photo_bm = new Bitmap();
photo_bm = Bitmap(e.target.content);
photo_bm.smoothing = true;
photo_bm.x=-photo_bm.width/2;
photo_bm.y=-photo_bm.height/2;
X1 = ((photo_bm.width / 2) + photo_bm.x)- (photo_bm.width+15)/2;
Y1 = ((photo_bm.height / 2) + photo_bm.y) - (photo_bm.height+15)/2;
if( first_time )
{
X1 = 0;
Y1 = 0;
gallery.podlojka.height = (photo_bm.height + 15);
gallery.podlojka.width = (photo_bm.width + 15);
X1 = ((photo_bm.width / 2) + photo_bm.x)- gallery.podlojka.width/2;
Y1 = ((photo_bm.height / 2) + photo_bm.y) - gallery.podlojka.height/2;
gallery.podlojka.x = X1;
gallery.podlojka.y = Y1;
gallery.podlojka.alpha = 1;
first_time = false;
add_photo();
}
else
{
gallery.previous.visible = false;
gallery.next.visible = false;
/****** Использование твинер классов для анимации фото *********/
Tweener.addTween( gallery.podlojka, { alpha: 0, time: tween_duration,
transition: "easeIn", onComplete: coord} );
Tweener.addTween( pic, { alpha: 0, time: tween_duration,
transition: "easeIn", onComplete: remove_photo } );
}
}
function coord():void
{
gallery.podlojka.x = X1;
gallery.podlojka.y = Y1;
gallery.podlojka.height = (photo_bm.height + 15);
gallery.podlojka.width = (photo_bm.width + 15);
/****** Использование твинер классов для анимации фото *********/
Tweener.addTween( gallery.podlojka, { alpha: 1, time: tween_duration, transition: "easeOut" });
}
function remove_photo():void
{
pic.removeChildAt( 0 );
add_photo();
}
function add_photo():void
{
current_pic_no = next_pic_no;
pic.addChild( photo_bm );
pic.addEventListener( MouseEvent.CLICK, on_photo_click );
if( previous_button )
{
gallery.previous.addEventListener( MouseEvent.CLICK, on_previous_click, false, 0, true );
gallery.previous.visible = true;
}
if( next_button )
{
gallery.next.addEventListener( MouseEvent.CLICK, on_next_click , false, 0, true );
gallery.next.visible = true;
}
Tweener.addTween( pic, { alpha: 1, time: tween_duration, transition: "easeOut" });
}
function on_previous_click(me:MouseEvent):void//предыдущее фото
{
next_pic_no--;
if( next_pic_no < 0 )
next_pic_no = total_items - 1;
load_photo();
}
function on_next_click(me:MouseEvent):void//следующее фото
{
next_pic_no++;
if( next_pic_no >= total_items )
next_pic_no = 0;
load_photo();
}
function on_photo_click(me:MouseEvent):void//функция для обработки клика по фото
{
} |