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.
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.

The widget sets the twitter user through flashvars so someone elses name, tweets, and twitter profile image could show up in this widget upon request. B)