root/trunk/as3/com/jeroenwijering/views/PlaylistButton.as @ 1

Revision 1, 2.4 kB (checked in by jeroen, 18 months ago)

initial commit of old repository into public one

Line 
1/**
2* Placeholder class for a playlistbutton.
3**/
4package com.jeroenwijering.views {
5
6
7import com.jeroenwijering.player.View;
8import com.jeroenwijering.utils.*;
9import flash.display.Loader;
10import flash.display.MovieClip;
11import flash.events.Event;
12import flash.events.MouseEvent;
13import flash.net.URLRequest;
14import flash.text.TextField;
15
16
17
18public class PlaylistButton extends MovieClip {
19
20
21        /** Playlist index of this button. **/
22        private var index:Number;
23        /** Reference to the view (to access config & playlist). **/
24        private var view:View;
25        /** Loader for loading the thumbnail. **/
26        private var loader:Loader;
27        /** Maximum width of the button. **/
28        private var buttonsize:Number;
29
30
31        /** Constructor; saves vars. **/
32        public function PlaylistButton(idx:Number=undefined,wid:Number=undefined,vie:View=undefined) {
33                super();
34                index = idx;
35                buttonsize = back.width;
36                view = vie;
37                if(view) {
38                        resize(wid);
39                        setElements();
40                }
41        };
42
43
44        /** Setup button elements **/
45        private function setElements() {
46                this.y = this.height*index;
47                if(title && view.playlist[index]['title']) {
48                        title.tf.text = Strings.fit(view.playlist[index]['title'],title.tf);
49                }
50                if(description && view.playlist[index]['description']) {
51                        var dsc = Strings.strip(view.playlist[index]['description']);
52                        description.tf.text = Strings.fit(dsc,description.tf);
53                }
54                if(view.playlist[index]['duration'] > 0) {
55                        duration.tf.text = Strings.digits(view.playlist[index]['duration']);
56                } else {
57                        duration.visible = false;
58                }
59                if(view.playlist[index]['image']) {
60                        loader = new Loader();
61                        loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderHandler);
62                        loader.load(new URLRequest(view.playlist[index]['image']));
63                }
64                buttonMode = true;
65                mouseChildren =false;
66                addEventListener(MouseEvent.CLICK,clickHandler);
67                resize(buttonsize);
68        };
69
70
71        /** Loading of image completed; resume loading **/
72        private function loaderHandler(evt:Event) {
73                var itm = addChild(loader);
74                Stretcher.stretch(itm,image.width,image.height,Stretcher.FILL);
75                itm.mask = image;
76        }
77
78
79        /** Handle a click on the button. **/
80        private function clickHandler(evt:MouseEvent) {
81                view.sendEvent('item',index);
82        };
83
84
85        /** Resize the button if the stage changes **/
86        public function resize(wid:Number) {
87                var dif = wid - buttonsize;
88                buttonsize = wid;
89                back.width = buttonsize;
90                duration.x = buttonsize - duration.width;
91                title.tf.width += dif;
92                description.tf.width += dif;
93        };
94
95
96};
97
98
99}
Note: See TracBrowser for help on using the browser.