source: plugins/sharing/com/jeroenwijering/plugins/Sharing.as @ 235

Revision 235, 6.8 KB checked in by jeroen, 4 years ago (diff)

removed the botr flashvar, aligned hitareas a little and added support for regular title/link flashvars

Line 
1package com.jeroenwijering.plugins {
2
3
4import com.jeroenwijering.events.*;
5
6import flash.display.MovieClip;
7import flash.display.Sprite;
8import flash.events.MouseEvent;
9import flash.net.navigateToURL;
10import flash.net.URLRequest;
11import flash.text.TextField;
12import flash.text.TextFormat;
13import flash.system.System;
14
15
16/**
17* Sharing plugin; shows a "share" and "embed" button in the (4.5+) dock or (4.3+) controlbar.
18**/
19public class Sharing extends MovieClip implements PluginInterface {
20
21
22        [Embed(source="../../../embedButton.png")]
23        private const EmbedButton:Class;
24        [Embed(source="../../../embedIcon.png")]
25        private const EmbedIcon:Class;
26        [Embed(source="../../../embedScreen.png")]
27        private const EmbedScreen:Class;
28        [Embed(source="../../../shareButton.png")]
29        private const ShareButton:Class;
30        [Embed(source="../../../shareIcon.png")]
31        private const ShareIcon:Class;
32        [Embed(source="../../../shareScreen.png")]
33        private const ShareScreen:Class;
34
35
36        /** List with configuration settings. **/
37        public var config:Object = {
38                code:undefined,
39                link:undefined,
40                title:'Great%20video'
41        };
42        /** Reference to the View of the player. **/
43        private var view:AbstractView;
44        /** Reference to the embed container. **/
45        private var embed:Sprite;
46        /** Reference to the embed graphics. **/
47        private var embedScreen:Sprite;
48        /** Reference to the embed textfield. **/
49        private var embedField:TextField;
50        /** Reference to the share graphics. **/
51        private var share:Sprite;
52        /** Reference to the share graphics. **/
53        private var shareScreen:Sprite;
54        /** Reference to the share textfield. **/
55        private var shareField:TextField;
56        /** Reference to the transparent bg area. **/
57        private var back:Sprite;
58        /** Remenber which item is visible. **/
59        private var showing:String;
60
61
62        /** Constructor; builds the background area. **/
63        public function Sharing():void {
64                back = new Sprite();
65                embed = new Sprite();
66                share = new Sprite();
67                back.graphics.beginFill(0x000000,0);
68                back.graphics.drawRect(0,0,320,240);
69                back.buttonMode = true;
70                back.addEventListener(MouseEvent.CLICK,backHandler);
71                addChild(back);
72        };
73
74
75        /** Screenground clicked; hide the screen. **/
76        private function backHandler(evt:MouseEvent=null):void {
77                showHide('none');
78        };
79
80
81        /** Embed area is clicked; select the code and copy to clipboard.. **/
82        private function codeHandler(evt:MouseEvent):void {
83                stage.focus = embedField;
84                embedField.setSelection(0,999999);
85                System.setClipboard(config['code']);
86        };
87
88
89        /** Embed icon is clicked; toggle the embed screen. **/
90        private function embedHandler(evt:MouseEvent):void {
91                showHide('embed');
92        };
93
94
95        /** The initialize call is invoked by the player View. **/
96        public function initializePlugin(vie:AbstractView):void {
97                view = vie;
98                view.addControllerListener(ControllerEvent.RESIZE,resizeHandler);
99                if(view.config['sharing.code']) {
100                        config['code'] = view.config['sharing.code'];
101                        setEmbed();
102                }
103                if(view.config['sharing.link']) {
104                        config['link'] = view.config['sharing.link'];
105                        setShare();
106                } else if (view.config['link']) {
107                        config['link'] = view.config['link'];
108                        setShare();
109                }
110                if(view.config['title']) {
111                        config['title'] = encodeURI(view.config['title']);
112                }
113                showHide('none');
114        };
115
116
117        /** Share area is clicked; select the link and copy to clipboard or follow a shortcut. **/
118        private function linkHandler(evt:MouseEvent):void {
119                if(shareScreen.mouseY < 80) {
120                        stage.focus = shareField;
121                        shareField.setSelection(0,999999);
122                        System.setClipboard(config['link']);
123                } else {
124                        var url:String;
125                        if (shareScreen.mouseX < 75) {
126                                url = 'http://www.facebook.com/share.php?u='+encodeURI(config['link']);
127                                navigateToURL(new URLRequest(url));
128                        } else if (shareScreen.mouseX < 150) {
129                                url = 'http://twitter.com/home?status='+config['title']+': '+encodeURI(config['link']);
130                                navigateToURL(new URLRequest(url));
131                        } else if (shareScreen.mouseX < 225) {
132                                if(config['code']) {
133                                        url = 'http://www.myspace.com/Modules/PostTo/Pages/?t='+config['title']+'&c='+encodeURI(config['code']);
134                                } else {
135                                        url = 'http://www.myspace.com/Modules/PostTo/Pages/?t='+config['title']+'&c='+encodeURI(config['link']);
136                                }
137                                navigateToURL(new URLRequest(url));
138                        } else {
139                                url = 'mailto:?subject='+config['title']+'&body='+encodeURI(config['link']);
140                                navigateToURL(new URLRequest(url),'_self');
141                        }
142                }
143        };
144
145
146        /** Resize the clip when on screen. **/
147        private function resizeHandler(evt:ControllerEvent):void {
148                back.width = view.config['width'];
149                back.height = view.config['height'];
150                embed.x = share.x = view.config['width']/2-150
151                embed.y = share.y = view.config['height']/2-65
152        };
153
154
155        /** Set the embed buttons and graphics. **/
156        private function setEmbed():void {
157                if(view.getPlugin('dock') && view.config['dock']) {
158                        view.getPlugin('dock').addButton(new EmbedIcon(),'embed',embedHandler);
159                } else if (view.getPlugin('controlbar')) {
160                        view.getPlugin('controlbar').addButton(new EmbedButton(),'embed',embedHandler);
161                }
162                embedScreen = new Sprite();
163                embedScreen.addChild(new EmbedScreen());
164                embedScreen.buttonMode = true;
165                embedScreen.addEventListener(MouseEvent.CLICK,codeHandler);
166                embed.addChild(embedScreen);
167                embedField = new TextField();
168                embedField.defaultTextFormat = new TextFormat('_sans',11);
169                embedField.multiline = true;
170                embedField.wordWrap = true;
171                embedField.x = 22;
172                embedField.y = 32;
173                embedField.text = config['code'];
174                embedField.width = 258;
175                embedField.height = 64;
176                embed.addChild(embedField);
177                addChild(embed);
178        };
179
180
181        /** Set the embed buttons and graphics. **/
182        private function setShare():void {
183                if(view.getPlugin('dock') && view.config['dock']) {
184                        view.getPlugin('dock').addButton(new ShareIcon(),'share',shareHandler);
185                } else if (view.getPlugin('controlbar')) {
186                        view.getPlugin('controlbar').addButton(new ShareButton(),'embed',shareHandler);
187                }
188                shareScreen = new Sprite();
189                shareScreen.addChild(new ShareScreen());
190                shareScreen.buttonMode = true;
191                shareScreen.addEventListener(MouseEvent.CLICK,linkHandler);
192                share.addChild(shareScreen);
193                shareField = new TextField();
194                shareField.defaultTextFormat = new TextFormat('_sans',11);
195                shareField.x = 22;
196                shareField.y = 32;
197                shareField.text = config['link'];
198                shareField.width = 258;
199                shareField.height = 20;
200                share.addChild(shareField);
201                addChild(share);
202        };
203
204
205        /** Share icon is clicked; toggle the share screen. **/
206        private function shareHandler(evt:MouseEvent):void {
207                showHide('share');
208        };
209
210
211        /** Show or hide the display icons. **/
212        private function showHide(stt:String):void {
213                if(stt == showing && stt != 'none') {
214                        stt = 'none';
215                }
216                switch (stt) {
217                        case 'none':
218                                back.visible = false;
219                                embed.visible = false;
220                                share.visible = false;
221                                break;
222                        case 'embed':
223                                back.visible = true;
224                                embed.visible = true;
225                                share.visible = false;
226                                break;
227                        case 'share':
228                                back.visible = true;
229                                embed.visible = false;
230                                share.visible = true;
231                                break;
232                }
233                showing = stt;
234        };
235
236
237};
238
239
240}
Note: See TracBrowser for help on using the repository browser.