-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlideshowAutomatico.as
269 lines (200 loc) · 6.37 KB
/
SlideshowAutomatico.as
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
var arr = [];
arr.push('http://developer.yahoo.com/ypatterns/images/pattern_calendar_sub.gif');
arr.push('http://developer.yahoo.com/ypatterns/images/pattern_carousel_sub.jpg');
arr.push('http://developer.yahoo.com/ypatterns/images/pattern_achievements_sub.jpg');
arr.push('http://developer.yahoo.com/ypatterns/images/pattern_competitive_sub.jpg');
arr.push('http://developer.yahoo.com/ypatterns/images/pattern_replabels_sub.jpg');
arr.push('http://developer.yahoo.com/ypatterns/images/pattern_leaderboard_sub.jpg');
arr.push('http://developer.yahoo.com/ypatterns/images/pattern_namedlevels_sub.jpg');
arr.push('http://developer.yahoo.com/ypatterns/images/pattern_numberedlevels_sub.jpg');
arr.push('http://developer.yahoo.com/ypatterns/images/pattern_grid_sub.gif');
var sld:SlideshowAutomatico = new SlideshowAutomatico(_root, arr, 1, 4);
sld.onLoadProgress = function ():void {
trace('...', sld.percentLoaded);
}
sld.onLoadComplete = function ():void {
trace('complete ', sld.mcAtual);
}
sld.start();
var sc:Shortcuts = new Shortcuts(_stage);
sc.add('a', sld.anterior);
sc.add('s', sld.proxima);
sc.add('p', sld.pause);
sc.add('l', sld.resume);
sc.add('m', sld.remove);
*/
package {
import flash.display.*
import flash.events.*;
import gs.TweenMax
import flash.utils.*;
public class SlideshowAutomatico {
private var __arr:Array
private var __imgfader:ImgFader
private var __delay1:Number
private var __delay2:Number
private var __t1:Timer //delay longo
private var __t2:Timer //delay normal
public var indexImg:Number; //numero da imagem atual
public var isPaused:Boolean = false;
public var isLoading:Boolean = false; //isLoading só é true quando o usuario interage
public var onLoadStart:Function
public var onLoadProgress:Function
public var onLoadComplete:Function
public var mc:MovieClip // movieclip onde o slideshow é carregado
public var mcAtual:MovieClip // movieclip onde a ultima imagem foi carregada, no onLoadComplete
public var percentLoaded:Number = 0;
public function SlideshowAutomatico($mcAlvo:DisplayObjectContainer, $arrUrls:Array, $intervalo:Number = 3, $intervalo2:Number = 6):void {
__arr = $arrUrls;
__delay1 = $intervalo*1000;
__delay2 = $intervalo2*1000;
__imgfader = new ImgFader($mcAlvo);
__imgfader.addEventListener(ImgFader.ON_LOAD_START, __onLoadStart)
__imgfader.addEventListener(ImgFader.ON_LOAD_PROGRESS, __onLoadProgress)
__imgfader.addEventListener(ImgFader.ON_LOAD_COMPLETE, __onLoadComplete)
//__imgfader.onLoadStart = __onLoadStart;
//__imgfader.onLoadProgress = __onLoadProgress;
//__imgfader.onLoadComplete = __onLoadComplete;
isPaused = false;
mc = __imgfader.mc;
}
/*
* Começa (do inicio, primeira imagem)
* */
public function start():void{
indexImg = -1
__t1 = new Timer(__delay2, 1);
__t1.addEventListener(TimerEvent.TIMER, __carregaPrimeira);
__t2 = new Timer(__delay1, 0);
__t2.addEventListener(TimerEvent.TIMER, __timerProxima);
__t2.start()
__proxima();
}
/*
* Pausa avanço automatico
* */
public function pause():void {
Main.trace( "sld.pause : >" );
isPaused = true;
if (__t1) {
__t1.stop();
__t2.stop();
}
Main.trace( "sld.pause : <" );
}
/* Continua avanço automatico após pausa
* */
public function resume ():void {
__proxima();
__t2.start();
}
/*
* Remove tudo
* */
public function remove ():void {
Main.trace( "sld.remove : >" );
try {
pause();
} catch (e:Error){}
try {
__t1.removeEventListener(TimerEvent.TIMER, __carregaPrimeira);
__t2.removeEventListener(TimerEvent.TIMER, __timerProxima);
} catch (e:Error){}
try {
__imgfader.remove();
} catch (e:Error) { }
Main.trace( "sld.remove : <" );
}
public function proxima():void {
isLoading = true;
__t2.stop();
__t1.stop();
__t1.start(); //inicia delay longo
__interrompeFades()
__proxima();
}
public function anterior():void {
isLoading = true;
__t2.stop();
__t1.stop();
__t1.start(); //inicia delay longo
__interrompeFades()
__anterior();
}
/* interrompe os fades. é necessario quando o usuario troca as imagens rapidamente */
private function __interrompeFades():void{
TweenMax.killTweensOf(__imgfader.mcCarregado);
TweenMax.killTweensOf(__imgfader.mcVelho);
}
private function __onLoadStart(e:*=null):void {
percentLoaded = 0;
try {
onLoadStart();
} catch (e:Error){
}
}
private function __onLoadProgress(e:*=null):void {
percentLoaded = __imgfader.loadedPercent;
try {
onLoadProgress()
} catch (e:Error){
}
}
private function __onLoadComplete(e:*=null):void {
isLoading = false;
percentLoaded = 100;
/* fades */
var mc:MovieClip = __imgfader.mcCarregado;
mc.alpha = 0;
TweenMax.to(mc, 0.5, { alpha:1, delay:0.5 } );
mcAtual = mc;
var mcVelho:MovieClip = __imgfader.mcVelho;
TweenMax.to(mcVelho, 0.5, { alpha:0, delay:0, onComplete:__disparaOnComplete} );
/*
try {
onLoadComplete()
} catch (e:Error){
}
*/
}
private function __disparaOnComplete():void {
try {
onLoadComplete()
} catch (e:Error){
}
}
private function __timerProxima(e:TimerEvent):void {
// nao pode carregar outra se nao terminou de carregar a anterior
if (__imgfader.isLoading==false) {
__proxima();
} else {
//trace('esperando');
}
}
/* carrega a proxima imagem */
private function __proxima(e:*=null):void {
if(indexImg+1<__arr.length){
indexImg++;
} else{
indexImg=0
}
__imgfader.load(__arr[indexImg]);
}
/* carrega a imagem anterior */
private function __anterior():void {
if(indexImg-1>-1){
indexImg--;
} else{
indexImg=__arr.length-1
}
__imgfader.load(__arr[indexImg]);
}
/* carrega primeira imagem depois do delay inicial */
private function __carregaPrimeira(e:*):void {
__proxima();
__t1.stop();
__t2.start();
}
}
}