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

Revision 1, 13.8 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 user interface View of the MCV cycle.
3*
4* @author       Jeroen Wijering
5* @version      1.5
6**/
7
8
9import com.jeroenwijering.players.*;
10import com.jeroenwijering.utils.ImageLoader;
11import com.jeroenwijering.utils.Animations;
12import flash.geom.Transform;
13import flash.geom.ColorTransform;
14
15class com.jeroenwijering.players.RotatorView extends AbstractView {
16
17
18        /** full width of the scrubbars **/
19        private var currentItem:Number;
20        /** clip that's currently active **/
21        private var upClip:MovieClip;
22        /** clip that's currently inactive **/
23        private var downClip:MovieClip;
24        /** boolean for whether to use the title display **/
25        private var useTitle:Boolean;
26        /** boolean to see if the transition is done **/
27        private var transitionDone:Boolean = false;
28        /** boolean to detect first run **/
29        private var firstRun:Boolean = true;
30        /** interval for hiding the display **/
31        private var hideInt:Number;
32        /** array with all transitions **/
33        private var allTransitions:Array = new Array(
34                "bgfade",
35                "blocks",
36                "bubbles",
37                "circles",
38                "fade",
39                "flash",
40                "fluids",
41                "lines",
42                "slowfade"
43        );
44
45
46        /** Constructor **/
47        function RotatorView(ctr:AbstractController,cfg:Object,fed:Object) {
48                super(ctr,cfg,fed);
49                setColorsClicks();
50                if(config["shownavigation"] == "true") {
51                        Mouse.addListener(this);
52                }
53        };
54
55
56        /** Sets up visibility, sizes and colors of all display items **/
57        private function setColorsClicks() {
58                var ref = this;
59                var tgt:MovieClip = config["clip"];
60                tgt.button._width = config["width"];
61                tgt.button._height = config["height"];
62                if(config['overstretch']=='true' || config['overstretch']=='fit') {
63                        tgt.img1.bg._visible = tgt.img2.bg._visible = false;
64                } else {
65                        tgt.img1.bg._width = tgt.img2.bg._width = config["width"];
66                        tgt.img1.bg._height = tgt.img2.bg._height = config["height"];
67                        tgt.img1.col = new Color(tgt.img1.bg);
68                        tgt.img1.col.setRGB(config["screencolor"]);
69                        tgt.img2.col = new Color(tgt.img2.bg);
70                        tgt.img2.col.setRGB(config["screencolor"]);
71                }
72                if(config["linkfromdisplay"] == "true") {
73                        tgt.button.onRelease = function() {
74                                ref.sendEvent("getlink",ref.currentItem);
75                        };
76                        tgt.playicon._visible = false;
77                } else {
78                        tgt.button.onRelease = function() {
79                                ref.sendEvent("next");
80                        };
81                }
82                tgt.img1.swapDepths(1);
83                tgt.img2.swapDepths(2);
84                tgt.playicon.swapDepths(4);
85                tgt.activity.swapDepths(5);
86                tgt.navigation.swapDepths(6);
87                tgt.logo.swapDepths(7);
88                tgt.playicon._x=tgt.activity._x = Math.round(config["width"]/2);
89                tgt.playicon._y=tgt.activity._y = Math.round(config["height"]/2);
90                if(config["logo"] != undefined) {
91                        var lll = new ImageLoader(tgt.logo,"none");
92                        lll.onLoadFinished = function() {
93                                ref.config['clip'].logo._x = ref.config["displaywidth"] -
94                                        ref.config['clip'].logo._width -10;
95                                ref.config['clip'].logo._y = 10;
96                        };
97                        lll.loadImage(config["logo"]);
98                }
99                tgt = config["clip"].navigation;
100                if (config["shownavigation"] == "true") {
101                        tgt._y = config["height"] - 40;
102                        tgt._x = config["width"]/2 - 50;
103                        tgt.prevBtn.col1 = new Color(tgt.prevBtn.bck);
104                        tgt.prevBtn.col1.setRGB(config["backcolor"]);
105                        tgt.prevBtn.col2 = new Color(tgt.prevBtn.icn);
106                        tgt.prevBtn.col2.setRGB(config["frontcolor"]);
107                        tgt.itmBtn.col1 = new Color(tgt.itmBtn.bck);
108                        tgt.itmBtn.col1.setRGB(config["backcolor"]);
109                        tgt.itmBtn.txt.textColor = config["frontcolor"];
110                        tgt.nextBtn.col1 = new Color(tgt.nextBtn.bck);
111                        tgt.nextBtn.col1.setRGB(config["backcolor"]);
112                        tgt.nextBtn.col2 = new Color(tgt.nextBtn.icn);
113                        tgt.nextBtn.col2.setRGB(config["frontcolor"]);
114                        tgt.prevBtn.onRollOver = tgt.nextBtn.onRollOver = function() {
115                                this.col2.setRGB(ref.config["lightcolor"]);
116                        };
117                        tgt.prevBtn.onRollOut = tgt.nextBtn.onRollOut = function() {
118                                this.col2.setRGB(ref.config["frontcolor"]);
119                        };
120                        tgt.itmBtn.onRollOver = function() {
121                                this.txt.textColor = ref.config["lightcolor"];
122                        };
123                        tgt.itmBtn.onRollOut = function() {
124                                this.txt.textColor = ref.config["frontcolor"];
125                        };
126                        tgt.prevBtn.onRelease = function() {
127                                ref.sendEvent("prev");
128                                this.col2.setRGB(ref.config["frontcolor"]);
129                        };
130                        tgt.itmBtn.onRelease = function() { ref.sendEvent("playpause"); };
131                        tgt.nextBtn.onRelease = function() {
132                                ref.sendEvent("next");
133                                this.col2.setRGB(ref.config["frontcolor"]);
134                        };
135                        // set sizes, colors and buttons for image title
136                        var len = 0;
137                        for(var i=0; i<feeder.feed.length; i++) {
138                                if(feeder.feed[i]['title'] != undefined &&
139                                        feeder.feed[i]['title'].length > len) {
140                                        len = feeder.feed[i]['title'].length;
141                                }
142                        }
143                        if(len == 0) {
144                                useTitle = false;
145                                tgt.titleBtn._visible = false;
146                        } else {
147                                useTitle = true;
148                                tgt.titleBtn._x = 74;
149                                tgt.titleBtn.col1 = new Color(tgt.titleBtn.left);
150                                tgt.titleBtn.col1.setRGB(config["backcolor"]);
151                                tgt.titleBtn.col2 = new Color(tgt.titleBtn.mid);
152                                tgt.titleBtn.col2.setRGB(config["backcolor"]);
153                                tgt.titleBtn.col3 = new Color(tgt.titleBtn.right);
154                                tgt.titleBtn.col3.setRGB(config["backcolor"]);
155                                tgt.titleBtn.tf._width = len*6;
156                                tgt.titleBtn.tf.textColor = config["frontcolor"];
157                                if(feeder.feed[0]["link"] != undefined) {
158                                        tgt.titleBtn.onRollOver = function() {
159                                                this.tf.textColor = ref.config["lightcolor"];
160                                        };
161                                        tgt.titleBtn.onRollOut = function() {
162                                                this.tf.textColor = ref.config["frontcolor"];
163                                        };
164                                        tgt.titleBtn.onRelease = function() {
165                                                ref.sendEvent("getlink",ref.currentItem);
166                                        };
167                                };
168                                tgt.titleBtn.mid._width = len*6;
169                                tgt.titleBtn.right._x = len*6+4;
170                                tgt.nextBtn._x = len*6 + 79;
171                        }
172                        if(feeder.audio == true) {
173                                tgt.audioBtn.col1 = new Color(tgt.audioBtn.bck);
174                                tgt.audioBtn.col2 = new Color(tgt.audioBtn.icnOn);
175                                tgt.audioBtn.col3 = new Color(tgt.audioBtn.icnOff);
176                                tgt.audioBtn.col1.setRGB(config["backcolor"]);
177                                tgt.audioBtn.col2.setRGB(config["frontcolor"]);
178                                tgt.audioBtn.col3.setRGB(config["frontcolor"]);
179                                tgt.audioBtn.onRollOver = function() {
180                                        this.col2.setRGB(ref.config["lightcolor"]);
181                                        this.col3.setRGB(ref.config["lightcolor"]);
182                                };
183                                tgt.audioBtn.onRollOut = function() {
184                                        this.col2.setRGB(ref.config["frontcolor"]);
185                                        this.col3.setRGB(ref.config["frontcolor"]);
186                                };
187                                tgt.audioBtn.onRelease = function() {
188                                        ref.sendEvent("audio");
189                                        this.col2.setRGB(ref.config["frontcolor"]);
190                                        this.col3.setRGB(ref.config["frontcolor"]);
191                                };
192                                if(config['useaudio'] == "true") {
193                                        tgt.audioBtn.icnOff._visible = false;
194                                } else {
195                                        tgt.audioBtn.icnOn._visible = false;
196                                }
197                                tgt.audioBtn._x = len*6 + 104;
198                        } else {
199                                tgt.audioBtn._x = 0;
200                                tgt.audioBtn._visible = false;
201                        }       
202                        tgt._x = Math.round(config["width"]/2 - tgt._width/2);
203                } else {
204                        tgt._visible = false;
205                }
206        };
207
208
209        /** New item: switch clips and ready transition **/
210        private function setItem(pr1) {
211                currentItem = pr1;
212                transitionDone = false;
213                var tgt = config["clip"];
214                tgt.navigation.itmBtn.txt.text = (currentItem+1) + " / " +
215                        feeder.feed.length;
216                if (useTitle == true) {
217                        tgt.navigation.titleBtn.tf.text=feeder.feed[currentItem]["title"];
218                }
219                tgt.img1.swapDepths(tgt.img2);
220                downClip = upClip;
221                if (upClip == tgt.img1) {
222                        upClip = tgt.img2;
223                } else {
224                        upClip = tgt.img1;
225                }
226        };
227
228
229        /** State switch; start the transition **/
230        private function setState(stt:Number) {
231                switch(stt) {
232                        case 0:
233                                if(config["showicons"] == "true") {
234                                        config["clip"].playicon._visible = true;
235                                }
236                                config["clip"].activity._visible = false;
237                                break;
238                        case 1:
239                                config["clip"].playicon._visible = false;
240                                if(config["showicons"] == "true") {
241                                        config["clip"].activity._visible = true;
242                                }
243                                break;
244                        case 2:
245                                config["clip"].playicon._visible = false;
246                                config["clip"].activity._visible = false;
247                                if(transitionDone == false) {
248                                        doTransition();
249                                        if(config["kenburns"] == "true") {
250                                                moveClip();
251                                        }
252                                }
253                                break;
254                }
255        };
256
257
258        /** (Re)set the ken burns fade **/
259        private function moveClip() {
260                var dir = random(4);
261                var clp = upClip.smc;
262                if(upClip.smc == undefined) { clp = upClip.mc; }
263                clp._xscale *= config['rotatetime']/20 + 1;
264                clp._yscale *= config['rotatetime']/20 + 1;
265                if(dir == 0) {
266                        clp._x = 0;
267                } else if (dir == 1) {
268                        clp._y = 0;
269                } else if (dir == 2) {
270                        clp._x = config['width'] - upClip._width;
271                } else {
272                        clp._y = config['height'] - upClip._height;
273                }
274                clp.onEnterFrame = function() {
275                        if(dir == 0) {
276                                this._x -= 0.3;
277                        } else if (dir == 1) {
278                                this._y -= 0.3;
279                        } else if (dir == 2) {
280                                this._x += 0.3;
281                        } else {
282                                this._y += 0.3;
283                        }
284                };
285        };
286
287
288        /** Start a transition **/
289        private function doTransition() {
290                transitionDone = true;
291                if(firstRun == true) {
292                        config["clip"].img1._alpha = 100;
293                        config["clip"].img2._alpha = 0;
294                        firstRun = false;
295                } else {
296                        var trs = config["transition"];
297                        if(trs == "random") {
298                                trs = allTransitions[random(allTransitions.length)];
299                        }
300                        switch (trs) {
301                                case "bgfade":
302                                        doBGFade();
303                                        break;
304                                case "blocks":
305                                        doBlocks();
306                                        break;
307                                case "bubbles":
308                                        doBubbles();
309                                        break;
310                                case "circles":
311                                        doCircles();
312                                        break;
313                                case "fade":
314                                        doFade();
315                                        break;
316                                case "flash":
317                                        doFlash();
318                                        break;
319                                case "fluids":
320                                        doFluids();
321                                        break;
322                                case "lines":
323                                        doLines();
324                                        break;
325                                case "slowfade":
326                                        doSlowfade();
327                                        break;
328                                default:
329                                        doFade();
330                                        break;
331                        }
332                }
333        };
334
335
336        /** Function for the fade transition **/
337        private function doFade() {
338                upClip.ref = this;
339                upClip._alpha = 0;
340                upClip.onEnterFrame = function() {
341                        this._alpha +=5;
342                        if(this._alpha >= 100) {
343                                delete this.onEnterFrame;
344                                this.ref.downClip._alpha = 0;
345                        }
346                };
347        };
348
349
350        /** Function for the bgfade transition **/
351        private function doBGFade() {
352                downClip.ref = upClip.ref = this;
353                downClip.onEnterFrame = function() {
354                        this._alpha -=5;
355                        if(this._alpha <= 0) {
356                                delete this.onEnterFrame;
357                                this.ref.upClip.onEnterFrame = function() {
358                                        if(this._alpha >= 100) {
359                                                delete this.onEnterFrame;
360                                        } else {
361                                                this._alpha +=5;
362                                        }
363                                };
364                        }
365                };
366        };
367
368
369        /** Function for the blocks transition **/
370        private function doBlocks() {
371                upClip._alpha = 100;
372                config["clip"].attachMovie("blocksMask","mask",3);
373                var msk:MovieClip = config["clip"].mask;
374                if (config["width"] > config["height"]) {
375                        msk._width = msk._height = config["width"];
376                } else {
377                        msk._width = msk._height = config["height"];
378                }
379                msk._rotation = random(4)*90;
380                msk._rotation == 90 ? msk._x = config["width"]: null;
381                msk._rotation == 180 ? msk._x = config["width"]: null;
382                msk._rotation == 180 ? msk._y = config["height"]: null;
383                msk._rotation == -90 ? msk._y = config["height"]: null;
384                upClip.setMask(msk);
385                playClip(msk);
386        };
387
388
389        /** Function for the bubbles transition **/
390        private function doBubbles() {
391                upClip._alpha = 100;
392                config["clip"].attachMovie("bubblesMask","mask",3);
393                var msk:MovieClip = config["clip"].mask;
394                upClip.setMask(msk);
395                if (config["width"] > config["height"]) {
396                        msk._width = msk._height = config["width"];
397                        msk._y = config["height"]/2 - msk._height/2;
398                } else {
399                        msk._width = msk._height = config["height"];
400                        msk._x = config["width"]/2- msk._width/2;
401                }
402                if(random(2) == 1) {
403                        msk._xscale = -msk._xscale;
404                        msk._x += config['width'];
405                }
406                playClip(msk);
407        };
408
409
410        /** Function for the circles transition **/
411        private function doCircles() {
412                upClip._alpha = 100;
413                config["clip"].attachMovie("circlesMask","mask",3);
414                var msk:MovieClip = config["clip"].mask;
415                upClip.setMask(msk);
416                if (config["width"] > config["height"]) {
417                        msk._width = msk._height = config["width"];
418                } else {
419                        msk._width = msk._height = config["height"];
420                }
421                msk._x = config["width"]/2;
422                msk._y = config["height"]/2;
423                playClip(msk,10);
424        };
425
426
427        /** Function for the flash transition **/
428        private function doFlash() {
429                upClip._alpha = 100;
430                upClip.col = new Color(upClip);
431                upClip.ctf = new Object({rb:255,gb:255,bb:255});
432                upClip.col.setTransform(upClip.ctf);
433                upClip.onEnterFrame = function() {
434                        if(this.ctf.rb < 1) {
435                                this.ctf =  new Object({rb:0,gb:0,bb:0});
436                                this.col.setTransform(this.ctf);
437                                delete this.onEnterFrame;
438                        } else {
439                                this.ctf.rb /= 1.05;
440                                this.ctf.gb /= 1.05;
441                                this.ctf.bb /= 1.05;
442                                this.col.setTransform(this.ctf);
443                        }
444                };
445        };
446
447        /** Function for the fluids transition **/
448        private function doFluids() {
449                upClip._alpha = 100;
450                config["clip"].attachMovie("fluidsMask","mask",3);
451                var msk:MovieClip = config["clip"].mask;
452                upClip.setMask(msk);
453                msk._width = config["width"];
454                msk._height = config["height"];
455                playClip(msk);
456        };
457
458
459        /** Function for the lines transition **/
460        private function doLines() {
461                upClip._alpha = 100;
462                config["clip"].attachMovie("linesMask","mask",3);
463                var msk:MovieClip = config["clip"].mask;
464                upClip.setMask(msk);
465                msk._width = config["width"];
466                msk._height = config["height"];
467                playClip(msk);
468        };
469
470
471        /** Function for the fade transition **/
472        private function doSlowfade() {
473                upClip.ref = this;
474                upClip._alpha = 0;
475                upClip.onEnterFrame = function() {
476                        this._alpha+=2;
477                        if(this._alpha >= 100) {
478                                delete this.onEnterFrame;
479                                this.ref.downClip._alpha = 0;
480                        }
481                };
482        };
483
484
485        /** Play a specific Movieclip and remove it once it's finished **/
486        private function playClip(tgt:MovieClip,rot:Number) {
487                tgt.ref = this;
488                tgt.onEnterFrame = function() {
489                        this.nextFrame();
490                        rot == undefined ? null: this._rotation +=rot;
491                        if(this._currentframe  == this._totalframes) {
492                                this.ref.downClip._alpha = 0;
493                                this.clear();
494                                this.unloadMovie();
495                                this.removeMovieClip();
496                        }
497                };
498        };
499
500
501        /** after a delay, the controlbar is hidden **/
502        private function hideBar() {
503                Animations.fadeOut(config['clip'].navigation);
504                clearInterval(hideInt);
505        }
506
507
508        /** Mouse move shows controlbar **/
509        public function onMouseMove() {
510                Animations.fadeIn(config['clip'].navigation);
511                clearInterval(hideInt);
512                if(!config["clip"].navigation.hitTest(_root._xmouse,_root._ymouse)) {
513                        hideInt = setInterval(this,"hideBar",500);
514                }
515        };
516
517
518}
Note: See TracBrowser for help on using the browser.