| 1 | package com.jeroenwijering.plugins { |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | import com.jeroenwijering.events.*; |
|---|
| 5 | import flash.display.MovieClip; |
|---|
| 6 | import flash.events.MouseEvent; |
|---|
| 7 | import flash.geom.Rectangle; |
|---|
| 8 | |
|---|
| 9 | public class PlaylistResizer extends MovieClip implements PluginInterface { |
|---|
| 10 | |
|---|
| 11 | /** Reference to the View of the player. **/ |
|---|
| 12 | private var view:AbstractView; |
|---|
| 13 | /** Reference to the graphics. **/ |
|---|
| 14 | private var clip:MovieClip; |
|---|
| 15 | |
|---|
| 16 | private var _dragging:Boolean = false; |
|---|
| 17 | |
|---|
| 18 | public function PlaylistResizer() { |
|---|
| 19 | clip = this; |
|---|
| 20 | clip.resizeBar.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown); |
|---|
| 21 | clip.addEventListener(MouseEvent.MOUSE_MOVE, _onMouseMove); |
|---|
| 22 | clip.resizeBar.addEventListener(MouseEvent.MOUSE_UP, _onMouseUp); |
|---|
| 23 | clip.resizeBar.buttonMode = true; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | private function _onMouseDown(evt:MouseEvent):void { |
|---|
| 27 | clip.resizeBar.startDrag(false, new Rectangle(0,0,stage.stageWidth,0)) |
|---|
| 28 | _dragging = true; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | private function _onMouseUp(evt:MouseEvent):void { |
|---|
| 32 | clip.resizeBar.stopDrag(); |
|---|
| 33 | _dragging = false; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | /** The initialize call is invoked by the player View. **/ |
|---|
| 37 | public function initializePlugin(vie:AbstractView):void { |
|---|
| 38 | view = vie; |
|---|
| 39 | view.addControllerListener(ControllerEvent.RESIZE,resizeHandler); |
|---|
| 40 | view.addModelListener(ModelEvent.STATE,stateHandler); |
|---|
| 41 | resizeHandler(); |
|---|
| 42 | }; |
|---|
| 43 | |
|---|
| 44 | /** Close on video completed. **/ |
|---|
| 45 | private function stateHandler(evt:ModelEvent) { |
|---|
| 46 | switch(evt.data.newstate) { |
|---|
| 47 | case ModelStates.BUFFERING: |
|---|
| 48 | case ModelStates.PLAYING: |
|---|
| 49 | //clip.visible = false; |
|---|
| 50 | break; |
|---|
| 51 | default: |
|---|
| 52 | //clip.stage.focus = clip.query; |
|---|
| 53 | //clip.visible = true; |
|---|
| 54 | break; |
|---|
| 55 | } |
|---|
| 56 | }; |
|---|
| 57 | |
|---|
| 58 | /** Handle a resize. **/ |
|---|
| 59 | private function resizeHandler(evt:ControllerEvent=undefined) { |
|---|
| 60 | //do nothing yet |
|---|
| 61 | }; |
|---|
| 62 | |
|---|
| 63 | private function _onMouseMove(evt:MouseEvent):void { |
|---|
| 64 | if(_dragging) { |
|---|
| 65 | var s:Number = Math.round(stage.stageWidth - clip.resizeBar.x); |
|---|
| 66 | view.sendEvent('TRACE',s.toString()); |
|---|
| 67 | onPlaylistResize(s); |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | private function onPlaylistResize(newWidth:Number):void { |
|---|
| 72 | if(newWidth >= 25) { |
|---|
| 73 | trace("bigger"); |
|---|
| 74 | view.config['playlistsize'] = newWidth; |
|---|
| 75 | //if(this.player.view.config['playlist'] == 'none') this.player.view.config['playlist'] = 'right'; |
|---|
| 76 | } else { |
|---|
| 77 | trace("smaller"); |
|---|
| 78 | //this.player.view.config['playlist'] = 'none'; |
|---|
| 79 | } |
|---|
| 80 | //view.controller.resizeHandler(new Event(Event.RESIZE)); |
|---|
| 81 | //view.sendEvent('RESIZE', {height:view.config['height'], width:view.config['width']}); |
|---|
| 82 | view.sendEvent('RESIZE'); |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | } |
|---|