LogoLogo
  • Home
  • Projects
  • About
  • Contact

Social Bookmarking from Flash or Flex

Devon O. · April 08, 2009 · Actionscript · 9 comments
4

Seems one of the things I’m asked to do fairly often is provide links to the social apps that all the kids are crazy about these days. Tired of constantly having to rewrite script or look up an api call, I figured I’d sit down and begin accumulating all the basic calls in one handy dandy file. And, hence, came Bookmark.as:

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.onebyonedesign.social {
    
    import flash.net.navigateToURL;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    
    /**
     * Posts links to various social networks
     * @author Devon O. Wolfgang
     */
    public class Bookmark {
        
        public static const DIGG:String = "digg";
        public static const FACEBOOK:String = "faceBook";
        public static const GOOGLE_BOOKMARK:String = "googleBookmark";
        public static const MYSPACE:String = "myspace";
        public static const STUMBLE_UPON:String = "stumbleUpon";
        public static const TECHNORATI:String = "technorati";
        public static const TWITTER:String = "twitter";
        public static const YAHOO_BOOKMARK:String = "yahooBookmark";
    
        public function Bookmark() { /* do not instantiate - use static method post() */ }
    
        public static function post(to:String, link:String, title:String = "") {
            var request:URLRequest = new URLRequest();
            request.method = URLRequestMethod.GET;
            link = encodeURI(link);
            title = encodeURI(title);
            switch (to) {
                case DIGG :
                    request.url = "http://digg.com/submit?phase=2&url=" + link + "&title=" + title;
                    break;
                case FACEBOOK :
                    request.url = "http://www.facebook.com/sharer.php?u=" + link;
                    break;
                case GOOGLE_BOOKMARK :
                    request.url = "http://www.google.com/bookmarks/mark?op=add&bkmk=" + link + "&title=" + title;
                    break;
                case MYSPACE :
                    request.url = "http://www.myspace.com/Modules/PostTo/Pages/?u=" + link + "&t=" + title;
                    break;
                case STUMBLE_UPON :
                    request.url = "http://www.stumbleupon.com/submit?url=" + link;
                    break;
                case TECHNORATI :
                    request.url = "http://technorati.com/faves/?add=" + link;
                    break;
                case TWITTER :
                    request.url = "http://twitter.com/home?status=" + link;
                    break;
                case YAHOO_BOOKMARK :
                    request.url = "http://myweb2.search.yahoo.com/myresults/bookmarklet?u=" + link + "&t=" + title;
                    break;
                default :
                    break;
            }
            
            navigateToURL(request, "_blank");
        }
    }
}

Usage is a piece of cake.

C#
1
2
3
4
5
6
7
8
var url:String = "http://www.onebyonedesign.com/";
var title:String = "Bitchin' Website!";
 
facebookButton.addEventListener(MouseEvent.CLICK, postToFacebook);
 
private function postToFacebook(event:MouseEvent):void {
    Bookmark.post(Bookmark.FACEBOOK, url, title);
}

That scrap of code will open up Facebook in a new browser window to let folks login if necessary or add comments or whatever. While many of the networks don’t require a title to be sent, it doesn’t hurt to pass one to the static post() method – it just won’t be used. On the other hand, if you know the network you’re posting to doesn’t need one, you can leave the title parameter out. I just find it easiest to always send one and not worry about it.

Obviously, this script ain’t rocket science, but sometimes it’s the simplest things that prove most useful. If you have any social site html api’s you’re holding out on and want to add them to the list, post them in a comment. I’d like to make this class fairly well inclusive.


++Love for Warbler

In other news, warbler has now been officially recognized by Twitter, so while surfing the Twitter page you may just see tweets ending in something like:  “5 minutes ago from warbler”. Pretty cool. Kind of the nerdy web app developer equivalent of seeing your name in lights.

  Facebook   Pinterest   Twitter   Google+
  • Facebook and Flash – A Book Review
    January 23, 2011 · 6 comments
    5435
    6
    Read more
  • Liquid Text Effect
    July 14, 2010 · 3 comments
    4173
    4
    Read more
  • BetweenAS3, Through AOS, and Around FOTB
    July 27, 2009 · 2 comments
    2108
    3
    Read more
