| 1 | /** |
|---|
| 2 | * Shows a bar that can be dragged to resize the playlist. |
|---|
| 3 | **/ |
|---|
| 4 | package com.jeroenwijering.plugins { |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | import com.jeroenwijering.events.*; |
|---|
| 8 | import flash.display.MovieClip; |
|---|
| 9 | import flash.events.MouseEvent; |
|---|
| 10 | import flash.geom.Rectangle; |
|---|
| 11 | import flash.utils.setInterval; |
|---|
| 12 | import flash.utils.clearInterval; |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | public class Resizer extends MovieClip implements PluginInterface { |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | /** Reference to the View of the player. **/ |
|---|
| 19 | private var view:AbstractView; |
|---|
| 20 | /** Reference to the graphics. **/ |
|---|
| 21 | private var clip:MovieClip; |
|---|
| 22 | /** Resizing interval. **/ |
|---|
| 23 | private var interval:Number; |
|---|
| 24 | /** initialize call for backward compatibility. **/ |
|---|
| 25 | public var initialize:Function = initializePlugin; |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | /** Set internal handlers on init. **/ |
|---|
| 29 | public function Resizer() { |
|---|
| 30 | clip = this; |
|---|
| 31 | clip.resizeBar.buttonMode = true; |
|---|
| 32 | clip.resizeBar.mouseChildren = false; |
|---|
| 33 | clip.resizeBar.addEventListener(MouseEvent.MOUSE_DOWN,downHandler); |
|---|
| 34 | }; |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | /** Set the new playlistsize and redraw the stage. **/ |
|---|
| 38 | private function doResize() { |
|---|
| 39 | var pls = clip.stage.stageWidth-clip.mouseX-view.config['margins'].split(',')[0]; |
|---|
| 40 | view.config['playlistsize'] = pls; |
|---|
| 41 | view.sendEvent('REDRAW'); |
|---|
| 42 | }; |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | /** Start dragging when mouse is down. **/ |
|---|
| 46 | private function downHandler(evt:MouseEvent):void { |
|---|
| 47 | interval = setInterval(doResize,50); |
|---|
| 48 | }; |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | /** The initialize call is invoked by the player View. **/ |
|---|
| 52 | public function initializePlugin(vie:AbstractView):void { |
|---|
| 53 | view = vie; |
|---|
| 54 | view.addControllerListener(ControllerEvent.RESIZE,resizeHandler); |
|---|
| 55 | clip.stage.addEventListener(MouseEvent.MOUSE_UP,upHandler); |
|---|
| 56 | resizeHandler(); |
|---|
| 57 | }; |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | /** Handle a resize. **/ |
|---|
| 61 | private function resizeHandler(evt:ControllerEvent=undefined) { |
|---|
| 62 | clip.resizeBar.x = view.config['width']; |
|---|
| 63 | clip.resizeBar.height = view.config['height']; |
|---|
| 64 | }; |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | /** Stop dragging when mouse is up again. **/ |
|---|
| 68 | private function upHandler(evt:MouseEvent):void { |
|---|
| 69 | clearInterval(interval); |
|---|
| 70 | }; |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | } |
|---|