| 1 | package com.longtailvideo.jwplayer.view.components { |
|---|
| 2 | import com.longtailvideo.jwplayer.events.MediaEvent; |
|---|
| 3 | import com.longtailvideo.jwplayer.events.PlayerEvent; |
|---|
| 4 | import com.longtailvideo.jwplayer.events.PlayerStateEvent; |
|---|
| 5 | import com.longtailvideo.jwplayer.events.PlaylistEvent; |
|---|
| 6 | import com.longtailvideo.jwplayer.events.ViewEvent; |
|---|
| 7 | import com.longtailvideo.jwplayer.player.IPlayer; |
|---|
| 8 | import com.longtailvideo.jwplayer.player.PlayerState; |
|---|
| 9 | import com.longtailvideo.jwplayer.utils.Strings; |
|---|
| 10 | import com.longtailvideo.jwplayer.view.interfaces.IControlbarComponent; |
|---|
| 11 | |
|---|
| 12 | import flash.display.DisplayObject; |
|---|
| 13 | import flash.display.MovieClip; |
|---|
| 14 | import flash.display.Sprite; |
|---|
| 15 | import flash.events.MouseEvent; |
|---|
| 16 | import flash.text.TextField; |
|---|
| 17 | import flash.text.TextFieldAutoSize; |
|---|
| 18 | import flash.text.TextFormat; |
|---|
| 19 | import flash.ui.Mouse; |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | /** |
|---|
| 23 | * Sent when the user interface requests that the player play the currently loaded media |
|---|
| 24 | * |
|---|
| 25 | * @eventType com.longtailvideo.jwplayer.events.ViewEvent.JWPLAYER_VIEW_PLAY |
|---|
| 26 | */ |
|---|
| 27 | [Event(name="jwPlayerViewPlay", type="com.longtailvideo.jwplayer.events.ViewEvent")] |
|---|
| 28 | /** |
|---|
| 29 | * Sent when the user interface requests that the player pause the currently playing media |
|---|
| 30 | * |
|---|
| 31 | * @eventType com.longtailvideo.jwplayer.events.ViewEvent.JWPLAYER_VIEW_PAUSE |
|---|
| 32 | */ |
|---|
| 33 | [Event(name="jwPlayerViewPause", type="com.longtailvideo.jwplayer.events.ViewEvent")] |
|---|
| 34 | /** |
|---|
| 35 | * Sent when the user interface requests that the player stop the currently playing media |
|---|
| 36 | * |
|---|
| 37 | * @eventType com.longtailvideo.jwplayer.events.ViewEvent.JWPLAYER_VIEW_STOP |
|---|
| 38 | */ |
|---|
| 39 | [Event(name="jwPlayerViewStop", type="com.longtailvideo.jwplayer.events.ViewEvent")] |
|---|
| 40 | /** |
|---|
| 41 | * Sent when the user interface requests that the player play the next item in its playlist |
|---|
| 42 | * |
|---|
| 43 | * @eventType com.longtailvideo.jwplayer.events.ViewEvent.JWPLAYER_VIEW_NEXT |
|---|
| 44 | */ |
|---|
| 45 | [Event(name="jwPlayerViewNext", type="com.longtailvideo.jwplayer.events.ViewEvent")] |
|---|
| 46 | /** |
|---|
| 47 | * Sent when the user interface requests that the player play the previous item in its playlist |
|---|
| 48 | * |
|---|
| 49 | * @eventType com.longtailvideo.jwplayer.events.ViewEvent.JWPLAYER_VIEW_PREV |
|---|
| 50 | */ |
|---|
| 51 | [Event(name="jwPlayerViewPrev", type="com.longtailvideo.jwplayer.events.ViewEvent")] |
|---|
| 52 | /** |
|---|
| 53 | * Sent when the user interface requests that the player navigate to the playlist item's <code>link</code> property |
|---|
| 54 | * |
|---|
| 55 | * @eventType com.longtailvideo.jwplayer.events.ViewEvent.JWPLAYER_VIEW_LINK |
|---|
| 56 | */ |
|---|
| 57 | [Event(name="jwPlayerViewLink", type="com.longtailvideo.jwplayer.events.ViewEvent")] |
|---|
| 58 | /** |
|---|
| 59 | * |
|---|
| 60 | * |
|---|
| 61 | * @eventType com.longtailvideo.jwplayer.events.ViewEvent.JWPLAYER_VIEW_MUTE |
|---|
| 62 | */ |
|---|
| 63 | [Event(name="jwPlayerViewMute", type="com.longtailvideo.jwplayer.events.ViewEvent")] |
|---|
| 64 | /** |
|---|
| 65 | * |
|---|
| 66 | * |
|---|
| 67 | * @eventType com.longtailvideo.jwplayer.events.ViewEvent.JWPLAYER_VIEW_FULLSCREEN |
|---|
| 68 | */ |
|---|
| 69 | [Event(name="jwPlayerViewFullscreen", type="com.longtailvideo.jwplayer.events.ViewEvent")] |
|---|
| 70 | /** |
|---|
| 71 | * |
|---|
| 72 | * |
|---|
| 73 | * @eventType com.longtailvideo.jwplayer.events.ViewEvent.JWPLAYER_VIEW_VOLUME |
|---|
| 74 | */ |
|---|
| 75 | [Event(name="jwPlayerViewVolume", type="com.longtailvideo.jwplayer.events.ViewEvent")] |
|---|
| 76 | /** |
|---|
| 77 | * |
|---|
| 78 | * |
|---|
| 79 | * @eventType com.longtailvideo.jwplayer.events.ViewEvent.JWPLAYER_VIEW_SEEK |
|---|
| 80 | */ |
|---|
| 81 | [Event(name="jwPlayerViewSeek", type="com.longtailvideo.jwplayer.events.ViewEvent")] |
|---|
| 82 | public class ControlbarComponent extends CoreComponent implements IControlbarComponent { |
|---|
| 83 | protected var _buttons:Object = {}; |
|---|
| 84 | protected var _dividers:Array; |
|---|
| 85 | protected var _defaultLayout:String = "[play|stop|prev|next|elapsed][time][duration|blank|fullscreen|mute volume]"; |
|---|
| 86 | protected var _currentLayout:String; |
|---|
| 87 | protected var _layoutManager:ControlbarLayoutManager; |
|---|
| 88 | protected var _width:Number; |
|---|
| 89 | protected var _height:Number; |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | public function ControlbarComponent(player:IPlayer) { |
|---|
| 93 | super(player, "controlbar"); |
|---|
| 94 | _layoutManager = new ControlbarLayoutManager(this); |
|---|
| 95 | _dividers = []; |
|---|
| 96 | setupBackground(); |
|---|
| 97 | setupDefaultButtons(); |
|---|
| 98 | addEventListeners(); |
|---|
| 99 | updateControlbarState(); |
|---|
| 100 | setTime(0, 0); |
|---|
| 101 | updateVolumeSlider(); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | private function addEventListeners():void { |
|---|
| 106 | player.addEventListener(PlayerStateEvent.JWPLAYER_PLAYER_STATE, stateHandler); |
|---|
| 107 | player.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_LOADED, playlistHandler); |
|---|
| 108 | player.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_UPDATED, playlistHandler); |
|---|
| 109 | player.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_ITEM, playlistHandler); |
|---|
| 110 | player.addEventListener(MediaEvent.JWPLAYER_MEDIA_MUTE, stateHandler); |
|---|
| 111 | player.addEventListener(MediaEvent.JWPLAYER_MEDIA_VOLUME, updateVolumeSlider); |
|---|
| 112 | player.addEventListener(MediaEvent.JWPLAYER_MEDIA_BUFFER, mediaHandler); |
|---|
| 113 | player.addEventListener(MediaEvent.JWPLAYER_MEDIA_TIME, mediaHandler); |
|---|
| 114 | player.addEventListener(PlayerEvent.JWPLAYER_LOCKED, lockHandler); |
|---|
| 115 | player.addEventListener(PlayerEvent.JWPLAYER_UNLOCKED, lockHandler); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | private function lockHandler(evt:PlayerEvent):void{ |
|---|
| 119 | if (_player.locked){ |
|---|
| 120 | getSlider('time').lock(); |
|---|
| 121 | getSlider('volume').lock(); |
|---|
| 122 | } else { |
|---|
| 123 | getSlider('time').unlock(); |
|---|
| 124 | getSlider('volume').unlock(); |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | private function playlistHandler(evt:PlaylistEvent):void { |
|---|
| 130 | getSlider('time').reset(); |
|---|
| 131 | updateControlbarState(); |
|---|
| 132 | redraw(); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | private function stateHandler(evt:PlayerEvent):void { |
|---|
| 137 | updateControlbarState(); |
|---|
| 138 | redraw(); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | private function updateControlbarState():void { |
|---|
| 143 | var newLayout:String = _defaultLayout; |
|---|
| 144 | newLayout = removeButtonFromLayout("blank", newLayout); |
|---|
| 145 | if (player.state == PlayerState.PLAYING) { |
|---|
| 146 | newLayout = newLayout.replace('play', 'pause'); |
|---|
| 147 | hideButton('play'); |
|---|
| 148 | } else if (player.state == PlayerState.IDLE) { |
|---|
| 149 | getSlider('time').reset(); |
|---|
| 150 | if (_player.playlist.currentItem) { |
|---|
| 151 | setTime(0, _player.playlist.currentItem.duration); |
|---|
| 152 | } |
|---|
| 153 | hideButton('pause'); |
|---|
| 154 | } else { |
|---|
| 155 | hideButton('pause'); |
|---|
| 156 | } |
|---|
| 157 | if (player.playlist.length <= 1) { |
|---|
| 158 | newLayout = newLayout.replace("|prev|next", ""); |
|---|
| 159 | hideButton('prev'); |
|---|
| 160 | hideButton('next'); |
|---|
| 161 | } |
|---|
| 162 | if (player.mute) { |
|---|
| 163 | newLayout = newLayout.replace("mute", "unmute"); |
|---|
| 164 | hideButton("mute"); |
|---|
| 165 | } else { |
|---|
| 166 | hideButton("unmute"); |
|---|
| 167 | } |
|---|
| 168 | if (player.fullscreen) { |
|---|
| 169 | newLayout = newLayout.replace("fullscreen", "normalscreen"); |
|---|
| 170 | hideButton("fullscreen"); |
|---|
| 171 | } else { |
|---|
| 172 | hideButton("normalscreen"); |
|---|
| 173 | } |
|---|
| 174 | _currentLayout = removeInactive(newLayout); |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | private function removeInactive(layout:String):String { |
|---|
| 179 | var buttons:Array = _defaultLayout.match(/\W*([A-Za-z0-9]+?)\W/g); |
|---|
| 180 | for (var i:Number = 0; i < buttons.length; i++) { |
|---|
| 181 | var button:String = (buttons[i] as String).replace(/\W/g, ""); |
|---|
| 182 | if (!_buttons[button]) { |
|---|
| 183 | layout = removeButtonFromLayout(button, layout); |
|---|
| 184 | } |
|---|
| 185 | } |
|---|
| 186 | return layout; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | private function removeButtonFromLayout(button:String,layout:String):String { |
|---|
| 190 | layout = layout.replace(button, ""); |
|---|
| 191 | layout = layout.replace("||", "|"); |
|---|
| 192 | return layout; |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | private function mediaHandler(evt:MediaEvent):void { |
|---|
| 197 | var scrubber:Slider = getSlider('time'); |
|---|
| 198 | switch (evt.type) { |
|---|
| 199 | case MediaEvent.JWPLAYER_MEDIA_BUFFER: |
|---|
| 200 | //setTime(evt.position, evt.duration); |
|---|
| 201 | if (scrubber) { |
|---|
| 202 | //scrubber.setProgress(evt.position / evt.duration *100); |
|---|
| 203 | scrubber.setBuffer(evt.bufferPercent); |
|---|
| 204 | } |
|---|
| 205 | break; |
|---|
| 206 | case MediaEvent.JWPLAYER_MEDIA_TIME: |
|---|
| 207 | setTime(evt.position, evt.duration); |
|---|
| 208 | if (scrubber) { |
|---|
| 209 | scrubber.setProgress(evt.position / evt.duration * 100); |
|---|
| 210 | if (evt.bufferPercent >= 0) { |
|---|
| 211 | scrubber.setBuffer(evt.bufferPercent); |
|---|
| 212 | } |
|---|
| 213 | } |
|---|
| 214 | break; |
|---|
| 215 | default: |
|---|
| 216 | scrubber.reset(); |
|---|
| 217 | break; |
|---|
| 218 | } |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | private function updateVolumeSlider(evt:MediaEvent=null):void { |
|---|
| 223 | var volume:Slider = getSlider('volume'); |
|---|
| 224 | if (volume) { |
|---|
| 225 | if (!_player.config.mute) { |
|---|
| 226 | volume.setBuffer(100); |
|---|
| 227 | volume.setProgress(_player.config.volume); |
|---|
| 228 | volume.resize(getSkinElement("volumeSliderRail").width, volume.height); |
|---|
| 229 | } else { |
|---|
| 230 | volume.reset(); |
|---|
| 231 | volume.resize(getSkinElement("volumeSliderRail").width, volume.height); |
|---|
| 232 | } |
|---|
| 233 | } |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | private function setTime(position:Number, duration:Number):void { |
|---|
| 238 | if (position < 0) { |
|---|
| 239 | position = 0; |
|---|
| 240 | } |
|---|
| 241 | if (duration < 0) { |
|---|
| 242 | duration = 0; |
|---|
| 243 | } |
|---|
| 244 | var elapsedText:TextField = getButton('elapsed') as TextField; |
|---|
| 245 | elapsedText.text = Strings.digits(position); |
|---|
| 246 | var durationField:TextField = getButton('duration') as TextField; |
|---|
| 247 | durationField.text = Strings.digits(duration); |
|---|
| 248 | redraw(); |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | private function setupBackground():void { |
|---|
| 253 | var back:DisplayObject = getSkinElement("background"); |
|---|
| 254 | var capLeft:DisplayObject = getSkinElement("capLeft"); |
|---|
| 255 | var capRight:DisplayObject = getSkinElement("capRight"); |
|---|
| 256 | //var shade:DisplayObject = getSkinElement("shade"); |
|---|
| 257 | |
|---|
| 258 | if (!back) { |
|---|
| 259 | var newBackground:Sprite = new Sprite(); |
|---|
| 260 | newBackground.name = "background"; |
|---|
| 261 | newBackground.graphics.beginFill(0, 1); |
|---|
| 262 | newBackground.graphics.drawRect(0, 0, 1, 1); |
|---|
| 263 | newBackground.graphics.endFill(); |
|---|
| 264 | back = newBackground as DisplayObject; |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | _buttons['background'] = back; |
|---|
| 268 | addChild(back); |
|---|
| 269 | _height = back.height; |
|---|
| 270 | player.config.pluginConfig("controlbar")['size'] = back.height; |
|---|
| 271 | |
|---|
| 272 | if (capLeft) { |
|---|
| 273 | _buttons['capLeft'] = capLeft; |
|---|
| 274 | addChild(capLeft); |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | if (capRight) { |
|---|
| 278 | _buttons['capRight'] = capRight; |
|---|
| 279 | addChild(capRight); |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | /*if (shade) { |
|---|
| 283 | _buttons['shade'] = shade; |
|---|
| 284 | addChild(shade); |
|---|
| 285 | }*/ |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | private function setupDefaultButtons():void { |
|---|
| 290 | addComponentButton('play', ViewEvent.JWPLAYER_VIEW_PLAY); |
|---|
| 291 | addComponentButton('pause', ViewEvent.JWPLAYER_VIEW_PAUSE); |
|---|
| 292 | addComponentButton('prev', ViewEvent.JWPLAYER_VIEW_PREV); |
|---|
| 293 | addComponentButton('next', ViewEvent.JWPLAYER_VIEW_NEXT); |
|---|
| 294 | addComponentButton('stop', ViewEvent.JWPLAYER_VIEW_STOP); |
|---|
| 295 | addComponentButton('fullscreen', ViewEvent.JWPLAYER_VIEW_FULLSCREEN, true); |
|---|
| 296 | addComponentButton('normalscreen', ViewEvent.JWPLAYER_VIEW_FULLSCREEN, false); |
|---|
| 297 | addComponentButton('unmute', ViewEvent.JWPLAYER_VIEW_MUTE, false); |
|---|
| 298 | addComponentButton('mute', ViewEvent.JWPLAYER_VIEW_MUTE, true); |
|---|
| 299 | addTextField('elapsed'); |
|---|
| 300 | addTextField('duration'); |
|---|
| 301 | addSlider('time', Slider.HORIZONTAL, ViewEvent.JWPLAYER_VIEW_CLICK, seekHandler); |
|---|
| 302 | addSlider('volume', Slider.HORIZONTAL, ViewEvent.JWPLAYER_VIEW_CLICK, volumeHandler); |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | private function addComponentButton(name:String, event:String, eventData:*=null):void { |
|---|
| 307 | var button:ComponentButton = new ComponentButton(); |
|---|
| 308 | button.name = name; |
|---|
| 309 | button.setOutIcon(getSkinElement(name + "Button")); |
|---|
| 310 | button.setOverIcon(getSkinElement(name + "ButtonOver")); |
|---|
| 311 | button.setBackground(getSkinElement(name + "ButtonBack")); |
|---|
| 312 | button.outColor = player.config.lightcolor; |
|---|
| 313 | button.overColor = player.config.backcolor; |
|---|
| 314 | button.clickFunction = function():void { |
|---|
| 315 | forward(new ViewEvent(event, eventData)); |
|---|
| 316 | } |
|---|
| 317 | if (getSkinElement(name + "Button") || getSkinElement(name + "ButtonOver") || getSkinElement(name + "ButtonBack")) { |
|---|
| 318 | button.init(); |
|---|
| 319 | addButtonDisplayObject(button, name); |
|---|
| 320 | } |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | private function addSlider(name:String, orientation:String, event:String, callback:Function):void { |
|---|
| 325 | var slider:Slider = new Slider(getSkinElement(name + "SliderRail") as Sprite, getSkinElement(name + "SliderBuffer") as Sprite, getSkinElement(name + "SliderProgress") as Sprite, getSkinElement(name + "SliderThumb") as Sprite, orientation); |
|---|
| 326 | slider.addEventListener(event, callback); |
|---|
| 327 | slider.name = name; |
|---|
| 328 | _buttons[name] = slider; |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | private function addTextField(name:String):void { |
|---|
| 333 | var textFormat:TextFormat = new TextFormat(); |
|---|
| 334 | textFormat.font = "_sans"; |
|---|
| 335 | textFormat.size = 10; |
|---|
| 336 | textFormat.bold = true; |
|---|
| 337 | textFormat.color = player.config.frontcolor.color; |
|---|
| 338 | var textField:TextField = new TextField(); |
|---|
| 339 | textField.defaultTextFormat = textFormat; |
|---|
| 340 | textField.selectable = false; |
|---|
| 341 | textField.autoSize = TextFieldAutoSize.LEFT; |
|---|
| 342 | textField.name = name; |
|---|
| 343 | addChild(textField); |
|---|
| 344 | _buttons[name] = textField; |
|---|
| 345 | } |
|---|
| 346 | |
|---|
| 347 | |
|---|
| 348 | private function forward(evt:ViewEvent):void { |
|---|
| 349 | dispatchEvent(evt); |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | |
|---|
| 353 | private function volumeHandler(evt:ViewEvent):void { |
|---|
| 354 | var volume:Number = Math.round(evt.data * 100); |
|---|
| 355 | if (!_player.locked) { |
|---|
| 356 | var volumeEvent:MediaEvent = new MediaEvent(MediaEvent.JWPLAYER_MEDIA_VOLUME); |
|---|
| 357 | volumeEvent.volume = volume; |
|---|
| 358 | updateVolumeSlider(volumeEvent); |
|---|
| 359 | } |
|---|
| 360 | dispatchEvent(new ViewEvent(ViewEvent.JWPLAYER_VIEW_VOLUME, volume)); |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | |
|---|
| 364 | private function seekHandler(evt:ViewEvent):void { |
|---|
| 365 | var duration:Number = 0; |
|---|
| 366 | try { |
|---|
| 367 | duration = player.playlist.currentItem.duration; |
|---|
| 368 | } catch (err:Error) { |
|---|
| 369 | } |
|---|
| 370 | var percent:Number = Math.round(duration * evt.data); |
|---|
| 371 | dispatchEvent(new ViewEvent(ViewEvent.JWPLAYER_VIEW_SEEK, percent)); |
|---|
| 372 | } |
|---|
| 373 | |
|---|
| 374 | private function addButtonDisplayObject(icon:DisplayObject, name:String, handler:Function=null):MovieClip { |
|---|
| 375 | if (icon) { |
|---|
| 376 | var clipMC:MovieClip = new MovieClip(); |
|---|
| 377 | if (handler != null) { |
|---|
| 378 | clipMC.addEventListener(MouseEvent.CLICK, handler); |
|---|
| 379 | } |
|---|
| 380 | clipMC.name = name; |
|---|
| 381 | clipMC.addChild(icon); |
|---|
| 382 | _buttons[name] = clipMC; |
|---|
| 383 | return clipMC; |
|---|
| 384 | } |
|---|
| 385 | return null; |
|---|
| 386 | } |
|---|
| 387 | |
|---|
| 388 | |
|---|
| 389 | public function addButton(icon:DisplayObject, name:String, handler:Function=null):MovieClip { |
|---|
| 390 | _defaultLayout = _defaultLayout.replace("|blank", "|blank|" + name); |
|---|
| 391 | return addButtonDisplayObject(icon, name, handler); |
|---|
| 392 | } |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | |
|---|
| 396 | |
|---|
| 397 | |
|---|
| 398 | public function removeButton(name:String):void { |
|---|
| 399 | _buttons[name] = null; |
|---|
| 400 | redraw(); |
|---|
| 401 | } |
|---|
| 402 | |
|---|
| 403 | |
|---|
| 404 | private function hideButton(name:String):void { |
|---|
| 405 | if (_buttons[name]) { |
|---|
| 406 | _buttons[name].visible = false; |
|---|
| 407 | } |
|---|
| 408 | } |
|---|
| 409 | |
|---|
| 410 | |
|---|
| 411 | public function getButton(buttonName:String):DisplayObject { |
|---|
| 412 | if (buttonName == "divider") { |
|---|
| 413 | var divider:DisplayObject = getSkinElement("divider"); |
|---|
| 414 | if (divider) { |
|---|
| 415 | _dividers.push(divider); |
|---|
| 416 | } |
|---|
| 417 | return divider; |
|---|
| 418 | } |
|---|
| 419 | return _buttons[buttonName]; |
|---|
| 420 | } |
|---|
| 421 | |
|---|
| 422 | public function getSlider(sliderName:String):Slider { |
|---|
| 423 | return getButton(sliderName) as Slider; |
|---|
| 424 | } |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | public function resize(width:Number, height:Number):void { |
|---|
| 428 | _width = width; |
|---|
| 429 | |
|---|
| 430 | if (getConfigParam('position') == 'over' || _player.fullscreen == true) { |
|---|
| 431 | player.config.pluginConfig("controlbar")['x'] = getConfigParam('margin'); |
|---|
| 432 | player.config.pluginConfig("controlbar")['y'] = height - background.height - getConfigParam('margin'); |
|---|
| 433 | _width = width - 2 * getConfigParam('margin'); |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | //shade.width = _width; |
|---|
| 437 | |
|---|
| 438 | var backgroundWidth:Number = _width; |
|---|
| 439 | |
|---|
| 440 | backgroundWidth -= capLeft.width; |
|---|
| 441 | capLeft.x = 0; |
|---|
| 442 | |
|---|
| 443 | backgroundWidth -= capRight.width; |
|---|
| 444 | capRight.x = _width - capRight.width; |
|---|
| 445 | |
|---|
| 446 | background.width = backgroundWidth; |
|---|
| 447 | background.x = capLeft.width; |
|---|
| 448 | setChildIndex(capLeft, numChildren - 1); |
|---|
| 449 | setChildIndex(capRight, numChildren - 1); |
|---|
| 450 | |
|---|
| 451 | updateControlbarState(); |
|---|
| 452 | redraw(); |
|---|
| 453 | Mouse.show(); |
|---|
| 454 | } |
|---|
| 455 | |
|---|
| 456 | |
|---|
| 457 | private function redraw():void { |
|---|
| 458 | clearDividers(); |
|---|
| 459 | _layoutManager.resize(_width, _height); |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | |
|---|
| 463 | private function clearDividers():void { |
|---|
| 464 | for (var i:Number = 0; i < _dividers.length; i++) { |
|---|
| 465 | _dividers[i].visible = false; |
|---|
| 466 | _dividers[i] = null; |
|---|
| 467 | } |
|---|
| 468 | _dividers = []; |
|---|
| 469 | } |
|---|
| 470 | |
|---|
| 471 | |
|---|
| 472 | public function get layout():String { |
|---|
| 473 | return _currentLayout; |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | |
|---|
| 477 | private function getFont(textField:TextField):String { |
|---|
| 478 | var result:String; |
|---|
| 479 | if (textField) { |
|---|
| 480 | textField.getTextFormat().font; |
|---|
| 481 | } |
|---|
| 482 | return result; |
|---|
| 483 | } |
|---|
| 484 | |
|---|
| 485 | |
|---|
| 486 | private function get background():DisplayObject { |
|---|
| 487 | if (_buttons['background']) { |
|---|
| 488 | return _buttons['background']; |
|---|
| 489 | } |
|---|
| 490 | return (new Sprite()); |
|---|
| 491 | } |
|---|
| 492 | |
|---|
| 493 | |
|---|
| 494 | /*private function get shade():DisplayObject { |
|---|
| 495 | if (_buttons['shade']) { |
|---|
| 496 | return _buttons['shade']; |
|---|
| 497 | } |
|---|
| 498 | return (new Sprite()); |
|---|
| 499 | }*/ |
|---|
| 500 | |
|---|
| 501 | private function get capLeft():DisplayObject { |
|---|
| 502 | if (_buttons['capLeft']) { |
|---|
| 503 | return _buttons['capLeft']; |
|---|
| 504 | } |
|---|
| 505 | return (new Sprite()); |
|---|
| 506 | } |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | private function get capRight():DisplayObject { |
|---|
| 510 | if (_buttons['capRight']) { |
|---|
| 511 | return _buttons['capRight']; |
|---|
| 512 | } |
|---|
| 513 | return (new Sprite()); |
|---|
| 514 | } |
|---|
| 515 | } |
|---|
| 516 | } |
|---|