Today I give a try to Tweetr, an Actionscript 3 library to work with Twitter from Flash/Flex applications.
After did some investigation to the ex-semi-official Twitter-API AS3 library which doesn’t work anymore (with swf published on the web only) due crossdomain.xml policy changes, I switched to Tweetr lib which comes with an handy php proxy file.
and here the basic code to get it to work:
import com.swfjunkie.tweetr.Tweetr;
import com.swfjunkie.tweetr.events.TweetEvent;
import com.swfjunkie.tweetr.data.objects.StatusData;
public function Twitter():void
{
var tweetr:Tweetr = new Tweetr();
tweetr.serviceHost = "http://www.fmajakovskij.info/proxy";
// the real credentials are stored on the proxy php file, so it is secure:
tweetr.username = "ghost";
tweetr.password = "ghost";
tweetr.addEventListener(TweetEvent.COMPLETE, handleLoad);
tweetr.addEventListener(TweetEvent.FAILED, handleFail);
tweetr.getUserTimeLine()
}
private function handleLoad(event:TweetEvent):void
{
for(var i:int = 0; i < event.responseArray.length; i++)
{
var statusData:StatusData = event.responseArray[i];
trace(statusData.text)
}
}
private function handleFail(event:TweetEvent):void
{
trace(event.info);
}
It works like a charm…