Changeset 4 for trunk/as3/com/jeroenwijering/views/PlaylistView.as
- Timestamp:
- 06/06/08 13:11:42 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/as3/com/jeroenwijering/views/PlaylistView.as
r3 r4 7 7 import com.jeroenwijering.events.*; 8 8 import com.jeroenwijering.player.View; 9 import com.jeroenwijering.utils.Draw; 9 import com.jeroenwijering.utils.*; 10 import flash.display.Loader; 10 11 import flash.display.MovieClip; 12 import flash.events.Event; 11 13 import flash.events.MouseEvent; 12 14 import flash.geom.Rectangle; 15 import flash.net.URLRequest; 13 16 import flash.utils.setInterval; 14 17 import flash.utils.clearInterval; … … 25 28 private var buttons:Array; 26 29 /** Height of a button (to calculate scrolling) **/ 27 private var buttonsize:Number; 30 private var buttonheight:Number; 31 /** Currently active button. **/ 32 private var active:Number; 28 33 /** Proportion between clip and mask. **/ 29 34 private var proportion:Number; … … 34 39 public function PlaylistView(vie:View) { 35 40 view = vie; 36 clip = view.skin['playlist'];37 clip.visible = false;38 41 view.addControllerListener(ControllerEvent.ITEM,itemHandler); 39 42 view.addControllerListener(ControllerEvent.PLAYLIST,playlistHandler); 40 43 view.addControllerListener(ControllerEvent.RESIZE,resizeHandler); 41 buttonsize = clip.scrollClip.getChildByName('button').height; 42 clip.list.mask = clip.scrollMask; 44 view.addModelListener(ModelEvent.STATE,stateHandler); 45 clip = view.skin['playlist']; 46 buttonheight = clip.list.button.height; 47 clip.list.button.visible = false; 48 clip.list.mask = clip.masker; 43 49 clip.slider.buttonMode = true; 44 50 clip.slider.mouseChildren = false; 51 clip.list.addEventListener(MouseEvent.CLICK,clickHandler); 52 clip.list.addEventListener(MouseEvent.MOUSE_OVER,overHandler); 53 clip.list.addEventListener(MouseEvent.MOUSE_OUT,outHandler); 54 clip.list.addEventListener(MouseEvent.MOUSE_UP,stopHandler); 45 55 clip.slider.addEventListener(MouseEvent.MOUSE_DOWN,startHandler); 46 view.skin.addEventListener(MouseEvent.MOUSE_UP,stopHandler); 56 clip.visible = false; 57 trace(clip); 47 58 }; 48 59 … … 52 63 var wid = clip.back.width; 53 64 var hei = clip.back.height; 54 proportion = view.playlist.length*button size/hei;65 proportion = view.playlist.length*buttonheight/hei; 55 66 if (proportion > 1) { 56 67 wid -=20; 57 buildS croller();68 buildSlider(); 58 69 } else { 59 clip.s crollBar.visible = false;60 } 61 clip. scrollMask.height = hei;62 clip. scrollMask.width = wid;70 clip.slider.visible = false; 71 } 72 clip.masker.height = hei; 73 clip.masker.width = wid; 63 74 if(clr) { 64 clip. scrollClip.y = 0;65 Draw.clear(clip. scrollClip);75 clip.list.y = 0; 76 Draw.clear(clip.list); 66 77 buttons = new Array(); 78 clip.visible= true; 79 } else { 80 if(proportion > 1) { scrollCheck(); } 67 81 } 68 82 for(var i=0; i<view.playlist.length; i++) { 69 if(clr) { 70 var btn = Draw.clone(clip.scrollClip.getChildByName('button')); 71 // new PlaylistButton(i,wid,view); 72 clip.scrollClip.addChild(btn); 73 buttons.push(btn); 74 } else { 75 buttons[i].resize(wid); 76 if(proportion > 1) { 77 scrollCheck(); 78 } 79 } 83 if(clr) { 84 var btn = Draw.clone(clip.list.button); 85 clip.list.addChild(btn); 86 var stc = new Stacker(btn); 87 btn.y = i*buttonheight; 88 btn.buttonMode = true; 89 btn.mouseChildren =false; 90 btn.name = i; 91 buttons.push({c:btn,s:stc}); 92 setContents(i); 93 } 94 buttons[i].s.rearrange(wid); 80 95 } 81 96 }; … … 83 98 84 99 /** Setup the scrollbar component **/ 85 private function buildS croller() {86 var scr = clip.s crollBar;100 private function buildSlider() { 101 var scr = clip.slider; 87 102 scr.visible = true; 88 scr.x = clip.back.width -scr.width;89 var dif = clip.back.height -scr.height;103 scr.x = clip.back.width-scr.width; 104 var dif = clip.back.height-scr.height; 90 105 scr.back.height += dif; 91 106 scr.rail.height += dif; … … 94 109 95 110 111 /** Handle a click on a button. **/ 112 private function clickHandler(evt:MouseEvent) { 113 view.sendEvent('item',Number(evt.target.name)); 114 }; 115 116 96 117 /** Switch the currently active item */ 97 118 private function itemHandler(evt:ControllerEvent) { 98 // code for highlighting a certain button. 119 var idx = evt.data.index; 120 if(!isNaN(active)) { 121 buttons[active].c.gotoAndStop('out'); 122 } 123 buttons[idx].c.gotoAndStop('active'); 124 active = idx; 125 }; 126 127 128 /** Loading of image completed; resume loading **/ 129 private function loaderHandler(evt:Event) { 130 var ldr = Loader(evt.target.loader); 131 Stretcher.stretch(ldr,ldr.mask.width,ldr.mask.height,Stretcher.FILL); 132 }; 133 134 135 /** Handle a button rollover. **/ 136 private function overHandler(evt:MouseEvent) { 137 var idx = Number(evt.target.name); 138 buttons[idx].c.gotoAndStop('over'); 139 }; 140 141 142 /** Handle a button rollover. **/ 143 private function outHandler(evt:MouseEvent) { 144 var idx = Number(evt.target.name); 145 if(idx == active) { 146 buttons[idx].c.gotoAndStop('active'); 147 } else { 148 buttons[idx].c.gotoAndStop('out'); 149 } 99 150 }; 100 151 … … 102 153 /** New playlist loaded: rebuild the playclip. **/ 103 154 private function playlistHandler(evt:ControllerEvent) { 104 buildList(true); 155 if(view.config['playlist'] != 'none') { 156 buildList(true); 157 } 105 158 }; 106 159 … … 109 162 private function resizeHandler(evt:ControllerEvent) { 110 163 if(view.config['playlist'] == 'right') { 111 clip.visible = true;112 164 clip.x = evt.data.width; 113 165 clip.y = 0; 114 166 clip.back.width = view.config['playlistsize']; 115 167 clip.back.height = evt.data.height; 116 } else if (view.config['playlist'] == 'below') { 117 clip.visible = true; 168 } else if (view.config['playlist'] == 'bottom') { 118 169 clip.x = 0; 119 170 clip.y = evt.data.height; 120 if (view.config['controlbar'] == 'b elow') {171 if (view.config['controlbar'] == 'bottom') { 121 172 clip.y += view.config['controlbarsize']; 122 173 } 123 174 clip.back.height = view.config['playlistsize']; 124 175 clip.back.width = evt.data.width; 125 } else if (view.config['playlist'] == 'above') { 126 clip.visible = true; 127 var wid = evt.data.width-2*view.config['controlbarsize']; 128 var hei = evt.data.height-2*view.config['controlbarsize']; 129 if(evt.data.width > 640) { wid = 600; } 130 if(view.config['controlbar'] == 'above') { hei -= 2*view.config['controlbarsize']; } 131 clip.x = Math.round(evt.data.width/2 - wid/2); 132 clip.y = view.config['controlbarsize']; 133 clip.back.height = hei; 134 clip.back.width = wid; 135 } else { 136 clip.visible = false; 176 } else if (view.config['playlist'] == 'over') { 177 clip.x = clip.y = 0; 178 clip.back.height = evt.data.height; 179 clip.back.width = evt.data.width; 137 180 } 138 181 buildList(false); … … 142 185 /** Make sure the playlist is not out of range. **/ 143 186 private function scrollCheck() { 144 var scr = clip.s crollBar;145 if(clip. scrollClip.y > 0) {146 clip. scrollClip.y = 0;187 var scr = clip.slider; 188 if(clip.list.y > 0) { 189 clip.list.y = 0; 147 190 scr.icon.y = scr.rail.y; 148 } else if (clip. scrollClip.y < clip.scrollMask.height-clip.scrollClip.height) {191 } else if (clip.list.y < clip.masker.height-clip.list.height) { 149 192 scr.icon.y = scr.rail.y+scr.rail.height-scr.icon.height; 150 clip. scrollClip.y = clip.scrollMask.height-clip.scrollClip.height;193 clip.list.y = clip.masker.height-clip.list.height; 151 194 } 152 195 }; … … 155 198 /** Scrolling handler. **/ 156 199 private function scrollHandler() { 157 var scr = clip.s crollBar;200 var scr = clip.slider; 158 201 var yps = scr.mouseY; 159 202 var ips = yps - scr.icon.height/2; 160 var cps = clip. scrollMask.y+clip.scrollMask.height/2-proportion*yps;203 var cps = clip.masker.y+clip.masker.height/2-proportion*yps; 161 204 scr.icon.y = Math.round(ips - (ips-scr.icon.y)/1.5); 162 clip. scrollClip.y = Math.round((cps - (cps-clip.scrollClip.y)/1.5));205 clip.list.y = Math.round((cps - (cps-clip.list.y)/1.5)); 163 206 scrollCheck(); 207 }; 208 209 210 /** Setup button elements **/ 211 private function setContents(idx:Number) { 212 for (var itm in view.playlist[idx]) { 213 if(!buttons[idx].c[itm]) { 214 continue; 215 } else if(itm == 'image') { 216 var ldr = new Loader(); 217 buttons[idx].c.addChild(ldr); 218 ldr.x = buttons[idx].c.image.x; 219 ldr.y = buttons[idx].c.image.y; 220 ldr.mask = buttons[idx].c.image; 221 ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderHandler); 222 ldr.load(new URLRequest(view.playlist[idx]['image'])); 223 } else if(itm == 'duration') { 224 if(view.playlist[idx][itm] > 0) { 225 buttons[idx].c[itm].field.text = Strings.digits(view.playlist[idx][itm]); 226 } 227 } else { 228 buttons[idx].c[itm].field.text = view.playlist[idx][itm]; 229 } 230 } 231 if(!view.playlist[idx]['image'] && buttons[idx].c['image']) { 232 buttons[idx].c['image'].visible = false; 233 } 164 234 }; 165 235 … … 172 242 }; 173 243 244 /** Process state changes **/ 245 private function stateHandler(evt:ModelEvent) { 246 if(view.config['playlist'] == 'over') { 247 if(evt.data.newstate == ModelStates.PLAYING || evt.data.newstate == ModelStates.BUFFERING) { 248 clip.visible = false; 249 } else { 250 clip.visible = true; 251 } 252 } 253 }; 254 174 255 175 256 /** Stop scrolling the playlist. **/ … … 179 260 180 261 181 182 183 262 }; 184 263
Note: See TracChangeset
for help on using the changeset viewer.
