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

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

initial commit of old repository into public one

  • Property svn:executable set to *
Line 
1/**
2* Rotator extension of the controller.
3*
4* @author       Jeroen Wijering
5* @version      1.6
6**/
7
8
9import com.jeroenwijering.players.AbstractController;
10import com.jeroenwijering.utils.Randomizer;
11
12
13class com.jeroenwijering.players.RotatorController extends AbstractController{
14
15
16        /** Which one of the models to send the changes to **/
17        private var currentModel:Number;
18        /** use SharedObject to save current file, item and volume **/
19        private var playerSO:SharedObject;
20
21
22        /** Constructor, inherited from super **/
23        function RotatorController(car:Object,ply:Object) {
24                super(car,ply);
25                playerSO = SharedObject.getLocal("com.jeroenwijerin.players", "/");
26                if(playerSO.data.volume != undefined && _root.volume == undefined) {
27                        config["volume"] = playerSO.data.volume;
28                }
29                if(playerSO.data.useaudio != undefined &&
30                        _root.useaudio == undefined) {
31                        config["useaudio"] = playerSO.data.useaudio;
32                }
33        };
34
35
36        /** Complete the build of the MCV cycle and start flow of events. **/
37        public function startMCV(mar:Array) {
38                if(mar != undefined) { registeredModels = mar; }
39                itemsPlayed = 0;
40                if(config["shuffle"] == "true") {
41                        randomizer = new Randomizer(feeder.feed);
42                        currentItem = randomizer.pick();
43                } else {
44                        currentItem = 0;
45                }
46                sendChange("item",currentItem);
47                if(config["autostart"] == "false") {
48                        sendChange("start",0);
49                        sendChange("pause",0);
50                        isPlaying = false;
51                } else {
52                        sendChange("start",0);
53                        isPlaying = true;
54                }
55        };
56
57
58        /** PlayPause switch **/
59        private  function setPlaypause() {
60                if(isPlaying == true) {
61                        isPlaying = false;
62                        sendChange("pause");
63                } else {
64                        isPlaying = true;
65                        sendChange("start");
66                }
67        };
68
69
70        /** Play previous item. **/
71        private  function setPrev() {
72                if(currentItem == 0) {
73                        setPlayitem(feeder.feed.length - 1);
74                } else {
75                        setPlayitem(currentItem-1);
76                }
77        };
78
79
80        /** Play next item. **/
81        private function setNext() {
82                if(currentItem == feeder.feed.length - 1) {
83                        setPlayitem(0);
84                } else {
85                        setPlayitem(currentItem+1);
86                }
87        };
88
89
90        /** Stop and clear item. **/
91        private function setStop() {
92                sendChange("pause",0);
93                sendChange("stop");
94                sendChange("item",currentItem);
95                isPlaying = false;
96        };
97
98
99        /** Forward scrub number to model. **/
100        private function setScrub(prm) {
101                isPlaying == true ? sendChange("start",prm): sendChange("pause",prm);
102        };
103
104
105        /** Play a new item. **/
106        private function setPlayitem(itm:Number) {
107                if(itm != currentItem) {
108                        sendChange("stop");
109                        itm > feeder.feed.length-1 ? itm = feeder.feed.length-1: null;
110                        currentItem = itm;
111                        sendChange("item",itm);
112                }
113                if(feeder.feed[itm]["start"] == undefined) {
114                        sendChange("start",0);
115                } else {
116                        sendChange("start",feeder.feed[itm]["start"]);
117                }
118                currentURL = feeder.feed[itm]['file'];
119                isPlaying = true;
120        };
121
122
123        /** Get url from an item if link exists, else playpause. **/
124        private function setGetlink(idx:Number) {
125                if(feeder.feed[idx]["link"] == undefined) {
126                        setPlaypause();
127                } else {
128                        getURL(feeder.feed[idx]["link"],config["linktarget"]);
129                }
130        };
131
132
133        /** Determine what to do if an item is completed. **/
134        private function setComplete() {
135                itemsPlayed++;
136                if(config["repeat"]=="false" || (config["repeat"] == "list"
137                        && itemsPlayed >= feeder.feed.length)) {
138                        sendChange("pause",0);
139                        isPlaying = false;
140                        itemsPlayed = 0;
141                } else {
142                        if(config["shuffle"] == "true") {
143                                setPlayitem(randomizer.pick());
144                        } else if(currentItem == feeder.feed.length - 1) {
145                                setPlayitem(0);
146                        } else {
147                                setPlayitem(currentItem+1);
148                        }
149                }
150        };
151
152
153        /** Audiotrack toggle **/
154        private function setAudio() {
155                if(config["useaudio"] == "true") {
156                        config["useaudio"] = "false";
157                        config["clip"].audio.setStop();
158                        config["clip"].navigation.audioBtn.icnOff._visible = true;
159                        config["clip"].navigation.audioBtn.icnOn._visible = false;
160                } else {
161                        config["useaudio"] = "true";
162                        config["clip"].audio.setStart();
163                        config["clip"].navigation.audioBtn.icnOff._visible = false;
164                        config["clip"].navigation.audioBtn.icnOn._visible = true;
165                }
166                playerSO.data.useaudio = config["useaudio"];
167                playerSO.flush();
168        };
169
170
171        /** Switch active model and send changes. **/
172        private function sendChange(typ:String,prm:Number):Void {
173                if(typ == "item") {
174                        currentModel == 0 ? currentModel = 1: currentModel = 0;
175                }
176                registeredModels[currentModel].getChange(typ,prm);
177        };
178
179
180}
Note: See TracBrowser for help on using the browser.