Actionscript:
-
[SWF(width = 400, height=600, frameRate=12)]
-
var loader:URLLoader = new URLLoader();
-
var req:URLRequest = new URLRequest("http://search.twitter.com/search.atom");
-
var vars:URLVariables = new URLVariables();
-
vars.q = "I'm";
-
// results per page
-
vars.rpp = "7";
-
vars.page = 1;
-
-
req.data = vars;
-
req.method = URLRequestMethod.GET;
-
-
loader.addEventListener(Event.COMPLETE, onLoaded);
-
loader.load(req);
-
-
// check for updates every 30 seconds -
-
var timer:Timer = new Timer(30000);
-
timer.addEventListener(TimerEvent.TIMER, onTick);
-
timer.start();
-
function onTick(evt:TimerEvent):void{
-
txt.htmlText = "loading...";
-
loader.load(req);
-
}
-
-
var txt:TextField = TextField(addChild(new TextField()));
-
txt.defaultTextFormat = new TextFormat("_sans", 12);
-
with (txt){ x=10, y=10, width=stage.stageWidth-10;
-
height=stage.stageHeight, multiline = true, wordWrap = true; }
-
txt.htmlText = "loading...";
-
-
function onLoaded(evt:Event):void{
-
var searchData:XML = new XML(loader.data);
-
var atom:Namespace = searchData.namespace("");
-
default xml namespace = atom;
-
var htmlText:String = "<b>Last " + vars.rpp + " '" + vars.q + "' tweets:</b><br><br>";
-
for each(var entry:XML in searchData.entry){
-
htmlText += entry.author.name.toString() + ": <br>";
-
htmlText += entry.title.toString() + "<br><br>";
-
}
-
txt.htmlText = htmlText;
-
}
Was curious about the twitter search api so spent a few minutes and whipped up a quick demo - the api is simple and easy to understand...
As a test I created something that shows the last 7 tweets including the phrase I'm. A new search is done every 30 seconds... I chose the phrase I'm so that there will be different results every time a new search is done...
Below is the swf:
This movie requires Flash Player 9
I noticed that there might be some kind of caching going on as sometimes it loads the same result 2 times in a row... if you need fresh results everytime you can do this:
vars.page = int(Math.random()*100);
... not perfect but randomly chooses from 100 pages of results
One Trackback
[...] I’m Twitter Search [...]