source: trunk/as3/com/jeroenwijering/views/PlaylistView.as @ 3

Revision 3, 5.0 KB checked in by jeroen, 5 years ago (diff)

added js initer BUT destroyed controlbar display

  • Property svn:executable set to *
Line 
1/**
2* Display a searchbar and direct the search externally.
3**/
4package com.jeroenwijering.views {
5
6
7import com.jeroenwijering.events.*;
8import com.jeroenwijering.player.View;
9import com.jeroenwijering.utils.Draw;
10import flash.display.MovieClip;
11import flash.events.MouseEvent;
12import flash.geom.Rectangle;
13import flash.utils.setInterval;
14import flash.utils.clearInterval;
15
16
17public class PlaylistView {
18
19
20        /** Reference to the view. **/
21        private var view:View;
22        /** Reference to the playlist MC. **/
23        private var clip:MovieClip;
24        /** Array with all button instances **/
25        private var buttons:Array;
26        /** Height of a button (to calculate scrolling) **/
27        private var buttonsize:Number;
28        /** Proportion between clip and mask. **/
29        private var proportion:Number;
30        /** Interval ID for scrolling **/
31        private var scrollInterval:Number;
32
33
34        public function PlaylistView(vie:View) {
35                view = vie;
36                clip = view.skin['playlist'];
37                clip.visible = false;
38                view.addControllerListener(ControllerEvent.ITEM,itemHandler);
39                view.addControllerListener(ControllerEvent.PLAYLIST,playlistHandler);
40                view.addControllerListener(ControllerEvent.RESIZE,resizeHandler);
41                buttonsize = clip.scrollClip.getChildByName('button').height;
42                clip.list.mask = clip.scrollMask;
43                clip.slider.buttonMode = true;
44                clip.slider.mouseChildren = false;
45                clip.slider.addEventListener(MouseEvent.MOUSE_DOWN,startHandler);
46                view.skin.addEventListener(MouseEvent.MOUSE_UP,stopHandler);
47        };
48
49
50        /** Setup all buttons in the playlist **/
51        private function buildList(clr:Boolean) {
52                var wid = clip.back.width;
53                var hei = clip.back.height;
54                proportion = view.playlist.length*buttonsize/hei;
55                if (proportion > 1) {
56                        wid -=20;
57                        buildScroller();
58                } else {
59                        clip.scrollBar.visible = false;
60                }
61                clip.scrollMask.height = hei;
62                clip.scrollMask.width = wid;
63                if(clr) {
64                        clip.scrollClip.y = 0;
65                        Draw.clear(clip.scrollClip);
66                        buttons = new Array();
67                }
68                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                        }
80                }
81        };
82
83
84        /** Setup the scrollbar component **/
85        private function buildScroller() {
86                var scr = clip.scrollBar;
87                scr.visible = true;
88                scr.x = clip.back.width - scr.width;
89                var dif = clip.back.height - scr.height;
90                scr.back.height += dif;
91                scr.rail.height += dif;
92                scr.icon.height = Math.round(scr.rail.height/proportion);
93        };
94
95
96        /** Switch the currently active item */
97        private function itemHandler(evt:ControllerEvent) {
98                // code for highlighting a certain button.
99        };
100
101
102        /** New playlist loaded: rebuild the playclip. **/
103        private function playlistHandler(evt:ControllerEvent) {
104                buildList(true);
105        };
106
107
108        /** Process resizing requests **/
109        private function resizeHandler(evt:ControllerEvent) {
110                if(view.config['playlist'] == 'right') {
111                        clip.visible = true;
112                        clip.x = evt.data.width;
113                        clip.y = 0;
114                        clip.back.width = view.config['playlistsize'];
115                        clip.back.height = evt.data.height;
116                } else if (view.config['playlist'] == 'below') {
117                        clip.visible = true;
118                        clip.x = 0;
119                        clip.y = evt.data.height;
120                        if (view.config['controlbar'] == 'below') {
121                                clip.y += view.config['controlbarsize'];
122                        }
123                        clip.back.height = view.config['playlistsize'];
124                        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;
137                }
138                buildList(false);
139        };
140
141
142        /** Make sure the playlist is not out of range. **/
143        private function scrollCheck() {
144                var scr = clip.scrollBar;
145                if(clip.scrollClip.y > 0) {
146                        clip.scrollClip.y = 0;
147                        scr.icon.y = scr.rail.y;
148                } else if (clip.scrollClip.y < clip.scrollMask.height-clip.scrollClip.height) {
149                        scr.icon.y = scr.rail.y+scr.rail.height-scr.icon.height;
150                        clip.scrollClip.y = clip.scrollMask.height-clip.scrollClip.height;
151                }
152        };
153
154
155        /** Scrolling handler. **/
156        private function scrollHandler() {
157                var scr = clip.scrollBar;
158                var yps = scr.mouseY;
159                var ips = yps - scr.icon.height/2;
160                var cps = clip.scrollMask.y+clip.scrollMask.height/2-proportion*yps;
161                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));
163                scrollCheck();
164        };
165
166
167        /** Start scrolling the playlist. **/
168        private function startHandler(evt:MouseEvent) {
169                clearInterval(scrollInterval);
170                scrollHandler();
171                scrollInterval = setInterval(scrollHandler,50);
172        };
173
174
175        /** Stop scrolling the playlist. **/
176        private function stopHandler(evt:MouseEvent) {
177                clearInterval(scrollInterval);
178        };
179
180
181
182
183};
184
185
186}
Note: See TracBrowser for help on using the repository browser.