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