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

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