root/trunk/as2/com/jeroenwijering/players/EqualizerView.as @ 1

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

initial commit of old repository into public one

  • Property svn:executable set to *
Line 
1/**
2* View for an actionscript-drawn equalizer (thanks to Brewer).
3* The eq. is fake, but it considers playstate and volume.
4*
5* @author       Jeroen Wijering
6* @version      1.1
7**/
8
9
10import com.jeroenwijering.players.*;
11
12
13class com.jeroenwijering.players.EqualizerView extends AbstractView {
14
15
16        /** EQ movieclip reference **/
17        private var eqClip:MovieClip;
18        /** current volume **/
19        private var currentVolume:Number;
20        /** number of stripes to display in the EQ **/
21        private var eqStripes:Number;
22
23
24        /** Constructor; just inheriting. **/
25        function EqualizerView(ctr:AbstractController,cfg:Object,fed:Object) {
26                super(ctr,cfg,fed);
27                setupEQ();
28                Stage.addListener(this);
29        };
30
31
32        /** setup EQ **/
33        private function setupEQ() {
34                eqClip = config["clip"].equalizer;
35                eqClip._y = config["displayheight"] - 50;
36                eqStripes = Math.floor((config['displaywidth'] - 20)/6);
37                eqClip.stripes.duplicateMovieClip("stripes2",1);
38                eqClip.mask.duplicateMovieClip("mask2",3);
39                eqClip.stripes._width = eqClip.stripes2._width =
40                        config['displaywidth']-20;
41                eqClip.stripes.top.col = new Color(eqClip.stripes.top);
42                eqClip.stripes.top.col.setRGB(config['lightcolor']);
43                eqClip.stripes.bottom.col = new Color(eqClip.stripes.bottom);
44                eqClip.stripes.bottom.col.setRGB(0xFFFFFF);
45                eqClip.stripes2.top.col = new Color(eqClip.stripes2.top);
46                eqClip.stripes2.top.col.setRGB(config['lightcolor']);
47                eqClip.stripes2.bottom.col = new Color(eqClip.stripes2.bottom);
48                eqClip.stripes2.bottom.col.setRGB(0xFFFFFF);
49                eqClip.stripes.setMask(eqClip.mask);
50                eqClip.stripes2.setMask(eqClip.mask2);
51                eqClip.stripes._alpha = eqClip.stripes2._alpha = 50;
52                setInterval(this,"drawEqualizer",100,eqClip.mask);
53                setInterval(this,"drawEqualizer",100,eqClip.mask2);
54        };
55
56
57        /** Draw a random frame for the equalizer **/
58        private function drawEqualizer(tgt:MovieClip) {
59                tgt.clear();
60            tgt.beginFill(0x000000, 100);
61                tgt.moveTo(0,0);
62                var h = Math.round(currentVolume/4);
63                for (var j=0; j< eqStripes; j++) {
64                        var z = random(h)+h/2 + 2;
65                        if(j == Math.floor(eqStripes/2)) { z = 0; }
66                        tgt.lineTo(j*6,-1);
67                        tgt.lineTo(j*6,-z);
68                        tgt.lineTo(j*6+4,-z);
69                        tgt.lineTo(j*6+4,-1);
70                        tgt.lineTo(j*6,-1);
71                }
72                tgt.lineTo(eqStripes*6,0);
73                tgt.lineTo(0,0);
74                tgt.endFill();
75        };
76
77
78        /** Change the height to reflect the volume **/
79        private function setVolume(vol:Number) { currentVolume = vol; };
80
81
82        /** Only display the eq if a song is playing **/
83        private function setState(stt:Number) {
84                stt == 2 ? eqClip._visible = true: eqClip._visible = false;
85        };
86
87
88        /** Hide the EQ on fullscreen view  **/
89        public function onFullScreen(fs:Boolean) {
90                if(fs == true) {
91                        eqClip._visible = false;
92                } else {
93                        eqClip._visible = true;
94                }
95        };
96
97
98}
Note: See TracBrowser for help on using the browser.