source: trunk/as3/com/jeroenwijering/plugins/Watermark.as @ 531

Revision 531, 3.5 KB checked in by jeroen, 4 years ago (diff)

added first implemetation of the popout plugin

Line 
1package com.jeroenwijering.plugins {
2
3
4import com.jeroenwijering.events.*;
5import com.jeroenwijering.utils.*;
6
7import fl.transitions.*;
8import fl.transitions.easing.*;
9
10import flash.display.*;
11import flash.utils.*;
12import flash.events.*;
13import flash.net.*;
14
15
16/**
17* Plugin that shows a watermark when buffering.
18**/
19public class Watermark extends MovieClip implements PluginInterface {
20
21
22        /** Reference to the skin MC. **/
23        public var clip:MovieClip;
24        /** Configuration flashvars pushed by the player. **/
25        public var config:Object = {};
26        /** Configuration flashvars, not overwritten by the player. **/
27        private var _config:Object = {
28                file:undefined,
29                link:undefined,
30                margin:10,
31                out:0.5,
32                over:1,
33                state:false,
34                timeout:3
35        };
36        /** Save whether the plugin is configurable. **/
37        private var configurable:Boolean;
38        /** Reference to the loader **/
39        private var loader:Loader;
40        /** Reference to the MVC view. **/
41        private var view:AbstractView;
42        /** Timeout keeping track of fade out  **/
43        private var timeout:uint;
44
45
46        /** Constructor. **/
47        public function Watermark(cfg:Boolean=false):void {
48                configurable = cfg;
49        };
50
51
52        /** Handle Mouse Click **/
53        private function clickHandler(evt:MouseEvent):void {
54                view.sendEvent(ViewEvent.PLAY,false);
55                var lnk:String = view.config['aboutlink'];
56                if(_config['link']) { lnk = _config['link']; }
57                navigateToURL(new URLRequest(lnk));
58        };
59
60
61        /** Fade out watermark. **/
62        private function hide():void {
63                _config['state'] = false;
64                clip.mouseEnabled = false;
65                TransitionManager.start(clip,{
66                        type:Fade,
67                        direction:Transition.OUT,
68                        duration:0.3,
69                        easing:Regular.easeIn
70                });
71        };
72
73
74        /** Initialize the plugin. **/
75        public function initializePlugin(vie:AbstractView):void {
76                view = vie;
77                view.addModelListener(ModelEvent.STATE,stateHandler);
78                view.addControllerListener(ControllerEvent.RESIZE,resizeHandler);
79                if(configurable) {
80                        for (var i:String in config) { _config[i] = config[i]; }
81                }
82                clip.visible = false;
83                clip.alpha = _config['out'];
84                clip.buttonMode = true;
85                clip.addEventListener(MouseEvent.CLICK,clickHandler);
86                clip.addEventListener(MouseEvent.MOUSE_OVER,overHandler);
87                clip.addEventListener(MouseEvent.MOUSE_OUT,outHandler);
88                if(!configurable) {
89                        clip.addChild(this);
90                        resizeHandler();
91                } else if(_config['file']) {
92                        loader = new Loader();
93                        loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderHandler);
94                        loader.load(new URLRequest(_config['file']));
95                }
96        };
97
98
99        /** Watermark loaded, so position it. **/
100        private function loaderHandler(evt:Event):void {
101                clip.addChild(loader);
102                resizeHandler();
103        };
104
105
106        /** Handle mouse out state **/
107        private function outHandler(evt:MouseEvent):void {
108                clip.alpha = _config['out'];
109        };
110
111
112        /** Handle mouse over state **/
113        private function overHandler(evt:MouseEvent):void {
114                clip.alpha = _config['over'];
115        };
116
117
118        private function resizeHandler(evt:ControllerEvent=null):void {
119                clip.x = config['x'] + _config['margin'];
120                clip.y = config['y'] + config['height'] - clip.height - _config['margin'];
121        };
122
123
124        /** Load the logo when buffering. **/
125        private function stateHandler(evt:ModelEvent):void {
126                switch(evt.data.newstate) {
127                        case ModelStates.BUFFERING:
128                                clearTimeout(timeout);
129                                show();
130                                break;
131                }
132        };
133
134
135        /** Fade in watermark. **/
136        private function show():void {
137                if(!_config['state']) {
138                        _config['state'] = true;
139                        TransitionManager.start(clip,{
140                                type:Fade,
141                                direction:Transition.IN,
142                                duration:0.3,
143                                easing:Regular.easeIn
144                        });
145                        resizeHandler();
146                }
147                timeout = setTimeout(hide,_config['timeout']*1000);
148                clip.mouseEnabled = true;
149        };
150
151
152}
153
154
155}
Note: See TracBrowser for help on using the repository browser.