9 Comments:
  1. Great! This looks useful. I’ve written a similar one of these just as included functions, but it’s a good idea to make it a class like you have. I never take it to that level of abstraction, so props to you!

    Evan Mullins · April 08, 2009
  2. Rock n’ roll my friend! Nice job on the app!

    Todd · April 11, 2009
  3. Kids will love you more.

    Beebs · April 28, 2009
  4. Excellent class – simplicity is the key and this has got me out of a hole – great job!

    Chris · October 29, 2009
  5. hey… where i put the code? i use blogger.. please help me….

    fanarshavin · December 29, 2009
  6. This was excellent help. if only we could some how add messages to facebook too. currently only links can be posted like this.

    Juwal Bose · June 17, 2010
  7. 1013: The private attribute may be used only on class property definitions.

    Sean · July 02, 2010
  8. Hey Sean, that usage example is just a snippet from a larger class file (obviously you would also need a facebookButton instance defined elsewhere as well).

    While I’m revisiting this old post though, I should say that, rather than using the encodeURI() function in the static post() method, you should use encodeURIComponent().

    Hope that helps out.

    d.

    Devon O. · July 02, 2010

Leave a Comment! Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Devon O. Wolfgang

AIR | Unity3D | AR/VR

Unity Certified Developer

Technical Reviewer of “The Essential Guide to Flash CS4 AIR Development” and “Starling Game Development Essentials”

Reviewer of “The Starling Handbook”

Unity Engineer at Touch Press.

Categories
  • Actionscript (95)
  • AIR (16)
  • Flash (99)
  • Games (7)
  • Liberty (13)
  • Life (53)
  • Shaders (20)
  • Unity3D (21)
Recent Comments
  • MainDepth on Unity Ripple or Shock Wave Effect
  • Devon O. on Unity Ripple or Shock Wave Effect
  • Feral_Pug on Unity Ripple or Shock Wave Effect
  • bavvireal on Unity3D Endless Runner Part I – Curved Worlds
  • Danielius Vargonas on Custom Post Processing with the LWRP
Archives
  • December 2020 (1)
  • December 2019 (1)
  • September 2019 (1)
  • February 2019 (2)
  • December 2018 (1)
  • July 2018 (1)
  • June 2018 (1)
  • May 2018 (2)
  • January 2018 (1)
  • December 2017 (2)
  • October 2017 (1)
  • September 2017 (2)
  • January 2017 (1)
  • July 2016 (1)
  • December 2015 (2)
  • March 2015 (1)
  • September 2014 (1)
  • January 2014 (1)
  • August 2013 (1)
  • July 2013 (1)
  • May 2013 (1)
  • March 2013 (2)
  • December 2012 (1)
  • November 2012 (1)
  • September 2012 (3)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (1)
  • December 2011 (2)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (1)
  • July 2011 (1)
  • May 2011 (2)
  • April 2011 (2)
  • March 2011 (1)
  • February 2011 (1)
  • January 2011 (2)
  • December 2010 (3)
  • October 2010 (5)
  • September 2010 (1)
  • July 2010 (2)
  • May 2010 (5)
  • April 2010 (2)
  • March 2010 (7)
  • February 2010 (5)
  • January 2010 (5)
  • December 2009 (3)
  • November 2009 (1)
  • October 2009 (5)
  • September 2009 (5)
  • August 2009 (1)
  • July 2009 (1)
  • June 2009 (2)
  • May 2009 (6)
  • April 2009 (4)
  • March 2009 (2)
  • February 2009 (4)
  • January 2009 (1)
  • December 2008 (5)
  • November 2008 (2)
  • September 2008 (1)
  • August 2008 (6)
  • July 2008 (6)
  • June 2008 (9)
  • May 2008 (4)
  • April 2008 (3)
  • March 2008 (4)
  • February 2008 (9)
  • January 2008 (7)
  • December 2007 (6)
Copyright © 2021 Devon O. Wolfgang