I’ve got a fever, and the only prescription is more cowbell.

Creating a Twitter Widget Using Flex and TwitterScript

I create a twitter widget with flex and actionscript.  I used twitterscript to obtain access to the twitter api in actionscript.  This is my little pet project that I been working on sparingly for the last couple weeks.  I finished it about a week ago, but I had to troubleshoot twitter’s cross domain policy and issues with my php configuration.

This is my partial mxml file.  The main part of this widget is the currentTweet text tag.  As shown below, the init function is being executing upon creationComplete.

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  xmlns:components="com.components.*"
  layout="absolute"
  backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FFFFFF, #FFFFFF]"
  creationComplete="init();">
  <mx:Script>
    ...
  </mx:Script>

  <mx:Text id="currentTweet" x="10" y="10" text="Loading..." width="113" height="110" />
</mx:Application>

Inside my init function exists the code for inintializing the twitter object.  After creating the twitter object, I want to load my tweets.  To find out when my tweets get loaded, I added an event listener for the specific twitter event.  When my tweets are loaded, I want to execcute the populateTweets function.

private function init():void {
  USERNAME = "jonkarna";
  if(application.parameters["username"] != null) USERNAME = application.parameters["username"];
  t = new Twitter();
  t.loadUserTimeline(USERNAME);
  t.addEventListener(TwitterEvent.ON_USER_TIMELINE_RESULT, populateTweets);
}

This is the populateTweets function that gets run after my tweets are loaded.  I store my tweets in an array collection and set the current tweet.

private function populateTweets(e:TwitterEvent):void {
  var twitterStatus:TwitterStatus;
  for (var i:String in e.data) {
    twitterStatus = e.data[i];
    tweets.addItem(twitterStatus);
  }
  currentTweet.htmlText = tweets[currentTweetIndex].text;
}

Here is my swf, but my widget includes several more features then what I have outlined here.

This movie requires Flash Player 9

On google code, you can find TwitterScript.  My initial widget was based on this article, Twitter AS3 library TwitterScript Flex Example.  To find out more user feedback, I was lead to this article, Twitter and Flash (twitterscript).  After creation of my widget, I had to reference this article, Twitter in Flash – Getting Past the SecurityErrorEvent, to troubleshoot twitter’s cross domain policy.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

1 Comment to Creating a Twitter Widget Using Flex and TwitterScript

  1. By on July 14, 2009 at 3:45 am
  2. By on July 25, 2009 at 1:21 pm

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe

Search

You Can Find Me On ...

Categories

RSS Other Articles By Me

  • reCAPTCHA: Blocking Spam and More
    A few months ago, I developed a ColdFusion/Mach-II implementation of the reCAPTCHA API.  This type of CAPTCHA requires the person to enter two words rather than a single sequence of random letters.  In addition to protecting your website from spam, reCAPTCHA helps digitize text books.  They do this by using a mystery word as one of the two words, until there […]
  • Using Friendfeed to Automatically Post Your Blog Entries on Twitter
    Friendfeed is a feed aggregator that groups together updates from twitter, facebook, digg, youtube, your blog and much more.  It can also publish entries from your friendfeed to twitter.  This article shows you how to tap into that twitter publishing feature of friendfeed to automate the posting of your blog entries to twitter.  Watch my screencast to create […]
  • Intense Debate Now on the Sitepro Blog!
    Recently on the Sitepro Blog, we have switched to using an enhanced commenting system called Intense Debate.  Intense Debate provides many features that will supercharge the community, increase comments, and increase pageviews.  Some notable features include commenter profiles, reputation scores, email notifications, reply by email, and facebook integration. […]
  • Sitepro Developers Attend TCCFUG
    Last Thursday, a few Sitepro developers attended the Twin Cities Coldfusion User Group at University of St. Thomas.  We were introduced to the future of Coldfusion, specifically Coldfusion 9.  There was free admission, free food, free shirt, prizes, and an abundance of new Coldfusion features. […]