Create Social Sharing Buttons in AS3

Hey all, recently I had to create a series of sharing buttons for a client so I went all over the internets in search for those sharing urls, then I had to fight against the popUp blockers and externalInterface problems, but I managed to pull it off and I present you with some very usefull functions, if one of those urls here changes drop me a line and I’ll try to find a replacement.

So here we go I’ll present the functions and then a single function that manages the display:

        // FACEBOOK
        private function shareFB(e:Event):void
        {
            openPage('http://www.facebook.com/sharer/sharer.php?t=A+cool+video&u='+escape("http://flepstudio.org/utilita/VideoPlayer/IronMan2.mov"),"_popup");
        }
       
        // TWITTER
        private function shareTwitter(e:Event):void
        {
            openPage('https://twitter.com/intent/tweet?source=webclient&text=A+cool+video%3A+'+escape("http://flepstudio.org/utilita/VideoPlayer/IronMan2.mov"),"_popup");
        }
       
        // MAIL
        private function shareMail(e:Event):void
        {
            var request:URLRequest = new URLRequest("mailto:"+address+"?subject="+videoInfo.videoTitle+"&body="+"\n\n Video Link: "+videoInfo.videoLink);            
            navigateToURL(request, "_self");
        }
       
        // TUMBLR
        private function shareTumblr(e:Event):void
        {
            openPage("http://www.tumblr.com/share/link?url=" + escape(videoInfo.videoLink) + "&name=" + escape(videoInfo.videoTitle) + "&description=" + escape(videoInfo.videoArtist),'_popup');
        }
       
        // STUMBLE UPON
        private function shareSU(e:Event):void
        {
            openPage("http://www.stumbleupon.com/submit?url="+escape(videoInfo.videoLink)+"&title="+escape(videoInfo.videoTitle));
        }
       
        // GOOGLE +
        private function shareGoogle(e:Event):void
        {
            openPage("https://m.google.com/app/plus/x/?v=compose&content="+escape(videoInfo.videoLink),"_popup");
        }
       
        // LinkedIn
        private function shareLinkedIn(e:Event):void
        {
            openPage("http://www.linkedin.com/shareArticle?mini=true&url=CONTENT-URL&title="+escape(videoInfo.videoArtist)+"&summary="+escape(videoInfo.videoArtist)+"&source="+escape(videoInfo.videoTitle),'_popup');
        }
       
        // DIGG
        private function shareDigg(e:Event):void
        {
            openPage("http://digg.com/submit?phase=2&url="+escape(videoInfo.videoLink)+"&title="+escape(videoInfo.videoTitle)+"&bodytext="+''+"&topic="+escape(videoInfo.videoArtist));
        }
       
        //BEBO
        private function shareBebo(e:Event):void
        {
            openPage("http://www.bebo.com/c/share?Url="+escape(videoInfo.videoLink)+"&Title="+escape(videoInfo.videoTitle),'_popup');
        }
       
        //ORKUT
        private function shareOrkut(e:Event):void
        {  
            openPage("http://www.orkut.com/FavoriteVideos.aspx?u="+escape(videoInfo.videoLink),'_popup');
        }
       
        //REDDIT
        private function shareReddit(e:Event):void
        {
            openPage("http://www.reddit.com/submit?url="+escape(videoInfo.videoLink),'_popup');
        }
       
        // DELICIOUS
        private function shareDelicious(e:Event):void
        {
            openPage("http://www.delicious.com/save?v=5&jump=close&url="+escape(videoInfo.videoLink)+"&title="+escape(videoInfo.videoTitle));
        }
       
        // MYSPACE
        private function shareMySpace(e:Event):void
        {
            openPage("http://www.myspace.com/Modules/PostTo/Pages/?t="+escape(videoInfo.videoTitle)+"&c="+escape(videoInfo.videoArtist)+"&u="+escape(videoInfo.videoLink)+"&l="+escape(videoInfo.videoLink),'_popup');
        }

These are most of the social networks that I could think of, but it is almost the same for everything else I suppose.
And the following is the master function that handles the popup. (This is based on a function used by flowplayer and their sharing plugin, but it is generic stuff).

public static function openPage(url:String, linkWindow:String = "_blank", popUpDimensions:Array = null):void {
            if (linkWindow == "_popup" && ExternalInterface.available) {
                var dimensions:Array = [800,600];
                ExternalInterface.call("window.open('" + url + "','PopUpWindow','width=" + dimensions[0] + ",height=" + dimensions[1] + ",toolbar=yes,scrollbars=yes')");
            } else {
                // Use JS to bypass popup blockers if ExternalInterface is available
                var window:String = linkWindow == "_popup" ? "_blank" : linkWindow;
                if (ExternalInterface.available) {
                    ExternalInterface.call('window.open("' + url + '","' + window + '")');
                } else {
                    //request a blank page
                    navigateToURL(new URLRequest(url), window);
                }
            }
        }

There now you can use these and link them into buttons for your sharing pleasure.
You can view an example here: http://www.netgfx.com/trunk/social/
Enjoy!

facebooktwittergoogle_pluspinterestlinkedin
linkedinrss