source: trunk/fl5/src/com/longtailvideo/jwplayer/view/components/PlaylistComponent.as @ 1022

Revision 1022, 27.9 KB checked in by pablo, 3 years ago (diff)
  • Playlist over state / transparency bug (915)
  • Only colorize playlist using v4 colors (frontcolor, activecolor, etc)
  • 'display.backgroundcolor' setting was not being respected.
Line 
1package com.longtailvideo.jwplayer.view.components {
2        import com.longtailvideo.jwplayer.events.PlayerStateEvent;
3        import com.longtailvideo.jwplayer.events.PlaylistEvent;
4        import com.longtailvideo.jwplayer.events.ViewEvent;
5        import com.longtailvideo.jwplayer.model.Color;
6        import com.longtailvideo.jwplayer.model.PlaylistItem;
7        import com.longtailvideo.jwplayer.player.IPlayer;
8        import com.longtailvideo.jwplayer.player.PlayerState;
9        import com.longtailvideo.jwplayer.utils.Draw;
10        import com.longtailvideo.jwplayer.utils.Logger;
11        import com.longtailvideo.jwplayer.utils.RootReference;
12        import com.longtailvideo.jwplayer.utils.Stacker;
13        import com.longtailvideo.jwplayer.utils.Stretcher;
14        import com.longtailvideo.jwplayer.utils.Strings;
15        import com.longtailvideo.jwplayer.view.PlayerLayoutManager;
16        import com.longtailvideo.jwplayer.view.interfaces.IPlaylistComponent;
17        import com.longtailvideo.jwplayer.view.interfaces.ISkin;
18        import com.longtailvideo.jwplayer.view.skins.DefaultSkin;
19        import com.longtailvideo.jwplayer.view.skins.PNGSkin;
20        import com.longtailvideo.jwplayer.view.skins.SWFSkin;
21       
22        import flash.display.Bitmap;
23        import flash.display.DisplayObject;
24        import flash.display.DisplayObjectContainer;
25        import flash.display.Loader;
26        import flash.display.LoaderInfo;
27        import flash.display.MovieClip;
28        import flash.display.Sprite;
29        import flash.events.Event;
30        import flash.events.IOErrorEvent;
31        import flash.events.MouseEvent;
32        import flash.geom.ColorTransform;
33        import flash.geom.Rectangle;
34        import flash.net.URLRequest;
35        import flash.system.LoaderContext;
36        import flash.text.TextField;
37        import flash.text.TextFormat;
38        import flash.utils.Dictionary;
39        import flash.utils.clearInterval;
40        import flash.utils.setInterval;
41       
42       
43        public class PlaylistComponent extends CoreComponent implements IPlaylistComponent {
44                /** Array with all button instances **/
45                private var buttons:Array;
46                /** Height of a button (to calculate scrolling) **/
47                private var buttonheight:Number;
48                /** Currently active button. **/
49                private var active:Number;
50                /** Proportion between clip and mask. **/
51                private var proportion:Number;
52                /** Interval ID for scrolling **/
53                private var scrollInterval:Number;
54                /** Image dimensions. **/
55                private var image:Array;
56                /** Color object for backcolor. **/
57                private var back:ColorTransform;
58                /** Color object for frontcolor. **/
59                private var front:ColorTransform;
60                /** Color object for lightcolor. **/
61                private var light:ColorTransform;
62                /** Visual representation of a the playlist **/
63                private var list:Sprite;
64                /** Visual representation of a playlist item **/
65                private var button:Sprite;
66                /** The playlist mask **/
67                private var listmask:Sprite;
68                /** The playlist slider **/
69                private var slider:Sprite;
70                /** The playlist background **/
71                private var background:Sprite;
72                /** Internal reference to the skin **/
73                private var skin:ISkin;
74                private var skinLoaded:Boolean = false;
75                private var pendingResize:Rectangle;
76                private var pendingBuild:Boolean = false;
77                /** Map of images and loaders **/
78                private var imageLoaderMap:Dictionary;
79                /** Which field element can be colorized **/           
80                private var colorizableFields:Array = ["title", "duration", "description", "author", "tags"];
81               
82                public function PlaylistComponent(player:IPlayer) {
83                        super(player, "playlist");
84                        player.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_ITEM, itemHandler);
85                        player.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_LOADED, playlistHandler);
86                        player.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_UPDATED, playlistHandler);
87                        player.addEventListener(PlayerStateEvent.JWPLAYER_PLAYER_STATE, stateHandler);
88                       
89                        if (_player.skin is SWFSkin && !_player.skin.hasComponent('playlist')) {
90                                var defaultSkin:DefaultSkin = new DefaultSkin();
91                                defaultSkin.addEventListener(Event.COMPLETE, continueSetup);
92                                skin = defaultSkin;
93                                defaultSkin.load();
94                        } else {
95                                skinLoaded = true;
96                                skin = _player.skin;
97                                continueSetup();
98                        }
99                }
100               
101                protected function continueSetup(evt:Event=null):void {
102                        skinLoaded = true;
103                       
104                        background = getSkinElement("background") as Sprite;
105                        if (!background) {
106                                var backColor:Color = getConfigParam("backgroundcolor") ? new Color(String(getConfigParam("backgroundcolor"))) : player.config.screencolor;
107                                background = new Sprite();
108                                background.name = "background";
109                                background.graphics.beginFill(backColor ? backColor.color : 0, 1);
110                                background.graphics.drawRect(0, 0, 1, 1);
111                                background.graphics.endFill();
112                        }
113                        addElement(background);
114                       
115                        slider = buildSlider();
116                        slider.buttonMode = true;
117                        slider.mouseChildren = false;
118                        slider.addEventListener(MouseEvent.MOUSE_DOWN, sdownHandler);
119                        slider.addEventListener(MouseEvent.MOUSE_OVER, soverHandler);
120                        slider.addEventListener(MouseEvent.MOUSE_OUT, soutHandler);
121                        slider.visible = false;
122                        addElement(slider);
123                       
124                        listmask = getSkinElement("masker") as Sprite;
125                        if (!listmask) {
126                                listmask = new Sprite();
127                                listmask.graphics.beginFill(0xff0000, 1);
128                                listmask.graphics.drawRect(0, 0, 1, 1);
129                                listmask.graphics.endFill();
130                        }
131                        addElement(listmask);
132                       
133                        list = getSkinElement("list") as Sprite;
134                        if (!list) {
135                                list = new Sprite();
136                                button = buildButton() as Sprite;
137                                addElement(button, list);
138                        } else {
139                                button = list.getChildByName("button") as Sprite;
140                        }
141                        buttonheight = button.height;
142                        button.visible = false;
143                        list.mask = listmask;
144                        list.addEventListener(MouseEvent.CLICK, clickHandler);
145                        list.addEventListener(MouseEvent.MOUSE_OVER, overHandler);
146                        list.addEventListener(MouseEvent.MOUSE_OUT, outHandler);
147                        addElement(list);
148                       
149                        buttons = new Array();
150                        this.addEventListener(MouseEvent.MOUSE_WHEEL, wheelHandler);
151                        try {
152                                image = new Array(button.getChildByName("image").width, button.getChildByName("image").height);
153                        } catch (err:Error) {
154                        }
155                        if (button.getChildByName("back")) {
156                                setColors();
157                        }
158                        if (pendingBuild) {
159                                buildPlaylist(true);
160                        }
161                        if (pendingResize) {
162                                resize(pendingResize.width, pendingResize.height);
163                        }
164                }
165               
166                private function buildSlider():Sprite {
167                        var newSlider:Sprite = getSkinElement("slider") as Sprite;
168
169                        if (!newSlider) {
170                                newSlider = new Sprite();
171                                var sliderBack:Sprite = buildSliderElement('back', 'sliderBackground', 1, 1);
172                                addElement(sliderBack, newSlider);
173                               
174                                var sliderRail:Sprite = buildSliderElement('rail', 'sliderRail', 7, 22);
175                                addElement(sliderRail, newSlider);
176                               
177                                var sliderThumb:Sprite = buildSliderElement('icon', 'sliderThumb', 5, 54);
178                                addElement(sliderThumb, newSlider, (sliderRail.width - sliderThumb.width) / 2);
179                        }
180
181                        /* These elements were never included in the swf skins, so add them even if the slider was in a SWF skin */
182                       
183                        var sliderCapTop:Sprite = buildSliderElement('captop', 'sliderCapTop');
184                        addElement(sliderCapTop, newSlider);
185
186                        var sliderCapBottom:Sprite = buildSliderElement('capbottom', 'sliderCapBottom');
187                        addElement(sliderCapBottom, newSlider);
188                       
189                        return newSlider;
190                }
191               
192                private function buildSliderElement(name:String, skinElementName:String, width:Number=0, height:Number=0):Sprite {
193                        var newElement:Sprite = getSkinElement(skinElementName) as Sprite;
194                        if (!newElement) {
195                                newElement = new Sprite();
196                                if (width * height > 0) {
197                                        newElement.graphics.beginFill(0, 1);
198                                        newElement.graphics.drawRect(0, 0, width, height);
199                                        newElement.graphics.endFill();
200                                }
201                        }
202                        try {
203                                newElement.name = name;
204                        } catch(e:Error) {} //This is not possible if the element was created and named from an FLA
205                       
206                        return newElement;
207                }
208               
209               
210                private function buildButton():MovieClip {
211                        var btn:MovieClip = new MovieClip();
212                       
213                        var backActive:Sprite = getSkinElement("itemActive") as Sprite;
214                        if (!backActive) {
215                                backActive = getSkinElement("item") as Sprite;
216                                if (!backActive) {
217                                        backActive = new Sprite();
218                                        backActive.graphics.beginFill(0, 1);
219                                        backActive.graphics.drawRect(0, 0, 100, 100);
220                                        backActive.graphics.endFill();
221                                }
222                        }
223                        backActive.name = "backActive";
224                        backActive.visible = false;
225                        addElement(backActive, btn, 0, 0);
226
227                        var backOver:Sprite = getSkinElement("itemOver") as Sprite;
228                        if (!backOver) {
229                                backOver = new Sprite();
230                                backOver.graphics.beginFill(0, 1);
231                                backOver.graphics.drawRect(0, 0, 1, 1);
232                                backOver.graphics.endFill();
233                        }
234                        backOver.name = "backOver";
235                        backOver.visible = false;
236                        addElement(backOver, btn, 0, 0);
237                       
238                        var back:Sprite = getSkinElement("item") as Sprite;
239                        if (!back) {
240                                back = new Sprite();
241                                back.graphics.beginFill(0, 1);
242                                back.graphics.drawRect(0, 0, 100, 100);
243                                back.graphics.endFill();
244                        }
245                        back.name = "back";
246                        addElement(back, btn, 0, 0);
247                       
248                        var img:MovieClip = new MovieClip;
249                        var imgBG:Sprite = getSkinElement("itemImage") as Sprite;
250                        var imageOffset:Number = 5;
251                        img.name = "image";
252                        img.graphics.beginFill(0, 0);
253                        if (imgBG) {
254                                imgBG.name = "imageBackground";
255                                img.addChild(imgBG);
256                                imgBG.x = imgBG.y = (back.height - imgBG.height) / 2;
257                                img.graphics.drawRect(0, 0, imgBG.width + 2 * imgBG.x, back.height);
258                                imageOffset = 0;
259                        } else {
260                                img.graphics.drawRect(0, 0, 4 * back.height / 3, back.height);
261                        }
262                        img.graphics.endFill();
263                        img['stacker.noresize'] = true;
264                        addElement(img, btn, 0, 0);
265                       
266                        var titleTextFormat:TextFormat = new TextFormat();
267                        titleTextFormat.size = fontSize ? fontSize : 13;
268                        titleTextFormat.font = fontFace ? fontFace : "_sans";
269                        titleTextFormat.bold = (!fontWeight || fontWeight == "bold");
270                        titleTextFormat.italic = (fontStyle == "italic");
271                        var title:TextField = new TextField();
272                        title.name = "title";
273                        //title.autoSize = TextFieldAutoSize.LEFT;
274                        title.defaultTextFormat = titleTextFormat;
275                        title.wordWrap = true;
276                        title.multiline = true;
277                        title.width = 250;
278                        title.height = 20;
279                        addElement(title, btn, img.width + imageOffset, 2);
280                       
281                        var descriptionTextFormat:TextFormat = new TextFormat();
282                        descriptionTextFormat.size = fontSize ? fontSize : 11;
283                        descriptionTextFormat.font = fontFace ? fontFace : "_sans";
284                        descriptionTextFormat.bold = (fontWeight == "bold");
285                        descriptionTextFormat.italic = (fontStyle == "italic");
286                        var description:TextField = new TextField();
287                        description.name = "description";
288                        //description.autoSize = TextFieldAutoSize.LEFT;
289                        description.wordWrap = true;
290                        description.multiline = true;
291                        description.width= 290;
292                        description.height = back.height - 20;
293                        description.defaultTextFormat = descriptionTextFormat;
294                        addElement(description, btn, img.width + imageOffset + 1, 20);
295                       
296                        var duration:TextField = new TextField();
297                        duration.name = "duration";
298                        duration.width = 40;
299                        duration.height = 20;
300                        titleTextFormat.size = fontSize ? fontSize : 11;
301                        duration.defaultTextFormat = titleTextFormat;
302                        addElement(duration, btn, 335, 4);
303                       
304                        backOver.width = backActive.width = back.width = btn.width;                     
305                       
306                        return btn;
307                }
308               
309                private function addElement(doc:DisplayObject, parent:DisplayObjectContainer = null, x:Number = 0, y:Number = 0):void {
310                        if (!parent) {
311                                parent = this;
312                        }
313                        doc.x = x;
314                        parent.addChild(doc);
315                        doc.y = y;
316                }
317               
318                private function get overColor():Color {
319                        return getConfigParam("overcolor") ? new Color(String(getConfigParam("overcolor"))) : null;
320                }
321               
322                private function get activeColor():Color {
323                        return getConfigParam("activecolor") ? new Color(String(getConfigParam("activecolor"))) : null;
324                }
325               
326                /** Handle a button rollover. **/
327                private function overHandler(evt:MouseEvent):void {
328                        var idx:Number = Number(evt.target.name);
329
330                        if (fontColor && overColor) {
331                                for each (var itm:String in colorizableFields) {
332                                        if (getButton(idx).getChildByName(itm) && getButton(idx).getChildByName(itm) is TextField) {
333                                                (getButton(idx).getChildByName(itm) as TextField).textColor = overColor.color;
334                                        }
335                                }
336                        } else if (front && back) {
337                                for each (itm in colorizableFields) {
338                                        if (getButton(idx).getChildByName(itm) && getButton(idx).getChildByName(itm) is TextField) {
339                                                (getButton(idx).getChildByName(itm) as TextField).textColor = back.color;
340                                        }
341                                }
342                        }
343                        if (swfSkinned) {
344                                if (light) {
345                                        getButton(idx).getChildByName("back").transform.colorTransform = light;
346                                }
347                        } else {
348                                getButton(idx).getChildByName("backActive").visible = false;
349                                getButton(idx).getChildByName("back").visible = false;
350                                getButton(idx).getChildByName("backOver").visible = true;
351                        }
352                }
353               
354               
355                /** Handle a button rollover. **/
356                private function outHandler(evt:MouseEvent):void {
357                        var idx:Number = Number(evt.target.name);
358                        for each (var itm:String in colorizableFields) {
359                                var button:Sprite = getButton(idx);
360                                if (button && button.getChildByName(itm)) {
361                                        var field:TextField = (getButton(idx).getChildByName(itm) as TextField)
362                                        if (field) {
363                                                if (idx == active && (activeColor || (light && swfSkinned))) {
364                                                        field.textColor = activeColor ? activeColor.color : (fontColor ? fontColor.color : light.color);
365                                                } else {
366                                                        if (fontColor && overColor) {
367                                                                field.textColor =  fontColor.color;
368                                                        } else if (front && back) {
369                                                                field.textColor =  front.color;
370                                                        }
371                                                }
372                                        }
373                                       
374                                        if (swfSkinned) {
375                                                if (front && back) {
376                                                        button.getChildByName("back").transform.colorTransform = back;
377                                                }
378                                        } else {
379                                                getButton(idx).getChildByName("backActive").visible = (idx == active);
380                                                getButton(idx).getChildByName("back").visible = (idx != active);
381                                                getButton(idx).getChildByName("backOver").visible = false;
382                                        }
383                                }
384                        }
385                       
386                }
387               
388               
389                /** Setup all buttons in the playlist **/
390                private function buildPlaylist(clr:Boolean):void {
391                        if (!_player.playlist || player.playlist.length < 1) {
392                                return;
393                        }
394                        if (!skinLoaded) {
395                                pendingBuild = true;
396                                return
397                        }
398
399                        var wid:Number = getConfigParam("width");
400                        var hei:Number = getConfigParam("height");
401                        listmask.height = hei;
402                        listmask.width = wid;
403                        proportion = _player.playlist.length * buttonheight / hei;
404                        if (proportion > 1.01) {
405                                wid -= slider.width;
406                                layoutSlider();
407                        } else {
408                                slider.visible = false;
409                        }
410                        if (clr) {
411                                list.y = listmask.y;
412                                for (var j:Number = 0; j < buttons.length; j++) {
413                                        list.removeChild(getButton(j));
414                                }
415                                buttons = new Array();
416                                imageLoaderMap = new Dictionary();
417                        } else {
418                                if (proportion > 1) {
419                                        scrollEase();
420                                }
421                        }
422                        for (var i:Number = 0; i < _player.playlist.length; i++) {
423                                if (clr) {
424                                        var btn:MovieClip;
425                                        if (swfSkinned) {
426                                                btn = Draw.clone(button, true) as MovieClip;
427                                        } else {
428                                                btn = buildButton();
429                                                list.addChild(btn);
430                                        }
431                                        var stc:Stacker = new Stacker(btn);
432                                        btn.y = i * buttonheight;
433                                        btn.buttonMode = true;
434                                        btn.mouseChildren = false;
435                                        btn.name = i.toString();
436                                        buttons.push({c: btn, s: stc});
437                                        setContents(i);
438                                }
439                                if (buttons[i]) {
440                                        (buttons[i].s as Stacker).rearrange(wid);
441                                }
442                        }
443                }
444               
445               
446                /** Setup the scrollbar component **/
447                private function layoutSlider():void {
448                        slider.visible = true;
449                        slider.x = getConfigParam("width") - slider.width;
450                        if (player.skin is PNGSkin) {
451                                var capTop:DisplayObject = slider.getChildByName("captop");
452                                var capBottom:DisplayObject = slider.getChildByName("capbottom");
453                                slider.getChildByName("back").y = capTop.height;
454                                slider.getChildByName("rail").y = capTop.height;
455                                slider.getChildByName("icon").y = capTop.height;
456                                slider.getChildByName("back").height = getConfigParam('height') - capBottom.height - capTop.height;
457                                slider.getChildByName("rail").height = getConfigParam('height') - capBottom.height - capTop.height;
458                                slider.getChildByName("icon").height = Math.round(slider.getChildByName("rail").height / proportion);
459                                capBottom.y = getConfigParam('height') - capBottom.height;
460                        } else {
461                                var dif:Number = getConfigParam("height") - slider.height - slider.y;
462                                slider.getChildByName("back").height += dif;
463                                slider.getChildByName("rail").height += dif;
464                                slider.getChildByName("icon").height = Math.round(slider.getChildByName("rail").height / proportion);
465                        }
466                }
467               
468               
469                /** Make sure the playlist is not out of range. **/
470                private function scrollEase(ips:Number = -1, cps:Number = -1):void {
471                        if (ips != -1) {
472                                slider.getChildByName("icon").y = Math.round(ips - (ips - slider.getChildByName("icon").y) / 1.5);
473                                list.y = Math.round((cps - (cps - list.y) / 1.5));
474                        }
475                        if (list.y > 0 || slider.getChildByName("icon").y < slider.getChildByName("rail").y) {
476                                list.y = listmask.y;
477                                slider.getChildByName("icon").y = slider.getChildByName("rail").y;
478                        } else if (list.y < listmask.height - list.height || slider.getChildByName("icon").y > slider.getChildByName("rail").y + slider.getChildByName("rail").height - slider.getChildByName("icon").height) {
479                                slider.getChildByName("icon").y = slider.getChildByName("rail").y + slider.getChildByName("rail").height - slider.getChildByName("icon").height;
480                                list.y = listmask.y + listmask.height - list.height;
481                        }
482                }
483               
484               
485                /** Scrolling handler. **/
486                private function scrollHandler():void {
487                        var yps:Number = slider.mouseY - slider.getChildByName("rail").y;
488                        var ips:Number = yps - slider.getChildByName("icon").height / 2;
489                        var cps:Number = listmask.y + listmask.height / 2 - proportion * yps;
490                        scrollEase(ips, cps);
491                }
492               
493               
494                /** Init the colors. **/
495                private function setColors():void {
496                        if (_player.config.backcolor) {
497                                back = new ColorTransform();
498                                back.color = _player.config.backcolor.color;
499                                if (swfSkinned) {
500                                        background.transform.colorTransform = back;
501                                        slider.getChildByName("back").transform.colorTransform = back;
502                                }
503                        }
504                        if (_player.config.frontcolor) {
505                                front = new ColorTransform();
506                                front.color = _player.config.frontcolor.color;
507                                try {
508                                        if (swfSkinned) {
509                                                slider.getChildByName("icon").transform.colorTransform = front;
510                                                slider.getChildByName("rail").transform.colorTransform = front;
511                                        }
512                                } catch (err:Error) {
513                                }
514                                if (_player.config.lightcolor && swfSkinned) {
515                                        light = new ColorTransform();
516                                        light.color = _player.config.lightcolor.color;
517                                } else {
518                                        light = front;
519                                }
520                        }
521                }
522               
523               
524                /** Setup button elements **/
525                private function setContents(idx:Number):void {
526                        var playlistItem:PlaylistItem = _player.playlist.getItemAt(idx);
527                        var title:TextField = getButton(idx).getChildByName("title") as TextField;
528                        var description:TextField = getButton(idx).getChildByName("description") as TextField;
529                        var duration:TextField = getButton(idx).getChildByName("duration") as TextField;
530                        var author:TextField = getButton(idx).getChildByName("author") as TextField;
531                        var tags:TextField = getButton(idx).getChildByName("tags") as TextField;
532                        if (playlistItem.image || playlistItem['playlist.image']) {
533                                var imageFile:String = playlistItem['playlist.image'] ? playlistItem['playlist.image'] : playlistItem.image;
534                                if (getConfigParam('thumbs') != false && _player.config.playlist != 'none') {
535                                        var img:Sprite = getButton(idx).getChildByName("image") as Sprite;
536                                        if (img) {
537                                                img.alpha = 0;
538                                                var ldr:Loader = new Loader();
539                                                imageLoaderMap[ldr] = idx;
540                                                ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderHandler);
541                                                ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
542                                                ldr.load(new URLRequest(encodeURI(imageFile)), new LoaderContext(true));
543                                        }
544                                }
545                        }
546                        if (duration && playlistItem.duration) {
547                                if (playlistItem.duration > 0) {
548                                        duration.text = Strings.digits(playlistItem.duration);
549                                        if (fontColor) {
550                                                duration.textColor = fontColor.color;
551                                        } else if (front) {
552                                                duration.textColor = front.color;
553                                        }
554                                }
555                        }
556                        try {
557                                if (description) {
558                                        description.htmlText = playlistItem.description;
559                                }
560                                if (title) {
561                                        title.htmlText = "<b>" + playlistItem.title + "</b>";
562                                }
563                                if (author) {
564                                        author.htmlText = playlistItem.author;
565                                }
566                                if (tags) {
567                                        tags.htmlText = playlistItem.tags;
568                                }
569                                if (fontColor) {
570                                        if (description) { description.textColor = fontColor.color; }
571                                        if (title) { title.textColor = fontColor.color; }
572                                        if (author) { author.textColor = fontColor.color; }
573                                        if (tags) { tags.textColor = fontColor.color; }
574                                } else if (front) {
575                                        if (description) { description.textColor = front.color; }
576                                        if (title) { title.textColor = front.color; }
577                                        if (author) { author.textColor = front.color; }
578                                        if (tags) { tags.textColor = front.color; }
579                                }
580                        } catch (e:Error) {
581                        }
582                        img = getButton(idx).getChildByName("image") as MovieClip;
583                        if (img && (!(playlistItem.image || playlistItem['playlist.image']) || getConfigParam('thumbs') == false)) {
584                                if (!img.getChildByName("imageBackground")) {
585                                        getButton(idx).getChildByName("image").visible = false;
586                                }
587                        }
588                        if (back && swfSkinned) {
589                                getButton(idx).getChildByName("back").transform.colorTransform = back;
590                        }
591                }
592               
593               
594                /** Loading of image completed; resume loading **/
595                private function loaderHandler(evt:Event):void {
596                        try {
597                                var ldr:Loader = (evt.target as LoaderInfo).loader;
598                                if (ldr in imageLoaderMap) {
599                                        var button:Sprite = getButton(imageLoaderMap[ldr]);
600                                        delete imageLoaderMap[ldr];
601                                        var img:Sprite = button.getChildByName("image") as Sprite;
602                                        var bg:Sprite = img.getChildByName("imageBackground") as Sprite;
603                                        img.alpha = 1;
604                                        var msk:Sprite
605                                        if (bg) {
606                                                bg.visible = false;
607                                                msk = Draw.rect(button, '0xFF0000', bg.width, bg.height, bg.x, bg.y);
608                                                ldr.x = bg.x;
609                                                ldr.y = bg.y;
610                                        } else {
611                                                msk = Draw.rect(button, '0xFF0000', img.width, img.height, img.x, img.y);
612                                        }
613                                        img.addChild(ldr);
614                                        img.mask = msk;
615                                        try {
616                                                Draw.smooth(ldr.content as Bitmap);
617                                        } catch (e:Error) {
618                                                Logger.log('Could not smooth thumbnail image: ' + e.message);
619                                        }
620                                        Stretcher.stretch(ldr, image[0], image[1], Stretcher.FILL);
621                                }
622                        } catch (err:Error) {
623                                Logger.log('Error loading playlist image: '+err.message);
624                        }
625                }
626               
627               
628                /** Loading of image failed; hide image **/
629                private function errorHandler(evt:Event):void {
630                        try {
631                                var ldr:Loader = (evt.target as LoaderInfo).loader;
632                                var button:Sprite = getButton(imageLoaderMap[ldr]);
633                                var img:Sprite = button.getChildByName("image") as Sprite;
634                                if (!img.getChildByName("imageBackground")) {
635                                        img.visible = false;
636                                }
637                                if (proportion > 1.01) {
638                                        (buttons[imageLoaderMap[ldr]].s as Stacker).rearrange(getConfigParam("width")-slider.width);
639                                } else {
640                                        (buttons[imageLoaderMap[ldr]].s as Stacker).rearrange(getConfigParam("width"));
641                                }
642                        } catch (err:Error) {
643                                Logger.log('Error loading playlist image '+ ldr.loaderInfo.url+': '+err.message);
644                        }
645                }
646               
647               
648                private function wheelHandler(evt:MouseEvent):void {
649                        //scrollEase(evt.delta * -1, getConfigParam("height"));
650                }
651               
652               
653                /** Start scrolling the playlist on mousedown. **/
654                private function sdownHandler(evt:MouseEvent):void {
655                        clearInterval(scrollInterval);
656                        RootReference.stage.addEventListener(MouseEvent.MOUSE_UP, supHandler);
657                        scrollHandler();
658                        scrollInterval = setInterval(scrollHandler, 50);
659                }
660               
661               
662                /** Revert the highlight on mouseout. **/
663                private function soutHandler(evt:MouseEvent):void {
664                        if (front && swfSkinned) {
665                                slider.getChildByName("icon").transform.colorTransform = front;
666                        } else {
667                                //slider.getChildByName("icon").gotoAndStop('out');
668                        }
669                }
670               
671               
672                /** Highlight the icon on rollover. **/
673                private function soverHandler(evt:MouseEvent):void {
674                        if (front && swfSkinned) {
675                                slider.getChildByName("icon").transform.colorTransform = light;
676                        } else {
677                                //slider.getChildByName("icon").gotoAndStop('over');
678                        }
679                }
680               
681               
682                /** Stop scrolling the playlist on mouseout. **/
683                private function supHandler(evt:MouseEvent):void {
684                        clearInterval(scrollInterval);
685                        RootReference.stage.removeEventListener(MouseEvent.MOUSE_UP, supHandler);
686                }
687               
688               
689                /** Handle a click on a button. **/
690                private function clickHandler(evt:MouseEvent):void {
691                        var itemNumber:Number = Number(evt.target.name);
692                        dispatchEvent(new ViewEvent(ViewEvent.JWPLAYER_VIEW_ITEM, itemNumber));
693                        _player.playlistItem(itemNumber);
694                }
695               
696               
697                /** Process resizing requests **/
698                public function resize(width:Number, height:Number):void {
699                        if (skinLoaded) {
700                                setConfigParam("width", width);
701                                setConfigParam("height", height);
702                                background.width = width;
703                                background.height = height;
704                                buildPlaylist(false);
705                                if (PlayerLayoutManager.testPosition(getConfigParam('position'))) {
706                                        visible = true;
707                                } else if (getConfigParam('position') == "over") {
708                                        stateHandler();
709                                } else {
710                                        visible = false;
711                                }
712                                if (visible && getConfigParam('visible') === false) {
713                                        visible = false;
714                                }
715                        } else {
716                                pendingResize = new Rectangle(0,0,width,height);
717                        }
718                }
719               
720               
721                /** Switch the currently active item */
722                protected function itemHandler(evt:PlaylistEvent = null):void {
723                        var idx:Number = _player.playlist.currentIndex;
724                        clearInterval(scrollInterval);
725                        if (proportion > 1.01) {
726                                scrollInterval = setInterval(scrollEase, 50, idx * buttonheight / proportion, -idx * buttonheight + listmask.y);
727                        }
728                        if ((light && swfSkinned) || activeColor) {
729                                for each (var itm:String in colorizableFields) {
730                                        if (getButton(idx).getChildByName(itm)) {
731                                                try {
732                                                        (getButton(idx).getChildByName(itm) as TextField).textColor = swfSkinned ? light.color : activeColor.color;
733                                                } catch (err:Error) {
734                                                }
735                                        }
736                                }
737                        }
738                        if (!isNaN(active)) {
739                                if (front || fontColor) {
740                                        for each (var act:String in colorizableFields) {
741                                                if (getButton(active).getChildByName(act)) {
742                                                        try {
743                                                                (getButton(active).getChildByName(act) as TextField).textColor = fontColor ? fontColor.color : front.color;
744                                                        } catch (err:Error) {
745                                                        }
746                                                }
747                                        }
748                                }
749
750                                if (swfSkinned) {
751                                        if (back) {
752                                                getButton(idx).getChildByName("back").transform.colorTransform = back;
753                                        }
754                                } else {
755                                        getButton(active).getChildByName("back").visible = true;
756                                        getButton(active).getChildByName("backOver").visible = false;
757                                        getButton(active).getChildByName("backActive").visible = false;
758                                }
759                        }
760                        active = idx;
761
762                        if (!swfSkinned) {
763                                getButton(active).getChildByName("backActive").visible = true;
764                                getButton(active).getChildByName("back").visible = false;
765                                getButton(active).getChildByName("backOver").visible = false;
766                        }
767                       
768                       
769
770                }
771               
772               
773                /** New playlist loaded: rebuild the playclip. **/
774                protected function playlistHandler(evt:PlaylistEvent = null):void {
775                        clearInterval(scrollInterval);
776                        active = undefined;
777                        buildPlaylist(true);
778                        if (background) {
779                                resize(background.width, background.height);
780                        }
781                }
782               
783               
784                /** Process state changes **/
785                protected function stateHandler(evt:PlayerStateEvent = null):void {
786                        if (getConfigParam('position') == "over") {
787                                if (player.state == PlayerState.PLAYING || player.state == PlayerState.PAUSED || player.state == PlayerState.BUFFERING) {
788                                        visible = false;
789                                } else {
790                                        visible = true;
791                                }
792                        }
793                }
794               
795               
796                private function getButton(id:Number):Sprite {
797                        return buttons[id].c as Sprite;
798                }
799               
800                private function get swfSkinned():Boolean {
801                        if (skin is SWFSkin) {
802                                return (skin.hasComponent('playlist'));
803                        }
804                        return false;
805                }
806               
807                protected override function getSkinElement(element:String):DisplayObject {
808                        return skin.getSkinElement(_name,element);
809                }
810               
811        }
812}
813
Note: See TracBrowser for help on using the repository browser.