Tweetr, ActionScript 3.0 Twitter library that just work.

December 15, 2009 by fMajakovskij

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.

This movie requires Flash Player 9
.

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…

Leave a Reply

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

*

You may 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>