[cvs] / ossdk / InnerServiceRIAC / lib / V2Components / mx / video / UIManager.as Repository:
Cosoft CVS

Annotation of /ossdk/InnerServiceRIAC/lib/V2Components/mx/video/UIManager.as

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download)

1 : thiswind 1.1 //****************************************************************************
2 :     //Copyright (C) 2004-2005 Macromedia, Inc. All Rights Reserved.
3 :     //The following is Sample Code and is subject to all restrictions on
4 :     //such code as contained in the End User License Agreement accompanying
5 :     //this product.
6 :     //****************************************************************************
7 :    
8 :     import mx.utils.Delegate;
9 :     import mx.video.*;
10 :    
11 :     /**
12 :     * <p>Functions you can plugin to seek bar or volume bar with, to
13 :     * override std behavior: startHandleDrag(), stopHandleDrag(),
14 :     * positionHandle(), calcPercentageFromHandle(), positionBar().
15 :     * Return true to override standard behavior or return false to allow
16 :     * standard behavior to execute. These do not override default
17 :     * behavior, but allow you to add addl functionality:
18 :     * addBarControl()</p>
19 :     *
20 :     * <p>Functions you can use for swf based skin controls: layoutSelf()
21 :     * - called after control is laid out to do additional layout.
22 :     * Properties that can be set to customize layout: anchorLeft,
23 :     * anchorRight, anchorTop, anchorLeft.</p>
24 :     *
25 :     * <p>Possible seek bar and volume bar customization variables:
26 :     * handleLeftMargin, handleRightMargin, handleY, handle_mc,
27 :     * progressLeftMargin, progressRightMargin, progressY, progress_mc,
28 :     * fullnessLeftMargin, fullnessRightMargin, fullnessY, fullness_mc,
29 :     * percentage. These variables will also be set to defaults by
30 :     * UIManager if values are not passed in. Percentage is constantly
31 :     * updated, others will be set by UIManager in addBarControl or
32 :     * finishAddBarControl.</p>
33 :     *
34 :     * <p>These seek bar and volume bar customization variables do not
35 :     * work with external skin swfs and are not set if no value is passed
36 :     * in: handleLinkageID, handleBelow, progressLinkageID, progressBelow,
37 :     * fullnessLinkageID, fullnessBelow</p>
38 :     *
39 :     * <p>Note that in swf skins, handle_mc must have same parent as
40 :     * correpsonding bar. fullness_mc and progress_mc may be at the same
41 :     * level or nested, and either of those may have a fill_mc at the same
42 :     * level or nested. Note that if any of these nestable clips are
43 :     * nested, then they must be scaled at 100% on stage, because
44 :     * UIManager uses xscale and yscale to resize them and assumes 100% is
45 :     * the original size. If they are not scaled at 100% when placed on
46 :     * stage, weird stuff might happen.</p>
47 :     *
48 :     * <p>Variables set in seek bar and volume bar that can be used by
49 :     * custom methods, but should be treated as read only: isDragging,
50 :     * uiMgr, controlIndex. Also set on handle mc: controlIndex</p>
51 :     *
52 :     * <p>Note that when skinAutoHide is true, skin is hidden unless
53 :     * mouse if over visible VideoPlayer or over the skin. Over the
54 :     * skin is measured by hitTest on bg1_mc clip from the layout_mc.
55 :     * If there is no bg1_mc, then mouse over the skin doesn't make
56 :     * it visible (unless skin is completely over the video, of course.)</p>
57 :     */
58 :     class mx.video.UIManager {
59 :    
60 :     #include "ComponentVersion.as"
61 :    
62 :     static var PAUSE_BUTTON:Number = 0;
63 :     static var PLAY_BUTTON:Number = 1;
64 :     static var STOP_BUTTON:Number = 2;
65 :     static var SEEK_BAR_HANDLE:Number = 3;
66 :     static var BACK_BUTTON:Number = 4;
67 :     static var FORWARD_BUTTON:Number = 5;
68 :     static var MUTE_ON_BUTTON:Number = 6;
69 :     static var MUTE_OFF_BUTTON:Number = 7;
70 :     static var VOLUME_BAR_HANDLE:Number = 8;
71 :     static var NUM_BUTTONS:Number = 9;
72 :    
73 :     static var PLAY_PAUSE_BUTTON:Number = 9;
74 :     static var MUTE_BUTTON:Number = 10;
75 :     static var BUFFERING_BAR:Number = 11;
76 :     static var SEEK_BAR:Number = 12;
77 :     static var VOLUME_BAR:Number = 13;
78 :     static var NUM_CONTROLS:Number = 14;
79 :    
80 :     static var UP_STATE:Number = 0;
81 :     static var OVER_STATE:Number = 1;
82 :     static var DOWN_STATE:Number = 2;
83 :    
84 :     // controls
85 :     private var controls:Array;
86 :     private var customClips:Array; // bg1, bg2... and fg1, fg2... clips
87 :    
88 :     // for layout
89 :     private var skin_mc:MovieClip; // loaded skin swf
90 :     private var skinLoader:MovieClipLoader;
91 :     private var layout_mc:MovieClip; // layout_mc from the skin_mc
92 :     private var border_mc:MovieClip; // determines bounds of whether mouse is over skin for autohide
93 :     private var placeholderLeft:Number;
94 :     private var placeholderRight:Number;
95 :     private var placeholderTop:Number;
96 :     private var placeholderBottom:Number;
97 :     private var videoLeft:Number;
98 :     private var videoRight:Number;
99 :     private var videoTop:Number;
100 :     private var videoBottom:Number;
101 :    
102 :     // properties
103 :     private var _bufferingBarHides:Boolean;
104 :     private var _controlsEnabled:Boolean;
105 :     private var _skin:String;
106 :     private var _skinAutoHide:Boolean;
107 :     private var _skinReady:Boolean;
108 :     private var __visible:Boolean;
109 :     private var _seekBarInterval:Number;
110 :     private var _seekBarScrubTolerance:Number;
111 :    
112 :     // progress
113 :     private var _progressPercent:Number;
114 :    
115 :     //volume and mute
116 :     private var cachedSoundLevel:Number;
117 :     private var _lastVolumePos:Number;
118 :     private var _isMuted:Boolean;
119 :     private var _volumeBarInterval:Number;
120 :     private var _volumeBarIntervalID:Number;
121 :     private var _volumeBarScrubTolerance:Number;
122 :    
123 :     // my FLVPlayback
124 :     var _vc:FLVPlayback;
125 :    
126 :     // buffering
127 :     private var _bufferingDelayIntervalID:Number;
128 :     private var _bufferingDelayInterval:Number;
129 :     private var _bufferingOn:Boolean;
130 :    
131 :     // seeking
132 :     private var _seekBarIntervalID:Number;
133 :     private var _lastScrubPos:Number;
134 :     private var _playAfterScrub:Boolean;
135 :    
136 :     // skin autohide
137 :     private var _skinAutoHideIntervalID:Number;
138 :     private static var SKIN_AUTO_HIDE_INTERVAL:Number = 200;
139 :    
140 :     /**
141 :     * Default value of volumeBarInterval
142 :     *
143 :     * @see #volumeBarInterval
144 :     */
145 :     public static var VOLUME_BAR_INTERVAL_DEFAULT:Number = 250;
146 :    
147 :     /**
148 :     * Default value of volumeBarScrubTolerance.
149 :     *
150 :     * @see #volumeBarScrubTolerance
151 :     */
152 :     public static var VOLUME_BAR_SCRUB_TOLERANCE_DEFAULT:Number = 0;
153 :    
154 :     /**
155 :     * Default value of seekBarInterval
156 :     *
157 :     * @see #seekBarInterval
158 :     */
159 :     public static var SEEK_BAR_INTERVAL_DEFAULT:Number = 250;
160 :    
161 :     /**
162 :     * Default value of seekBarScrubTolerance.
163 :     *
164 :     * @see #seekBarScrubTolerance
165 :     */
166 :     public static var SEEK_BAR_SCRUB_TOLERANCE_DEFAULT:Number = 5;
167 :    
168 :     /**
169 :     * Default value of bufferingDelayInterval.
170 :     *
171 :     * @see #seekBarInterval
172 :     */
173 :     public static var BUFFERING_DELAY_INTERVAL_DEFAULT:Number = 1000;
174 :    
175 :     /**
176 :     * UIManager.
177 :     */
178 :     // todo: buffeirng ui changes delay for 1 sec
179 :     // todo: buffering disables play for bufferTime secs (-1 sec delay)
180 :     // todo: buffering goes from seekBar to buffering animation
181 :     public function UIManager(vc:FLVPlayback) {
182 :     // init properties
183 :     _vc = vc;
184 :     _skin = undefined;
185 :     _skinAutoHide = false;
186 :     _skinReady = true;
187 :     __visible = true;
188 :     _bufferingBarHides = false;
189 :     _controlsEnabled = true;
190 :     _lastScrubPos = 0;
191 :     _lastVolumePos = 0;
192 :     cachedSoundLevel = _vc.volume;
193 :     _isMuted = false;
194 :     controls = new Array();
195 :     customClips = undefined;
196 :     skin_mc = undefined;
197 :     skinLoader = undefined;
198 :     layout_mc = undefined;
199 :     border_mc = undefined;
200 :     _seekBarIntervalID = 0
201 :     _seekBarInterval = SEEK_BAR_INTERVAL_DEFAULT;
202 :     _seekBarScrubTolerance = SEEK_BAR_SCRUB_TOLERANCE_DEFAULT;
203 :     _volumeBarIntervalID = 0
204 :     _volumeBarInterval = VOLUME_BAR_INTERVAL_DEFAULT;
205 :     _volumeBarScrubTolerance = VOLUME_BAR_SCRUB_TOLERANCE_DEFAULT;
206 :     _bufferingDelayIntervalID = 0
207 :     _bufferingDelayInterval = BUFFERING_DELAY_INTERVAL_DEFAULT;
208 :     _bufferingOn = false;
209 :     _skinAutoHideIntervalID = 0;
210 :    
211 :     // listen to the VideoPlayer
212 :     _vc.addEventListener("metadataReceived", this);
213 :     _vc.addEventListener("playheadUpdate", this);
214 :     _vc.addEventListener("progress", this);
215 :     _vc.addEventListener("stateChange", this);
216 :     _vc.addEventListener("ready", this);
217 :     _vc.addEventListener("resize", this);
218 :     _vc.addEventListener("volumeUpdate", this);
219 :    
220 :     }
221 :    
222 :     public function handleEvent(e:Object):Void {
223 :     // UI only handles events from visible player, must set it to active
224 :     if (e.vp != undefined && e.vp != _vc.visibleVideoPlayerIndex) return;
225 :    
226 :     // set activeVideoPlayerIndex to visibleVideoPlayerIndex
227 :     var cachedActivePlayerIndex:Number = _vc.activeVideoPlayerIndex;
228 :     _vc.activeVideoPlayerIndex = _vc.visibleVideoPlayerIndex;
229 :    
230 :     //ifdef DEBUG
231 :     ////debugTrace("handleEvent :: " + e.type );
232 :     //endif
233 :     if (e.type == "stateChange") {
234 :     if (e.state == FLVPlayback.BUFFERING) {
235 :     if (!_bufferingOn) {
236 :     clearInterval(_bufferingDelayIntervalID);
237 :     _bufferingDelayIntervalID = setInterval(this, "doBufferingDelay", _bufferingDelayInterval);
238 :     }
239 :     } else {
240 :     clearInterval(_bufferingDelayIntervalID);
241 :     _bufferingDelayIntervalID = 0;
242 :     _bufferingOn = false;
243 :     }
244 :     if (e.state == FLVPlayback.LOADING) {
245 :     _progressPercent = (_vc.getVideoPlayer(e.vp).isRTMP) ? 100 : 0;
246 :     for (var i:Number = SEEK_BAR; i <= VOLUME_BAR; i++) {
247 :     var ctrl:MovieClip = controls[i];
248 :     if (ctrl.progress_mc != undefined) {
249 :     positionBar(ctrl, "progress", _progressPercent);
250 :     }
251 :     }
252 :     }
253 :     for (var i:Number = 0; i < NUM_CONTROLS; i++) {
254 :     if (controls[i] == undefined) continue;
255 :     setEnabledAndVisibleForState(i, e.state);
256 :     if (i < NUM_BUTTONS) skinButtonControl(controls[i]);
257 :     }
258 :     } else if (e.type == "ready" || e.type == "metadataReceived") {
259 :     for (var i:Number = 0; i < NUM_CONTROLS; i++) {
260 :     if (controls[i] == undefined) continue;
261 :     setEnabledAndVisibleForState(i, _vc.state);
262 :     if (i < NUM_BUTTONS) skinButtonControl(controls[i]);
263 :     }
264 :     if (_vc.getVideoPlayer(e.vp).isRTMP) {
265 :     _progressPercent = 100;
266 :     for (var i:Number = SEEK_BAR; i <= VOLUME_BAR; i++) {
267 :     var ctrl:MovieClip = controls[i];
268 :     if (ctrl.progress_mc != undefined) {
269 :     positionBar(ctrl, "progress", _progressPercent);
270 :     }
271 :     }
272 :     }
273 :     } else if (e.type == "resize") {
274 :     layoutSkin();
275 :     setupSkinAutoHide();
276 :     } else if (e.type == "volumeUpdate") {
277 :     if (_isMuted && e.volume > 0) {
278 :     _isMuted = false;
279 :     setEnabledAndVisibleForState(MUTE_OFF_BUTTON, FLVPlayback.PLAYING);
280 :     skinButtonControl(controls[MUTE_OFF_BUTTON]);
281 :     setEnabledAndVisibleForState(MUTE_ON_BUTTON, FLVPlayback.PLAYING);
282 :     skinButtonControl(controls[MUTE_ON_BUTTON]);
283 :     }
284 :     var volumeBar:MovieClip = controls[VOLUME_BAR];
285 :     volumeBar.percentage = (_isMuted) ? cachedSoundLevel : e.volume;
286 :     if (volumeBar.percentage < 0) {
287 :     volumeBar.percentage = 0;
288 :     } else if (volumeBar.percentage > 100) {
289 :     volumeBar.percentage = 100;
290 :     }
291 :     positionHandle(VOLUME_BAR);
292 :     } else if (e.type == "playheadUpdate" && controls[SEEK_BAR] != undefined) {
293 :     if (!_vc.isLive && _vc.totalTime > 0) {
294 :     var percentage:Number = e.playheadTime / _vc.totalTime * 100;
295 :     if (percentage < 0) {
296 :     percentage = 0;
297 :     } else if (percentage > 100) {
298 :     percentage = 100;
299 :     }
300 :     var seekBar:MovieClip = controls[SEEK_BAR];
301 :     seekBar.percentage = percentage;
302 :     positionHandle(SEEK_BAR);
303 :     }
304 :     } else if (e.type == "progress") {
305 :     _progressPercent = (e.bytesTotal <= 0) ? 100 : (e.bytesLoaded / e.bytesTotal * 100);
306 :     var minProgressPercent:Number = _vc._vpState[e.vp].minProgressPercent;
307 :     if (!isNaN(minProgressPercent) && minProgressPercent > _progressPercent) {
308 :     _progressPercent = minProgressPercent;
309 :     }
310 :     if (_vc.totalTime > 0) {
311 :     var playheadPercent:Number = _vc.playheadTime / _vc.totalTime * 100;
312 :     if (playheadPercent > _progressPercent) {
313 :     _progressPercent = playheadPercent;
314 :     _vc._vpState[e.vp].minProgressPercent = _progressPercent;
315 :     }
316 :     }
317 :     for (var i:Number = SEEK_BAR; i <= VOLUME_BAR; i++) {
318 :     var ctrl:MovieClip = controls[i];
319 :     if (ctrl.progress_mc != undefined) {
320 :     positionBar(ctrl, "progress", _progressPercent);
321 :     }
322 :     }
323 :     }
324 :    
325 :     // set activeVideoPlayerIndex back to prev value
326 :     _vc.activeVideoPlayerIndex = cachedActivePlayerIndex;
327 :     }
328 :    
329 :     /**
330 :     * <p>If true, we hide and disable certain controls when the
331 :     * buffering bar is displayed. The seek bar will be hidden, the
332 :     * play, pause, play/pause, forward and back buttons would be
333 :     * disabled. Default is false. This only has effect if there
334 :     * is a buffering bar control.</p>
335 :     */
336 :     public function get bufferingBarHidesAndDisablesOthers():Boolean {
337 :     return _bufferingBarHides;
338 :     }
339 :     public function set bufferingBarHidesAndDisablesOthers(b:Boolean):Void {
340 :     _bufferingBarHides = b;
341 :     }
342 :    
343 :     public function get controlsEnabled():Boolean {
344 :     return _controlsEnabled;
345 :     }
346 :     public function set controlsEnabled(flag:Boolean):Void {
347 :     if (_controlsEnabled == flag) return;
348 :     _controlsEnabled = flag;
349 :     for (var i:Number = 0; i < NUM_BUTTONS; i++) {
350 :     if (controls[i] == undefined) continue;
351 :     controls[i].releaseCapture();
352 :     controls[i].enabled = (_controlsEnabled && controls[i].myEnabled);
353 :     skinButtonControl(controls[i]);
354 :     }
355 :     }
356 :    
357 :     public function get skin():String {
358 :     return _skin;
359 :     }
360 :     public function set skin(s:String) {
361 :     if (s == _skin) return;
362 :     if (_skin != undefined) {
363 :     removeSkin();
364 :     }
365 :     _skin = s;
366 :     _skinReady = (_skin == undefined || _skin == null || _skin == "");
367 :     if (!_skinReady) {
368 :     downloadSkin();
369 :     }
370 :     }
371 :    
372 :     public function get skinAutoHide():Boolean {
373 :     return _skinAutoHide;
374 :     }
375 :     public function set skinAutoHide(b:Boolean) {
376 :     if (b == _skinAutoHide) return;
377 :     _skinAutoHide = b;
378 :     setupSkinAutoHide();
379 :     }
380 :    
381 :     public function get skinReady():Boolean {
382 :     return _skinReady;
383 :     }
384 :    
385 :     /**
386 :     * Determines how often check the seek bar handle location when
387 :     * scubbing, in milliseconds. Default is 250.
388 :     *
389 :     * @see #SEEK_BAR_INTERVAL_DEFAULT
390 :     */
391 :     public function get seekBarInterval():Number {
392 :     return _seekBarInterval;
393 :     }
394 :     public function set seekBarInterval(s:Number) {
395 :     if (_seekBarInterval == s) return;
396 :     _seekBarInterval = s;
397 :     if (_seekBarIntervalID > 0) {
398 :     clearInterval(_seekBarIntervalID);
399 :     _seekBarIntervalID = setInterval(this, "seekBarListener", _seekBarInterval, false);
400 :     }
401 :     }
402 :    
403 :     /**
404 :     * Determines how often check the volume bar handle location when
405 :     * scubbing, in milliseconds. Default is 250.
406 :     *
407 :     * @see #VOLUME_BAR_INTERVAL_DEFAULT
408 :     */
409 :     public function get volumeBarInterval():Number {
410 :     return _volumeBarInterval;
411 :     }
412 :     public function set volumeBarInterval(s:Number) {
413 :     if (_volumeBarInterval == s) return;
414 :     _volumeBarInterval = s;
415 :     if (_volumeBarIntervalID > 0) {
416 :     clearInterval(_volumeBarIntervalID);
417 :     _volumeBarIntervalID = setInterval(this, "volumeBarListener", _volumeBarInterval, false);
418 :     }
419 :     }
420 :    
421 :     /**
422 :     * Determines how long after FLVPlayback.BUFFERING state entered
423 :     * we disable controls for buffering. This delay is put into
424 :     * place to avoid annoying rapid switching between states.
425 :     * Default is 1000.
426 :     *
427 :     * @see #BUFFERING_DELAY_INTERVAL_DEFAULT
428 :     */
429 :     public function get bufferingDelayInterval():Number {
430 :     return _bufferingDelayInterval;
431 :     }
432 :     public function set bufferingDelayInterval(s:Number) {
433 :     if (_bufferingDelayInterval == s) return;
434 :     _bufferingDelayInterval = s;
435 :     if (_bufferingDelayIntervalID > 0) {
436 :     clearInterval(_bufferingDelayIntervalID);
437 :     _bufferingDelayIntervalID = setInterval(this, "doBufferingDelay", _bufferingDelayIntervalID);
438 :     }
439 :     }
440 :    
441 :     /**
442 :     * <p>Determines how far user can move scrub bar before an update
443 :     * will occur. Specified in percentage from 1 to 100. Set to 0
444 :     * to indicate no scrub tolerance--always update volume on
445 :     * volumeBarInterval regardless of how far user has moved handle.
446 :     * Default is 0.</p>
447 :     *
448 :     * @see #VOLUME_BAR_SCRUB_TOLERANCE_DEFAULT
449 :     */
450 :     public function get volumeBarScrubTolerance():Number {
451 :     return _volumeBarScrubTolerance;
452 :     }
453 :     public function set volumeBarScrubTolerance(s:Number) {
454 :     _volumeBarScrubTolerance = s;
455 :     }
456 :    
457 :    
458 :     /**
459 :     * <p>Determines how far user can move scrub bar before an update
460 :     * will occur. Specified in percentage from 1 to 100. Set to 0
461 :     * to indicate no scrub tolerance--always update position on
462 :     * seekBarInterval regardless of how far user has moved handle.
463 :     * Default is 5.</p>
464 :     *
465 :     * @see #SEEK_BAR_SCRUB_TOLERANCE_DEFAULT
466 :     */
467 :     public function get seekBarScrubTolerance():Number {
468 :     return _seekBarScrubTolerance;
469 :     }
470 :     public function set seekBarScrubTolerance(s:Number) {
471 :     _seekBarScrubTolerance = s;
472 :     }
473 :    
474 :     /**
475 :     * whether or not skin swf controls
476 :     * should be shown or hidden
477 :     */
478 :     public function get visible():Boolean {
479 :     return __visible;
480 :     }
481 :     public function set visible(v:Boolean) {
482 :     if (__visible == v) return;
483 :     __visible = v;
484 :     if (!__visible) {
485 :     skin_mc._visible = false;
486 :     } else {
487 :     setupSkinAutoHide();
488 :     }
489 :     }
490 :    
491 :     function getControl(index:Number):MovieClip {
492 :     return controls[index];
493 :     }
494 :    
495 :     function setControl(index:Number, s:MovieClip) {
496 :     // do nothing if the same
497 :     if (s == null) s = undefined;
498 :     if (s == controls[index]) return;
499 :    
500 :     // for some controls, extra stuff we do to keep connections correct
501 :     switch (index) {
502 :     case PAUSE_BUTTON:
503 :     case PLAY_BUTTON:
504 :     resetPlayPause();
505 :     break;
506 :     case PLAY_PAUSE_BUTTON:
507 :     if (s._parent != layout_mc) {
508 :     resetPlayPause();
509 :     setControl(PAUSE_BUTTON, s.pause_mc);
510 :     setControl(PLAY_BUTTON, s.play_mc);
511 :     }
512 :     break;
513 :     case MUTE_BUTTON:
514 :     if (s._parent != layout_mc) {
515 :     setControl(MUTE_ON_BUTTON, s.on_mc);
516 :     setControl(MUTE_OFF_BUTTON, s.off_mc);
517 :     }
518 :     break;
519 :    
520 :     } // switch
521 :    
522 :     if (index >= NUM_BUTTONS) {
523 :     controls[index] = s;
524 :     switch (index) {
525 :     case SEEK_BAR:
526 :     addBarControl(SEEK_BAR);
527 :     break;
528 :     case VOLUME_BAR:
529 :     addBarControl(VOLUME_BAR);
530 :     controls[VOLUME_BAR].percentage = _vc.volume;
531 :     break;
532 :     case BUFFERING_BAR:
533 :     controls[BUFFERING_BAR].uiMgr = this;
534 :     controls[BUFFERING_BAR].controlIndex = BUFFERING_BAR;
535 :     // do right away if from loaded swf, wait to give time for
536 :     // initialization if control defined in this swf
537 :     if (controls[BUFFERING_BAR]._parent == skin_mc) {
538 :     finishAddBufferingBar();
539 :     } else {
540 :     controls[BUFFERING_BAR].onEnterFrame = function() {
541 :     this.uiMgr.finishAddBufferingBar();
542 :     }
543 :     }
544 :     break;
545 :     } // switch
546 :     setEnabledAndVisibleForState(index, _vc.state);
547 :     } else {
548 :     removeButtonControl(index);
549 :     controls[index] = s;
550 :     addButtonControl(index);
551 :     }
552 :     }
553 :    
554 :     private function resetPlayPause():Void {
555 :     if (controls[PLAY_PAUSE_BUTTON] == undefined) return;
556 :     for (var i:Number = PAUSE_BUTTON; i <= PLAY_BUTTON; i++) {
557 :     removeButtonControl(i);
558 :     }
559 :     controls[PLAY_PAUSE_BUTTON] = undefined;
560 :     }
561 :    
562 :     private function addButtonControl(index:Number):Void {
563 :     var ctrl:MovieClip = controls[index];
564 :     if (ctrl == undefined) return;
565 :    
566 :     // set activeVideoPlayerIndex to visibleVideoPlayerIndex
567 :     var cachedActivePlayerIndex:Number = _vc.activeVideoPlayerIndex;
568 :     _vc.activeVideoPlayerIndex = _vc.visibleVideoPlayerIndex;
569 :    
570 :     ctrl.id = index;
571 :     ctrl.state = UP_STATE;
572 :     ctrl.uiMgr = this;
573 :     setEnabledAndVisibleForState(index, _vc.state);
574 :     ctrl.onRollOver = function() {
575 :     this.state = UIManager.OVER_STATE;
576 :     this.uiMgr.skinButtonControl(this);
577 :     }
578 :     ctrl.onRollOut = function() {
579 :     this.state = UIManager.UP_STATE;
580 :     this.uiMgr.skinButtonControl(this);
581 :     }
582 :    
583 :     if (index == SEEK_BAR_HANDLE || index == VOLUME_BAR_HANDLE ) {
584 :     ctrl.onPress = function() {
585 :     if (_root.focusManager) {
586 :     this._focusrect = false;
587 :     Selection.setFocus(this);
588 :     }
589 :     this.state = UIManager.DOWN_STATE;
590 :     this.uiMgr.dispatchMessage(this);
591 :     this.uiMgr.skinButtonControl(this);
592 :     }
593 :     ctrl.onRelease = function() {
594 :     this.state = UIManager.OVER_STATE;
595 :     this.uiMgr.handleRelease(this.controlIndex);
596 :     this.uiMgr.skinButtonControl(this);
597 :     }
598 :     ctrl.onReleaseOutside = function() {
599 :     this.state = UIManager.UP_STATE;
600 :     this.uiMgr.handleRelease(this.controlIndex);
601 :     this.uiMgr.skinButtonControl(this);
602 :     }
603 :     } else {
604 :     ctrl.onPress = function() {
605 :     if (_root.focusManager) {
606 :     this._focusrect = false;
607 :     Selection.setFocus(this);
608 :     }
609 :     this.state = UIManager.DOWN_STATE;
610 :     this.uiMgr.skinButtonControl(this);
611 :     }
612 :     ctrl.onRelease = function() {
613 :     this.state = UIManager.OVER_STATE;
614 :     this.uiMgr.dispatchMessage(this);
615 :     this.uiMgr.skinButtonControl(this);
616 :     }
617 :     ctrl.onReleaseOutside = function() {
618 :     this.state = UIManager.UP_STATE;
619 :     this.uiMgr.skinButtonControl(this);
620 :     }
621 :     }
622 :    
623 :    
624 :     // do right away if from loaded swf, wait to give time for
625 :     // initialization if control defined in this swf
626 :     if (ctrl._parent == skin_mc) {
627 :     skinButtonControl(ctrl);
628 :     } else {
629 :     ctrl.onEnterFrame = function() {
630 :     this.uiMgr.skinButtonControl(this);
631 :     }
632 :     }
633 :    
634 :     // set activeVideoPlayerIndex back to prev value
635 :     _vc.activeVideoPlayerIndex = cachedActivePlayerIndex;
636 :     }
637 :    
638 :     private function removeButtonControl(index:Number):Void {
639 :     if (controls[index] == undefined) return;
640 :     controls[index].uiMgr = undefined;
641 :     controls[index].onRollOver = undefined;
642 :     controls[index].onRollOut = undefined;
643 :     controls[index].onPress = undefined;
644 :     controls[index].onRelease = undefined;
645 :     controls[index].onReleaseOutside = undefined;
646 :     controls[index] = undefined;
647 :     }
648 :    
649 :     /**
650 :     * start download of skin swf, called when skin property set.
651 :     *
652 :     * @private
653 :     */
654 :     private function downloadSkin():Void {
655 :     if (skinLoader == undefined) {
656 :     skinLoader = new MovieClipLoader();
657 :     skinLoader.addListener(this);
658 :     }
659 :     if (skin_mc == undefined) {
660 :     skin_mc = _vc.createEmptyMovieClip("skin_mc", _vc.getNextHighestDepth());
661 :     }
662 :     skin_mc._visible = false;
663 :     skin_mc._x = Stage.width + 100;
664 :     skin_mc._y = Stage.height + 100;
665 :     skinLoader.loadClip(_skin, skin_mc);
666 :     }
667 :    
668 :     /**
669 :     * MovieClipLoader event handler function
670 :     */
671 :     private function onLoadError(target_mc:MovieClip, errorCode:String):Void {
672 :     _skinReady = true;
673 :     _vc.skinError("Unable to load skin swf");
674 :     }
675 :    
676 :     /**
677 :     * MovieClipLoader event handler function
678 :     */
679 :     private function onLoadInit():Void {
680 :     try {
681 :     skin_mc._visible = false;
682 :     skin_mc._x = 0;
683 :     skin_mc._y = 0;
684 :     // get layout_mc from skin swf. This defines the layout
685 :     layout_mc = skin_mc.layout_mc;
686 :     if (layout_mc == undefined) throw new Error("No layout_mc");
687 :     layout_mc._visible = false;
688 :    
689 :     // load any custom background clips
690 :     customClips = new Array();
691 :     setCustomClips("bg");
692 :    
693 :     // load all the controls
694 :     if (layout_mc.playpause_mc != undefined) {
695 :     setSkin(PLAY_PAUSE_BUTTON, layout_mc.playpause_mc);
696 :     } else {
697 :     setSkin(PAUSE_BUTTON, layout_mc.pause_mc);
698 :     setSkin(PLAY_BUTTON, layout_mc.play_mc);
699 :     }
700 :     setSkin(STOP_BUTTON, layout_mc.stop_mc);
701 :     setSkin(BACK_BUTTON, layout_mc.back_mc);
702 :     setSkin(FORWARD_BUTTON, layout_mc.forward_mc);
703 :     setSkin(MUTE_BUTTON, layout_mc.volumeMute_mc);
704 :     setSkin(SEEK_BAR, layout_mc.seekBar_mc);
705 :     setSkin(VOLUME_BAR, layout_mc.volumeBar_mc);
706 :     setSkin(BUFFERING_BAR, layout_mc.bufferingBar_mc);
707 :    
708 :     // load any custom foreground clips
709 :     setCustomClips("fg");
710 :    
711 :     // layout all the clips and controls
712 :     layoutSkin();
713 :     setupSkinAutoHide();
714 :     skin_mc._visible = __visible;
715 :    
716 :     _skinReady = true;
717 :     _vc.skinLoaded();
718 :    
719 :     // set activeVideoPlayerIndex to visibleVideoPlayerIndex
720 :     var cachedActivePlayerIndex:Number = _vc.activeVideoPlayerIndex;
721 :     _vc.activeVideoPlayerIndex = _vc.visibleVideoPlayerIndex;
722 :    
723 :     // set enabledness for current state
724 :     var state:String = _vc.state;
725 :     for (var i:Number = 0; i < NUM_CONTROLS; i++) {
726 :     if (controls[i] == undefined) continue;
727 :     setEnabledAndVisibleForState(i, state);
728 :     if (i < NUM_BUTTONS) skinButtonControl(controls[i]);
729 :     }
730 :    
731 :     // set activeVideoPlayerIndex back to prev value
732 :     _vc.activeVideoPlayerIndex = cachedActivePlayerIndex;
733 :    
734 :     } catch (err:Error) {
735 :     _vc.skinError(err.message);
736 :     removeSkin();
737 :     }
738 :     }
739 :    
740 :     /**
741 :     * layout all controls from loaded swf
742 :     *
743 :     * @private
744 :     */
745 :     // todo: figure out errors...
746 :     function layoutSkin():Void {
747 :     if (layout_mc == undefined) return;
748 :     // get bounds of placeholder
749 :     var video_mc:MovieClip = layout_mc.video_mc;
750 :     if (video_mc == undefined) throw new Error("No layout_mc.video_mc");
751 :     placeholderLeft = video_mc._x;
752 :     placeholderRight = video_mc._x + video_mc._width;
753 :     placeholderTop = video_mc._y;
754 :     placeholderBottom = video_mc._y + video_mc._height;
755 :    
756 :     // get bounds of real video
757 :     videoLeft = 0;
758 :     videoRight = _vc.width;
759 :     videoTop = 0;
760 :     videoBottom = _vc.height;
761 :    
762 :     // do not go below min dimensions
763 :     if (!isNaN(layout_mc.minWidth) && layout_mc.minWidth > 0 && layout_mc.minWidth > videoRight) {
764 :     videoLeft -= ((layout_mc.minWidth - videoRight) / 2);
765 :     videoRight = layout_mc.minWidth + videoLeft;
766 :     }
767 :     if (!isNaN(layout_mc.minHeight) && layout_mc.minHeight > 0 && layout_mc.minHeight > videoBottom) {
768 :     videoTop -= ((layout_mc.minHeight - videoBottom) / 2);
769 :     videoBottom = layout_mc.minHeight + videoTop;
770 :     }
771 :    
772 :     // iterate over customClips
773 :     var i:Number;
774 :     for (i = 0; i < customClips.length; i++) {
775 :     layoutControl(customClips[i]);
776 :     }
777 :     // iterate over controls
778 :     for (i = 0; i < NUM_CONTROLS; i++) {
779 :     layoutControl(controls[i]);
780 :     }
781 :     }
782 :    
783 :     /**
784 :     * layout individual control from loaded swf
785 :     *
786 :     * @private
787 :     */
788 :     private function layoutControl(ctrl:MovieClip):Void {
789 :     if (ctrl == undefined) return;
790 :     if (ctrl.skin.anchorRight) {
791 :     if (ctrl.skin.anchorLeft) {
792 :     ctrl._x = ctrl.skin._x - placeholderLeft + videoLeft;
793 :     ctrl._width = ctrl.skin._x + ctrl.skin._width - placeholderRight + videoRight - ctrl._x;
794 :     if (ctrl.origWidth != undefined) ctrl.origWidth = undefined;
795 :     } else {
796 :     ctrl._x = ctrl.skin._x - placeholderRight + videoRight;
797 :     }
798 :     } else {
799 :     ctrl._x = ctrl.skin._x - placeholderLeft + videoLeft;
800 :     }
801 :     if (ctrl.skin.anchorTop) {
802 :     if (ctrl.skin.anchorBottom) {
803 :     ctrl._y = ctrl.skin._y - placeholderTop + videoTop;
804 :     ctrl._height = ctrl.skin._y + ctrl.skin._height - placeholderBottom + videoBottom - ctrl._y;
805 :     if (ctrl.origHeight != undefined) ctrl.origHeight = undefined;
806 :    
807 :     } else {
808 :     ctrl._y = ctrl.skin._y - placeholderTop + videoTop;
809 :     }
810 :     } else {
811 :     ctrl._y = ctrl.skin._y - placeholderBottom + videoBottom;
812 :     }
813 :    
814 :     switch (ctrl.controlIndex) {
815 :     case SEEK_BAR:
816 :     case VOLUME_BAR:
817 :     if (ctrl.progress_mc != undefined) {
818 :     if (_progressPercent == undefined) {
819 :     _progressPercent = (_vc.isRTMP ? 100 : 0);
820 :     }
821 :     positionBar(ctrl, "progress", _progressPercent);
822 :     }
823 :     positionHandle(ctrl.controlIndex);
824 :     break;
825 :     case BUFFERING_BAR:
826 :     if (ctrl.fill_mc != undefined) {
827 :     positionMaskedFill(ctrl, ctrl.fill_mc, 100);
828 :     }
829 :     break;
830 :     }
831 :    
832 :     // optional callback
833 :     if (ctrl.layoutSelf != undefined) ctrl.layoutSelf();
834 :     }
835 :    
836 :     /**
837 :     * remove controls from prev skin swf
838 :     *
839 :     * @private
840 :     */
841 :     private function removeSkin():Void {
842 :     if (skin_mc != undefined) {
843 :     for (var i:Number = 0; i < NUM_BUTTONS; i++) {
844 :     removeButtonControl(i);
845 :     }
846 :     for (var i:Number = NUM_BUTTONS; i < NUM_CONTROLS; i++) {
847 :     controls[i] = undefined;
848 :     }
849 :     skin_mc.unloadMovie();
850 :     layout_mc = undefined;
851 :     border_mc = undefined;
852 :     }
853 :     }
854 :    
855 :     /**
856 :     * set custom clip from loaded swf
857 :     *
858 :     * @private
859 :     */
860 :     private function setCustomClips(prefix:String):Void {
861 :     var i:Number = 1;
862 :     while (true) {
863 :     var clip:MovieClip = layout_mc[prefix + i++ + "_mc"];
864 :     if (clip == undefined) break;
865 :     var ctrl:MovieClip = clip.mc;
866 :     // default is movie clip with same instance name at root
867 :     if (ctrl == undefined) ctrl = clip._parent._parent[clip._name];
868 :     if (ctrl == undefined) throw new Error("Bad clip in skin: " + clip);
869 :     ctrl.skin = clip;
870 :     customClips.push(ctrl);
871 :    
872 :     // take bg1 for border_mc
873 :     if (prefix == "bg" && i == 2) {
874 :     border_mc = ctrl;
875 :     }
876 :     }
877 :     }
878 :    
879 :     /**
880 :     * set skin clip from loaded swf
881 :     *
882 :     * @private
883 :     */
884 :     private function setSkin(index:Number, s:MovieClip):Void {
885 :    
886 :     if (s == undefined) return;
887 :     var ctrl:MovieClip = s.mc;
888 :     if (ctrl == undefined) ctrl = s._parent._parent[s._name];
889 :     if (ctrl == undefined) throw new Error("Bad clip in skin: " + s);
890 :    
891 :     ctrl.skin = s;
892 :    
893 :     if (index < NUM_BUTTONS) {
894 :     setupSkinStates(ctrl);
895 :     } else {
896 :     switch (index) {
897 :     case PLAY_PAUSE_BUTTON:
898 :     setupSkinStates(ctrl.play_mc)
899 :     setupSkinStates(ctrl.pause_mc)
900 :     break;
901 :     case MUTE_BUTTON:
902 :     setupSkinStates(ctrl.on_mc)
903 :     setupSkinStates(ctrl.off_mc)
904 :     break;
905 :     case SEEK_BAR:
906 :     case VOLUME_BAR:
907 :     var type:String = (index == SEEK_BAR) ? "seekBar" : "volumeBar";
908 :     if (ctrl.handle_mc == undefined) {
909 :     ctrl.handle_mc = ctrl.skin.seekBarHandle_mc;
910 :     if (ctrl.handle_mc == undefined) {
911 :     ctrl.handle_mc = ctrl.skin._parent._parent[type + "Handle_mc"];
912 :     }
913 :     }
914 :     if (ctrl.progress_mc == undefined) {
915 :     ctrl.progress_mc = ctrl.skin.progress_mc;
916 :     if (ctrl.progress_mc == undefined) {
917 :     ctrl.progress_mc = ctrl.skin._parent._parent[type + "Progress_mc"];
918 :     }
919 :     }
920 :     if (ctrl.fullness_mc == undefined) {
921 :     ctrl.fullness_mc = ctrl.skin.fullness_mc;
922 :     if (ctrl.fullness_mc == undefined) {
923 :     ctrl.fullness_mc = ctrl.skin._parent._parent[type + "Fullness_mc"];
924 :     }
925 :     }
926 :     break;
927 :     case BUFFERING_BAR:
928 :     if (ctrl.fill_mc == undefined) {
929 :     ctrl.fill_mc = ctrl.skin.fill_mc;
930 :     if (ctrl.fill_mc == undefined) {
931 :     ctrl.fill_mc = ctrl.skin._parent._parent.bufferingBarFill_mc;
932 :     }
933 :     }
934 :     break;
935 :     }
936 :     }
937 :     setControl(index, ctrl);
938 :     }
939 :     /**
940 :     * will layout the contnents of a toggle buton - for debugging - this is temporary will roll into setSkin
941 :     *
942 :     * @private
943 :     */
944 :     private function setupSkinStates(ctrl:MovieClip):Void {
945 :     // if no up_mc, then we have no states at all
946 :     if (ctrl.up_mc == undefined) {
947 :     ctrl.up_mc = ctrl;
948 :     ctrl.over_mc = ctrl;
949 :     ctrl.down_mc = ctrl;
950 :     ctrl.disabled_mc = ctrl;
951 :     } else {
952 :     ctrl._x = 0;
953 :     ctrl._y = 0;
954 :     ctrl.up_mc._x = 0;
955 :     ctrl.up_mc._y = 0;
956 :     ctrl.up_mc._visible = true;
957 :     if (ctrl.over_mc == undefined) {
958 :     ctrl.over_mc = ctrl.up_mc;
959 :     } else {
960 :     ctrl.over_mc._x = 0;
961 :     ctrl.over_mc._y = 0;
962 :     ctrl.over_mc._visible = false;
963 :     }
964 :     if (ctrl.down_mc == undefined) {
965 :     ctrl.down_mc = ctrl.up_mc;
966 :     } else {
967 :     ctrl.down_mc._x = 0;
968 :     ctrl.down_mc._y = 0;
969 :     ctrl.down_mc._visible = false;
970 :     }
971 :     if (ctrl.disabled_mc == undefined) {
972 :     ctrl.disabled_mc_mc = ctrl.up_mc;
973 :     } else {
974 :     ctrl.disabled_mc._x = 0;
975 :     ctrl.disabled_mc._y = 0;
976 :     ctrl.disabled_mc._visible = false;
977 :     }
978 :     }
979 :     }
980 :    
981 :     /**
982 :     * skin button
983 :     *
984 :     * @private
985 :     */
986 :     private function skinButtonControl(ctrl:MovieClip):Void {
987 :     if (ctrl.onEnterFrame != undefined) {
988 :     delete ctrl.onEnterFrame;
989 :     ctrl.onEnterFrame = undefined;
990 :     }
991 :     if (ctrl.enabled) {
992 :     switch (ctrl.state) {
993 :     case UP_STATE:
994 :     if (ctrl.up_mc == undefined) {
995 :     ctrl.up_mc = ctrl.attachMovie(ctrl.upLinkageID, "up_mc", ctrl.getNextHighestDepth());
996 :     }
997 :     applySkinState(ctrl, ctrl.up_mc);
998 :     break;
999 :     case OVER_STATE:
1000 :     if (ctrl.over_mc == undefined) {
1001 :     if (ctrl.overLinkageID == undefined) {
1002 :     ctrl.over_mc = ctrl.up_mc;
1003 :     } else {
1004 :     ctrl.over_mc = ctrl.attachMovie(ctrl.overLinkageID, "over_mc", ctrl.getNextHighestDepth());
1005 :     }
1006 :     }
1007 :     applySkinState(ctrl, ctrl.over_mc);
1008 :     break;
1009 :     case DOWN_STATE:
1010 :     if (ctrl.down_mc == undefined) {
1011 :     if (ctrl.downLinkageID == undefined) {
1012 :     ctrl.down_mc = ctrl.up_mc;
1013 :     } else {
1014 :     ctrl.down_mc = ctrl.attachMovie(ctrl.downLinkageID, "down_mc", ctrl.getNextHighestDepth());
1015 :     }
1016 :     }
1017 :     applySkinState(ctrl, ctrl.down_mc);
1018 :     break;
1019 :     } // switch
1020 :     } else {
1021 :     ctrl.state = UP_STATE;
1022 :     if (ctrl.disabled_mc == undefined) {
1023 :     if (ctrl.disabledLinkageID == undefined) {
1024 :     ctrl.disabled_mc = ctrl.up_mc;
1025 :     } else {
1026 :     ctrl.disabled_mc = ctrl.attachMovie(ctrl.disabledLinkageID, "disabled_mc", ctrl.getNextHighestDepth());
1027 :     }
1028 :     }
1029 :     applySkinState(ctrl, ctrl.disabled_mc);
1030 :     }
1031 :     if (ctrl.placeholder_mc != undefined) {
1032 :     ctrl.placeholder_mc.unloadMovie();
1033 :     delete ctrl.placeholder_mc;
1034 :     ctrl.placeholder_mc = undefined;
1035 :     }
1036 :     }
1037 :    
1038 :     /**
1039 :     * helper to skin button
1040 :     *
1041 :     * @private
1042 :     */
1043 :     private function applySkinState(ctrl:MovieClip, state:MovieClip):Void {
1044 :     if (state != ctrl.currentState_mc) {
1045 :     if (state != undefined) state._visible = true;
1046 :     if (ctrl.currentState_mc != undefined) ctrl.currentState_mc._visible = false;
1047 :     ctrl.currentState_mc = state;
1048 :     }
1049 :     }
1050 :    
1051 :     /**
1052 :     * adds seek bar or volume bar
1053 :     *
1054 :     * @private
1055 :     */
1056 :     private function addBarControl(controlIndex:Number):Void {
1057 :     var ctrl:MovieClip = controls[controlIndex];
1058 :    
1059 :     // init vars
1060 :     ctrl.isDragging = false;
1061 :     ctrl.percentage = 0;
1062 :     ctrl.uiMgr = this;
1063 :     ctrl.controlIndex = controlIndex;
1064 :    
1065 :     // do right away if from loaded swf, wait to give time for
1066 :     // initialization if control defined in this swf
1067 :     if (ctrl._parent == skin_mc) {
1068 :     finishAddBarControl(controlIndex);
1069 :     } else {
1070 :     ctrl.onEnterFrame = function() {
1071 :     this.uiMgr.finishAddBarControl(this.controlIndex);
1072 :     }
1073 :     }
1074 :     }
1075 :    
1076 :     /**
1077 :     * finish adding seek bar or volume bar onEnterFrame to allow for
1078 :     * initialization to complete
1079 :     *
1080 :     * @private
1081 :     */
1082 :     private function finishAddBarControl(controlIndex:Number) {
1083 :     var ctrl:MovieClip = controls[controlIndex];
1084 :    
1085 :     // ditch the onEnterFrame
1086 :     delete ctrl.onEnterFrame;
1087 :     ctrl.onEnterFrame = undefined;
1088 :    
1089 :     // opportunity for custom init code
1090 :     if (ctrl.addBarControl != undefined) {
1091 :     ctrl.addBarControl();
1092 :     }
1093 :    
1094 :     // set the margins
1095 :     calcBarMargins(ctrl, "handle", true);
1096 :     calcBarMargins(ctrl, "progress", false);
1097 :     calcBarMargins(ctrl.progress_mc, "fill", false);
1098 :     calcBarMargins(ctrl.progress_mc, "mask", false);
1099 :     calcBarMargins(ctrl, "fullness", false);
1100 :     calcBarMargins(ctrl.fullness_mc, "fill", false);
1101 :     calcBarMargins(ctrl.fullness_mc, "mask", false);
1102 :    
1103 :     // save orig width and height, used for bars that are not
1104 :     // scaled. If they are scaled in layoutControl, we will
1105 :     // set this to undefined so it will be ignored.
1106 :     ctrl.origWidth = ctrl._width;
1107 :     ctrl.origHeight = ctrl._height;
1108 :    
1109 :     // fix up and position the progress bar
1110 :     fixUpBar(ctrl, "progress");
1111 :     if (ctrl.progress_mc != undefined) {
1112 :     fixUpBar(ctrl, "progressBarFill");
1113 :     if (_progressPercent == undefined) {
1114 :     _progressPercent = (_vc.isRTMP ? 100 : 0);
1115 :     }
1116 :     positionBar(ctrl, "progress", _progressPercent);
1117 :     }
1118 :    
1119 :     // fix up the fullness bar, positioned by positionHandle
1120 :     fixUpBar(ctrl, "fullness");
1121 :     if (ctrl.fullness_mc != undefined) {
1122 :     fixUpBar(ctrl, "fullnessBarFill");
1123 :     }
1124 :    
1125 :     // fix up and position the handle
1126 :     fixUpBar(ctrl, "handle");
1127 :     ctrl.handle_mc.controlIndex = controlIndex;
1128 :     switch (controlIndex) {
1129 :     case SEEK_BAR:
1130 :     setControl(SEEK_BAR_HANDLE, ctrl.handle_mc);
1131 :     break;
1132 :     case VOLUME_BAR:
1133 :     setControl(VOLUME_BAR_HANDLE, ctrl.handle_mc);
1134 :     break;
1135 :     } // switch
1136 :     positionHandle(controlIndex);
1137 :     }
1138 :    
1139 :     /**
1140 :     * Fix up progres or fullness bar
1141 :     *
1142 :     * @private
1143 :     */
1144 :     private function fixUpBar(ctrl:MovieClip, type:String):Void {
1145 :     if (ctrl[type + "LinkageID"] != undefined && ctrl[type + "LinkageID"].length > 0) {
1146 :     var depth:Number;
1147 :     if (ctrl[type + "Below"]) {
1148 :     depth = -1;
1149 :     while (ctrl._parent.getInstanceAtDepth(depth) != undefined) {
1150 :     depth--;
1151 :     }
1152 :     } else {
1153 :     ctrl[type + "Below"] = false;
1154 :     depth = ctrl._parent.getNextHighestDepth();
1155 :     }
1156 :     ctrl[type + "_mc"] = ctrl._parent.attachMovie(ctrl[type + "LinkageID"], type + "_mc", depth);
1157 :     }
1158 :     }
1159 :    
1160 :     /**
1161 :     * Gets left and right margins for progress or fullness
1162 :     *
1163 :     * @private
1164 :     */
1165 :     private function calcBarMargins(ctrl:MovieClip, type:String, symmetricMargins:Boolean):Void {
1166 :     //ifdef DEBUG
1167 :     //debugTrace("calcBarMargins(" + ctrl + ", " + type + ", " + symmetricMargins + ")");
1168 :     //endif
1169 :     var bar:MovieClip = ctrl[type + "_mc"];
1170 :     if (bar == undefined) return;
1171 :    
1172 :     if (ctrl[type + "LeftMargin"] == undefined && bar._parent == ctrl._parent) {
1173 :     ctrl[type + "LeftMargin"] = bar._x - ctrl._x;
1174 :     }
1175 :    
1176 :     if (ctrl[type + "RightMargin"] == undefined) {
1177 :     if (symmetricMargins) {
1178 :     ctrl[type + "RightMargin"] = ctrl[type + "LeftMargin"];
1179 :     } else if (bar._parent == ctrl._parent) {
1180 :     ctrl[type + "RightMargin"] = ctrl._width - bar._width - bar._x + ctrl._x;
1181 :     }
1182 :     }
1183 :    
1184 :     if (ctrl[type + "TopMargin"] == undefined && bar._parent == ctrl._parent) {
1185 :     ctrl[type + "TopMargin"] = bar._y - ctrl._y;
1186 :     }
1187 :    
1188 :     if (ctrl[type + "BottomMargin"] == undefined) {
1189 :     if (symmetricMargins) {
1190 :     ctrl[type + "BottomMargin"] = ctrl[type + "TopMargin"];
1191 :     } else if (bar._parent == ctrl._parent) {
1192 :     ctrl[type + "BottomMargin"] = ctrl._height - bar._height - bar._y + ctrl._y;
1193 :     }
1194 :     }
1195 :    
1196 :     if (ctrl[type + "X"] == undefined) {
1197 :     if (bar._parent == ctrl._parent) {
1198 :     ctrl[type + "X"] = bar._x - ctrl._x;
1199 :     } else if (bar._parent == ctrl) {
1200 :     ctrl[type + "X"] = bar._x;
1201 :     }
1202 :     }
1203 :    
1204 :     if (ctrl[type + "Y"] == undefined) {
1205 :     if (bar._parent == ctrl._parent) {
1206 :     ctrl[type + "Y"] = bar._y - ctrl._y;
1207 :     } else if (bar._parent == ctrl) {
1208 :     ctrl[type + "Y"] = bar._y;
1209 :     }
1210 :     }
1211 :    
1212 :     // grab the orig values
1213 :     ctrl[type + "XScale"] = bar._xscale;
1214 :     ctrl[type + "YScale"] = bar._yscale;
1215 :     ctrl[type + "Width"] = bar._width;
1216 :     ctrl[type + "Height"] = bar._height;
1217 :    
1218 :     //ifdef DEBUG
1219 :     //debugTrace(type + "LeftMargin = " + ctrl[type + "LeftMargin"]);
1220 :     //debugTrace(type + "RightMargin = " + ctrl[type + "RightMargin"]);
1221 :     //debugTrace(type + "TopMargin = " + ctrl[type + "TopMargin"]);
1222 :     //debugTrace(type + "BottomMargin = " + ctrl[type + "BottomMargin"]);
1223 :     //debugTrace(type + "X = " + ctrl[type + "X"]);
1224 :     //debugTrace(type + "Y = " + ctrl[type + "Y"]);
1225 :     //debugTrace(type + "XScale = " + ctrl[type + "XScale"]);
1226 :     //debugTrace(type + "YScale = " + ctrl[type + "YScale"]);
1227 :     //debugTrace(type + "Width = " + ctrl[type + "Width"]);
1228 :     //debugTrace(type + "Height = " + ctrl[type + "Height"]);
1229 :     //endif
1230 :     }
1231 :    
1232 :     /**
1233 :     * finish adding buffer bar onEnterFrame to allow for initialization to complete
1234 :     *
1235 :     * @private
1236 :     */
1237 :     private function finishAddBufferingBar() {
1238 :     var bufferingBar:MovieClip = controls[BUFFERING_BAR];
1239 :    
1240 :     // ditch the onEnterFrame
1241 :     delete bufferingBar.onEnterFrame;
1242 :     bufferingBar.onEnterFrame = undefined;
1243 :    
1244 :     // set the margins
1245 :     calcBarMargins(bufferingBar, "fill", true);
1246 :    
1247 :     // fix up the fill
1248 :     fixUpBar(bufferingBar, "fill");
1249 :    
1250 :     // position the fill
1251 :     if (bufferingBar.fill_mc != undefined) {
1252 :     positionMaskedFill(bufferingBar, bufferingBar.fill_mc, 100);
1253 :     }
1254 :     }
1255 :    
1256 :     /**
1257 :     * Place the buffering pattern and mask over the buffering bar
1258 :     * @private
1259 :     */
1260 :     private function positionMaskedFill(ctrl:MovieClip, fill:MovieClip, percent:Number):Void {
1261 :     // create mask if necessary
1262 :     var theParent:MovieClip = fill._parent;
1263 :     var mask:MovieClip = ctrl.mask_mc;
1264 :     if (mask == undefined) {
1265 :     mask = theParent.createEmptyMovieClip(ctrl._name + "Mask_mc", theParent.getNextHighestDepth());
1266 :     ctrl.mask_mc = mask;
1267 :     mask.beginFill(0xffffff);
1268 :     mask.lineTo(0,0);
1269 :     mask.lineTo(1,0);
1270 :     mask.lineTo(1,1);
1271 :     mask.lineTo(0,1);
1272 :     mask.lineTo(0,0);
1273 :     mask.endFill();
1274 :     fill.setMask(mask);
1275 :     mask._x = ctrl.fillX;
1276 :     mask._y = ctrl.fillY;
1277 :     mask._width = ctrl.fillWidth;
1278 :     mask._height = ctrl.fillHeight;
1279 :     mask._visible = false;
1280 :     calcBarMargins(ctrl, "mask", true);
1281 :     }
1282 :    
1283 :     if (theParent == ctrl) {
1284 :     if (fill.slideReveal) {
1285 :     // slide fill, mask stays put
1286 :     fill._x = ctrl.maskX - ctrl.fillWidth + (ctrl.fillWidth * percent / 100);
1287 :     } else {
1288 :     // resize mask
1289 :     mask._width = ctrl.fillWidth * percent / 100;
1290 :     }
1291 :     } else if (theParent == ctrl._parent) {
1292 :     // in neither of these cases do we ever scale the fill_mc, we just scale the mask
1293 :     // and move the fill_mc around, so for skin swf case will usually make sense to
1294 :     // make a very long fill_mc that will always be long enough
1295 :     if (fill.slideReveal) {
1296 :     // place and size mask
1297 :     mask._x = ctrl._x + ctrl.maskLeftMargin
1298 :     mask._y = ctrl._y + ctrl.maskTopMargin;
1299 :     mask._width = ctrl._width - ctrl.maskRightMargin - ctrl.maskLeftMargin;
1300 :     mask._height = ctrl._height - ctrl.maskTopMargin - ctrl.maskBottomMargin;
1301 :    
1302 :     // put fill in correct place
1303 :     fill._x = mask._x - ctrl.fillWidth + (ctrl.maskWidth * percent / 100);
1304 :     fill._y = ctrl._y + ctrl.fillTopMargin;
1305 :     } else {
1306 :     // put fill in correct place, do not scale
1307 :     fill._x = ctrl._x + ctrl.fillLeftMargin;
1308 :     fill._y = ctrl._y + ctrl.fillTopMargin;
1309 :    
1310 :     // place mask
1311 :     mask._x = fill._x;
1312 :     mask._y = fill._y;
1313 :     mask._width = (ctrl._width - ctrl.fillRightMargin - ctrl.fillLeftMargin) * percent / 100;
1314 :     mask._height = ctrl._height - ctrl.fillTopMargin - ctrl.fillBottomMargin;
1315 :     }
1316 :     }
1317 :     }
1318 :    
1319 :     /**
1320 :     * Default startHandleDrag function (can be defined on seek bar
1321 :     * movie clip instance) to handle start dragging the seek bar
1322 :     * handle or volume bar handle.
1323 :     *
1324 :     * @private
1325 :     */
1326 :     private function startHandleDrag(controlIndex:Number):Void {
1327 :     //ifdef DEBUG
1328 :     //debugTrace("startHandleDrag()");
1329 :     //endif
1330 :     var ctrl:MovieClip = controls[controlIndex];
1331 :     var handle:MovieClip = ctrl.handle_mc;
1332 :    
1333 :     // call custom implementation instead, if available
1334 :     if (ctrl.startHandleDrag == undefined || !ctrl.startHandleDrag()) {
1335 :     // calc constriction coords and start drag
1336 :     var theY = ctrl._y + ctrl.handleY;
1337 :     var theWidth = (ctrl.origWidth == undefined) ? ctrl._width : ctrl.origWidth;
1338 :     handle.startDrag( false,
1339 :     ctrl._x + ctrl.handleLeftMargin,
1340 :     theY,
1341 :     ctrl._x + theWidth - ctrl.handleRightMargin,
1342 :     theY );
1343 :     }
1344 :     ctrl.isDragging = true;
1345 :     }
1346 :    
1347 :     /**
1348 :     * Default stopHandleDrag function (can be defined on seek bar
1349 :     * movie clip instance) to handle stop dragging the seek bar
1350 :     * handle or volume bar handle.
1351 :     *
1352 :     * @private
1353 :     */
1354 :     private function stopHandleDrag(controlIndex:Number):Void {
1355 :     //ifdef DEBUG
1356 :     //debugTrace("stopHandleDrag()");
1357 :     //endif
1358 :     var ctrl:MovieClip = controls[controlIndex];
1359 :     var handle:MovieClip = ctrl.handle_mc;
1360 :    
1361 :     // call custom implementation instead, if available
1362 :     if (ctrl.stopHandleDrag == undefined || !ctrl.stopHandleDrag()) {
1363 :     // stop drag
1364 :     handle.stopDrag();
1365 :     }
1366 :    
1367 :     ctrl.isDragging = false;
1368 :     }
1369 :    
1370 :     /**
1371 :     * Default positionHandle function (can be defined on seek bar
1372 :     * movie clip instance) to handle positioning seek bar handle.
1373 :     *
1374 :     * @private
1375 :     */
1376 :     private function positionHandle(controlIndex:Number):Void {
1377 :     var ctrl:MovieClip = controls[controlIndex];
1378 :     var handle:MovieClip = ctrl.handle_mc;
1379 :     if (handle == undefined) return;
1380 :    
1381 :     // call custom implementation instead, if available
1382 :     if (ctrl.positionHandle != undefined && ctrl.positionHandle()) {
1383 :     return;
1384 :     }
1385 :    
1386 :     var theWidth = (ctrl.origWidth == undefined) ? ctrl._width : ctrl.origWidth;
1387 :     var handleSpanLength:Number = theWidth - ctrl.handleRightMargin - ctrl.handleLeftMargin;
1388 :     handle._x = ctrl._x + ctrl.handleLeftMargin + (handleSpanLength * ctrl.percentage / 100);
1389 :     handle._y = ctrl._y + ctrl.handleY;
1390 :    
1391 :     // set fullness mask clip if there is one
1392 :     if (ctrl.fullness_mc != undefined) {
1393 :     positionBar(ctrl, "fullness", ctrl.percentage);
1394 :     }
1395 :     }
1396 :    
1397 :     /**
1398 :     * helper for other positioning funcs
1399 :     *
1400 :     * @private
1401 :     */
1402 :     private function positionBar(ctrl:MovieClip, type:String, percent:Number):Void {
1403 :     if (ctrl.positionBar != undefined && ctrl.positionBar(type, percent)) {
1404 :     return;
1405 :     }
1406 :     var bar:MovieClip = ctrl[type + "_mc"];
1407 :     if (bar._parent == ctrl) {
1408 :     // don't move me, just scale me relative to myself, since
1409 :     // I'm already scaled with the parent clip
1410 :     if (bar.fill_mc == undefined) {
1411 :     bar._xscale = ctrl[type + "XScale"] * percent / 100;
1412 :     } else {
1413 :     positionMaskedFill(bar, bar.fill_mc, percent);
1414 :     }
1415 :     } else {
1416 :     // assume I'm at the same level of the parent clip, so
1417 :     // move and scale to match, taking margins and y pos into
1418 :     // account
1419 :     bar._x = ctrl._x + ctrl[type + "LeftMargin"];
1420 :     bar._y = ctrl._y + ctrl[type + "Y"];
1421 :     if (bar.fill_mc == undefined) {
1422 :     bar._width = (ctrl._width - ctrl[type + "LeftMargin"] - ctrl[type + "RightMargin"]) * percent / 100;
1423 :     } else {
1424 :     positionMaskedFill(bar, bar.fill_mc, percent);
1425 :     }
1426 :     }
1427 :     }
1428 :    
1429 :     /**
1430 :     * Default calcPercentageFromHandle function (can be defined on
1431 :     * seek bar movie clip instance) to handle calculating percentage
1432 :     * from seek bar handle position.
1433 :     *
1434 :     * @private
1435 :     */
1436 :     private function calcPercentageFromHandle(controlIndex:Number):Void {
1437 :     var ctrl:MovieClip = controls[controlIndex];
1438 :     var handle:MovieClip = ctrl.handle_mc;
1439 :    
1440 :     // call custom implementation instead, if available
1441 :     if (ctrl.calcPercentageFromHandle == undefined || !ctrl.calcPercentageFromHandle()) {
1442 :     var theWidth = (ctrl.origWidth == undefined) ? ctrl._width : ctrl.origWidth;
1443 :     var handleSpanLength:Number = theWidth - ctrl.handleRightMargin - ctrl.handleLeftMargin;
1444 :     var handleLoc:Number = handle._x - (ctrl._x + ctrl.handleLeftMargin);
1445 :     ctrl.percentage = handleLoc / handleSpanLength * 100;
1446 :    
1447 :     // set fullness mask clip if there is one
1448 :     if (ctrl.fullness_mc != undefined) {
1449 :     positionBar(ctrl, "fullness", ctrl.percentage);
1450 :     }
1451 :     }
1452 :    
1453 :     // sanity
1454 :     if (ctrl.percentage < 0) ctrl.percentage = 0;
1455 :     if (ctrl.percentage > 100) ctrl.percentage = 100;
1456 :     }
1457 :    
1458 :     /**
1459 :     * Called to signal end of seek bar scrub. Call from
1460 :     * onRelease and onReleaseOutside event listeners.
1461 :     *
1462 :     * @private
1463 :     */
1464 :     private function handleRelease(controlIndex:Number):Void {
1465 :     //ifdef DEBUG
1466 :     //debugTrace("handleRelease()");
1467 :     //endif
1468 :    
1469 :     // set activeVideoPlayerIndex to visibleVideoPlayerIndex
1470 :     var cachedActivePlayerIndex:Number = _vc.activeVideoPlayerIndex;
1471 :     _vc.activeVideoPlayerIndex = _vc.visibleVideoPlayerIndex;
1472 :    
1473 :     if (controlIndex == SEEK_BAR) {
1474 :     seekBarListener(true);
1475 :     } else if (controlIndex == VOLUME_BAR) {
1476 :     volumeBarListener(true);
1477 :     }
1478 :     stopHandleDrag(controlIndex);
1479 :    
1480 :     // set activeVideoPlayerIndex back to prev value
1481 :     _vc.activeVideoPlayerIndex = cachedActivePlayerIndex;
1482 :    
1483 :     if (controlIndex == SEEK_BAR) {
1484 :     _vc._scrubFinish();
1485 :     }
1486 :     }
1487 :    
1488 :     /**
1489 :     * Called on interval when user scrubbing by dragging seekbar handle.
1490 :     *
1491 :     * @private
1492 :     */
1493 :     function seekBarListener(finish:Boolean):Void {
1494 :     // set activeVideoPlayerIndex to visibleVideoPlayerIndex
1495 :     var cachedActivePlayerIndex:Number = _vc.activeVideoPlayerIndex;
1496 :     _vc.activeVideoPlayerIndex = _vc.visibleVideoPlayerIndex;
1497 :    
1498 :     var seekBar:MovieClip = controls[SEEK_BAR];
1499 :     calcPercentageFromHandle(SEEK_BAR);
1500 :     var scrubPos:Number = seekBar.percentage;
1501 :     if (finish) {
1502 :     clearInterval(_seekBarIntervalID);
1503 :     _seekBarIntervalID = 0;
1504 :     if (scrubPos != _lastScrubPos) {
1505 :     _vc.seekPercent(scrubPos);
1506 :     }
1507 :     _vc.addEventListener("playheadUpdate", this);
1508 :     if (_playAfterScrub) {
1509 :     _vc.play();
1510 :     }
1511 :     } else if (_vc.getVideoPlayer(_vc.visibleVideoPlayerIndex).state == VideoPlayer.SEEKING) {
1512 :     // do nothing
1513 :     } else if ( _seekBarScrubTolerance <= 0 ||
1514 :     Math.abs(scrubPos - _lastScrubPos) > _seekBarScrubTolerance ||
1515 :     scrubPos < _seekBarScrubTolerance ||
1516 :     scrubPos > (100 - _seekBarScrubTolerance) ) {
1517 :     if (scrubPos != _lastScrubPos) {
1518 :     _lastScrubPos = scrubPos;
1519 :     _vc.seekPercent(scrubPos);
1520 :     }
1521 :     }
1522 :    
1523 :     // set activeVideoPlayerIndex back to prev value
1524 :     _vc.activeVideoPlayerIndex = cachedActivePlayerIndex;
1525 :     }
1526 :    
1527 :     /**
1528 :     * Called on interval when user scrubbing by dragging volumebar handle.
1529 :     *
1530 :     * @private
1531 :     */
1532 :     function volumeBarListener(finish:Boolean):Void {
1533 :     var volumeBar:MovieClip = controls[VOLUME_BAR];
1534 :     calcPercentageFromHandle(VOLUME_BAR);
1535 :     var volumePos:Number = volumeBar.percentage;
1536 :     if (finish) {
1537 :     clearInterval(_volumeBarIntervalID);
1538 :     _volumeBarIntervalID = 0;
1539 :     _vc.addEventListener("volumeUpdate", this);
1540 :     }
1541 :     if ( finish || _volumeBarScrubTolerance <= 0 ||
1542 :     Math.abs(volumePos - _lastVolumePos) > _volumeBarScrubTolerance ||
1543 :     volumePos < _volumeBarScrubTolerance ||
1544 :     volumePos > (100 - _volumeBarScrubTolerance) ) {
1545 :     if (volumePos != _lastVolumePos) {
1546 :     if (_isMuted) {
1547 :     cachedSoundLevel = volumePos;
1548 :     } else {
1549 :     _vc.volume = volumePos;
1550 :     }
1551 :     }
1552 :     }
1553 :     }
1554 :    
1555 :     /**
1556 :     * Called on interval do delay entering buffering state.
1557 :     *
1558 :     * @private
1559 :     */
1560 :     function doBufferingDelay():Void {
1561 :     // set activeVideoPlayerIndex to visibleVideoPlayerIndex
1562 :     clearInterval(_bufferingDelayIntervalID);
1563 :     _bufferingDelayIntervalID = 0;
1564 :    
1565 :     // set activeVideoPlayerIndex to visibleVideoPlayerIndex
1566 :     var cachedActivePlayerIndex:Number = _vc.activeVideoPlayerIndex;
1567 :     _vc.activeVideoPlayerIndex = _vc.visibleVideoPlayerIndex;
1568 :    
1569 :     if (_vc.state == FLVPlayback.BUFFERING) {
1570 :     _bufferingOn = true;
1571 :     handleEvent({type:"stateChange", state:FLVPlayback.BUFFERING, vp:_vc.visibleVideoPlayerIndex});
1572 :     }
1573 :    
1574 :     // set activeVideoPlayerIndex back to prev value
1575 :     _vc.activeVideoPlayerIndex = cachedActivePlayerIndex;
1576 :     }
1577 :    
1578 :     function dispatchMessage(ctrl:MovieClip):Void {
1579 :     if (ctrl.id == SEEK_BAR_HANDLE) {
1580 :     _vc._scrubStart();
1581 :     }
1582 :    
1583 :     // set activeVideoPlayerIndex to visibleVideoPlayerIndex
1584 :     var cachedActivePlayerIndex:Number = _vc.activeVideoPlayerIndex;
1585 :     _vc.activeVideoPlayerIndex = _vc.visibleVideoPlayerIndex;
1586 :    
1587 :     switch (ctrl.id) {
1588 :     case PAUSE_BUTTON:
1589 :     _vc.pause();
1590 :     break;
1591 :     case PLAY_BUTTON:
1592 :     _vc.play();
1593 :     break;
1594 :     case STOP_BUTTON:
1595 :     _vc.stop();
1596 :     break;
1597 :     case SEEK_BAR_HANDLE:
1598 :     calcPercentageFromHandle(SEEK_BAR);
1599 :     _lastScrubPos = controls[SEEK_BAR].percentage;
1600 :     _vc.removeEventListener("playheadUpdate", this);
1601 :     if (_vc.playing || _vc.buffering) {
1602 :     _playAfterScrub = true;
1603 :     } else if (_vc.state != VideoPlayer.SEEKING) {
1604 :     _playAfterScrub = false;
1605 :     }
1606 :     _seekBarIntervalID = setInterval(this, "seekBarListener", _seekBarInterval, false);
1607 :     startHandleDrag(SEEK_BAR, SEEK_BAR_HANDLE);
1608 :     _vc.pause();
1609 :     break;
1610 :     case VOLUME_BAR_HANDLE:
1611 :     calcPercentageFromHandle(VOLUME_BAR);
1612 :     _lastVolumePos = controls[VOLUME_BAR].percentage;
1613 :     _vc.removeEventListener("volumeUpdate", this);
1614 :     _volumeBarIntervalID = setInterval(this, "volumeBarListener", _volumeBarInterval, false);
1615 :     startHandleDrag(VOLUME_BAR, VOLUME_BAR_HANDLE);
1616 :     break;
1617 :     case BACK_BUTTON:
1618 :     _vc.seekToPrevNavCuePoint();
1619 :     break;
1620 :     case FORWARD_BUTTON:
1621 :     _vc.seekToNextNavCuePoint();
1622 :     break;
1623 :     case MUTE_ON_BUTTON:
1624 :     case MUTE_OFF_BUTTON:
1625 :     if (!_isMuted) {
1626 :     _isMuted = true;
1627 :     cachedSoundLevel = _vc.volume;
1628 :     _vc.volume = 0;
1629 :     } else {
1630 :     _isMuted = false;
1631 :     _vc.volume = cachedSoundLevel;
1632 :     }
1633 :     setEnabledAndVisibleForState(MUTE_OFF_BUTTON, FLVPlayback.PLAYING);
1634 :     skinButtonControl(controls[MUTE_OFF_BUTTON]);
1635 :     setEnabledAndVisibleForState(MUTE_ON_BUTTON, FLVPlayback.PLAYING);
1636 :     skinButtonControl(controls[MUTE_ON_BUTTON]);
1637 :     break;
1638 :     default:
1639 :     throw new Error("Unknown ButtonControl");
1640 :     } // switch
1641 :    
1642 :     // set activeVideoPlayerIndex back to prev value
1643 :     _vc.activeVideoPlayerIndex = cachedActivePlayerIndex;
1644 :     }
1645 :    
1646 :     private function setEnabledAndVisibleForState(index:Number, state:String):Void {
1647 :     // set activeVideoPlayerIndex to visibleVideoPlayerIndex
1648 :     var cachedActivePlayerIndex:Number = _vc.activeVideoPlayerIndex;
1649 :     _vc.activeVideoPlayerIndex = _vc.visibleVideoPlayerIndex;
1650 :    
1651 :     // use effectiveState because BUFFERING has this
1652 :     // doBufferingDelay() thing going on
1653 :     var effectiveState:String = state;
1654 :     if (effectiveState == FLVPlayback.BUFFERING && !_bufferingOn) {
1655 :     effectiveState = FLVPlayback.PLAYING;
1656 :     }
1657 :    
1658 :     switch (index) {
1659 :     case VOLUME_BAR:
1660 :     case VOLUME_BAR_HANDLE:
1661 :     // always enabled
1662 :     controls[index].myEnabled = true;
1663 :     controls[index].enabled = _controlsEnabled;
1664 :     break;
1665 :     case MUTE_ON_BUTTON:
1666 :     controls[index].myEnabled = !_isMuted;
1667 :     if (controls[MUTE_BUTTON] != undefined) {
1668 :     controls[index]._visible = controls[index].myEnabled;
1669 :     }
1670 :     break;
1671 :     case MUTE_OFF_BUTTON:
1672 :     controls[index].myEnabled = _isMuted;
1673 :     if (controls[MUTE_BUTTON] != undefined) {
1674 :     controls[index]._visible = controls[index].myEnabled;
1675 :     }
1676 :     break;
1677 :     default:
1678 :     switch (effectiveState) {
1679 :     case FLVPlayback.LOADING:
1680 :     case FLVPlayback.CONNECTION_ERROR:
1681 :     controls[index].myEnabled = false;
1682 :     break;
1683 :     case FLVPlayback.DISCONNECTED:
1684 :     controls[index].myEnabled = (_vc.contentPath != undefined);
1685 :     break;
1686 :     case FLVPlayback.SEEKING:
1687 :     // no change
1688 :     break;
1689 :     default:
1690 :     controls[index].myEnabled = true;
1691 :     break;
1692 :     } // switch
1693 :     break;
1694 :     } // switch
1695 :    
1696 :     switch (index) {
1697 :     case SEEK_BAR:
1698 :     // set enabled
1699 :     switch (effectiveState) {
1700 :     case FLVPlayback.STOPPED:
1701 :     case FLVPlayback.PLAYING:
1702 :     case FLVPlayback.PAUSED:
1703 :     case FLVPlayback.REWINDING:
1704 :     case FLVPlayback.SEEKING:
1705 :     controls[index].myEnabled = true;
1706 :     break;
1707 :     case FLVPlayback.BUFFERING:
1708 :     controls[index].myEnabled = (!_bufferingBarHides || controls[BUFFERING_BAR] == undefined);
1709 :     break;
1710 :     default:
1711 :     controls[index].myEnabled = false;
1712 :     break;
1713 :     } // switch
1714 :     if (controls[index].myEnabled) {
1715 :     controls[index].myEnabled = (!isNaN(_vc.totalTime) && _vc.totalTime > 0);
1716 :     }
1717 :    
1718 :     // set handle enabled and visible
1719 :     controls[index].handle_mc.myEnabled = controls[index].myEnabled;
1720 :     controls[index].handle_mc.enabled = controls[index].handle_mc.myEnabled;
1721 :     controls[index].handle_mc._visible = controls[index].myEnabled;
1722 :    
1723 :     // hide when buffer bar active
1724 :     var vis:Boolean = ( !_bufferingBarHides || controls[index].myEnabled || controls[BUFFERING_BAR] == undefined || !controls[BUFFERING_BAR]._visible );
1725 :     controls[index]._visible = vis;
1726 :     controls[index].progress_mc._visible = vis;
1727 :     controls[index].progress_mc.fill_mc._visible = vis;
1728 :     controls[index].fullness_mc._visible = vis;
1729 :     controls[index].progress_mc.fill_mc._visible = vis;
1730 :     break;
1731 :     case BUFFERING_BAR:
1732 :     // set enabled
1733 :     switch (effectiveState) {
1734 :     case FLVPlayback.STOPPED:
1735 :     case FLVPlayback.PLAYING:
1736 :     case FLVPlayback.PAUSED:
1737 :     case FLVPlayback.REWINDING:
1738 :     case FLVPlayback.SEEKING:
1739 :     controls[index].myEnabled = false;
1740 :     break;
1741 :     default:
1742 :     controls[index].myEnabled = true;
1743 :     break;
1744 :     } // switch
1745 :    
1746 :     // set visible
1747 :     controls[index]._visible = controls[index].myEnabled;
1748 :     controls[index].fill_mc._visible = controls[index].myEnabled;
1749 :     break;
1750 :     case PAUSE_BUTTON:
1751 :     switch (effectiveState) {
1752 :     case FLVPlayback.DISCONNECTED:
1753 :     case FLVPlayback.STOPPED:
1754 :     case FLVPlayback.PAUSED:
1755 :     case FLVPlayback.REWINDING:
1756 :     controls[index].myEnabled = false;
1757 :     break;
1758 :     case FLVPlayback.PLAYING:
1759 :     controls[index].myEnabled = true;
1760 :     break;
1761 :     case FLVPlayback.BUFFERING:
1762 :     controls[index].myEnabled = (!_bufferingBarHides || controls[BUFFERING_BAR] == undefined);
1763 :     break;
1764 :     } // switch
1765 :     if (controls[PLAY_PAUSE_BUTTON] != undefined) {
1766 :     controls[index]._visible = controls[index].myEnabled;
1767 :     }
1768 :     break;
1769 :     case PLAY_BUTTON:
1770 :     switch (effectiveState) {
1771 :     case FLVPlayback.PLAYING:
1772 :     controls[index].myEnabled = false;
1773 :     break;
1774 :     case FLVPlayback.STOPPED:
1775 :     case FLVPlayback.PAUSED:
1776 :     controls[index].myEnabled = true;
1777 :     break;
1778 :     case FLVPlayback.BUFFERING:
1779 :     controls[index].myEnabled = (!_bufferingBarHides || controls[BUFFERING_BAR] == undefined);
1780 :     break;
1781 :     } // switch
1782 :     if (controls[PLAY_PAUSE_BUTTON] != undefined) {
1783 :     controls[index]._visible = !controls[PAUSE_BUTTON]._visible;
1784 :     }
1785 :     break;
1786 :     case STOP_BUTTON:
1787 :     switch (effectiveState) {
1788 :     case FLVPlayback.DISCONNECTED:
1789 :     case FLVPlayback.STOPPED:
1790 :     controls[index].myEnabled = false;
1791 :     break;
1792 :     case FLVPlayback.PAUSED:
1793 :     case FLVPlayback.PLAYING:
1794 :     case FLVPlayback.BUFFERING:
1795 :     controls[index].myEnabled = true;
1796 :     break;
1797 :     } // switch
1798 :     break;
1799 :     case BACK_BUTTON:
1800 :     case FORWARD_BUTTON:
1801 :     switch (effectiveState) {
1802 :     case FLVPlayback.BUFFERING:
1803 :     controls[index].myEnabled = (!_bufferingBarHides || controls[BUFFERING_BAR] == undefined);
1804 :     break;
1805 :     }
1806 :     } // switch index
1807 :    
1808 :     controls[index].enabled = (_controlsEnabled && controls[index].myEnabled);
1809 :    
1810 :     // set activeVideoPlayerIndex back to prev value
1811 :     _vc.activeVideoPlayerIndex = cachedActivePlayerIndex;
1812 :     }
1813 :    
1814 :     function setupSkinAutoHide():Void {
1815 :     var visibleVP:VideoPlayer = _vc.getVideoPlayer(_vc.visibleVideoPlayerIndex);
1816 :     if (_skinAutoHide && skin_mc != undefined) {
1817 :     // set visibility
1818 :     skinAutoHideHitTest();
1819 :     // setup interval
1820 :     if (_skinAutoHideIntervalID == 0) {
1821 :     _skinAutoHideIntervalID = setInterval(this, "skinAutoHideHitTest", SKIN_AUTO_HIDE_INTERVAL);
1822 :     }
1823 :     } else {
1824 :     // set visibility
1825 :     skin_mc._visible = __visible;
1826 :     // setup interval
1827 :     clearInterval(_skinAutoHideIntervalID);
1828 :     _skinAutoHideIntervalID = 0;
1829 :     }
1830 :     }
1831 :    
1832 :     private function skinAutoHideHitTest():Void {
1833 :     if (!__visible) {
1834 :     skin_mc._visible = false;
1835 :     } else {
1836 :     var visibleVP:VideoPlayer = _vc.getVideoPlayer(_vc.visibleVideoPlayerIndex);
1837 :     var hit:Boolean = visibleVP.hitTest(_root._xmouse, _root._ymouse, true);
1838 :     if (!hit && border_mc != undefined) {
1839 :     hit = border_mc.hitTest(_root._xmouse, _root._ymouse, true);
1840 :     }
1841 :     skin_mc._visible = hit;
1842 :     }
1843 :     }
1844 :    
1845 :     //ifdef DEBUG
1846 :     //function debugTrace(s:String):Void {
1847 :     // if (_vc != null && _vc != undefined) {
1848 :     // _vc.debugTrace(s);
1849 :     // }
1850 :     //}
1851 :     //endif
1852 :    
1853 :     } // class mx.video.UIManager

cvs-admin
ViewVC Help
Powered by ViewVC 1.0.0