It took me quite a while to figure out how to get started with my own twitter app, so I thought it might be usefull writing down the steps to get started.
I use the open source FlashDevelop IDE, but in Flex Builder it should work identical.
First, create your project.
The next thing you need to do is loading the offical AS3 Twitter lib swc from google code.
This SWC contains a few classes only, you can browse them on the Source tab of the google code page.
Just put it into the lib folder of your project and, in FlashDevelop, rightclick it to select Add To Library.
Now, let’s go over to the code
package {
import flash.display.Sprite;
import twitter.api.Twitter;
import twitter.api.events.TwitterEvent;
import twitter.api.data.TwitterStatus;
import twitter.api.data.TwitterUser;
public class Main extends Sprite {
private var api:Twitter;
public function Main() {
api = new Twitter();
api.setAuthenticationCredentials("xathis", "password");
api.loadFriendsTimeline("xathis");
api.addEventListener(TwitterEvent.ON_FRIENDS_TIMELINE_RESULT, resultHandler);
}
private function resultHandler(event:TwitterEvent):void {
for (var i:int = 0; i < event.data.length; i++) {
var status:TwitterStatus = event.data[i] as TwitterStatus;
var user:TwitterUser = status.user;
trace(user.screenName + ": " + status.text);
}
}
}
}
That’s it. There’s only this one Main class. All it does is loading your friend’s timelines and display them in the output panel.
Of course you have to change your username and password.
And remember, this is only an example, you should never leave your password hardcoded in a swf.
For more information on the twitter API take a look at the documentation at the API-Wiki
