Actionscript:
-
[SWF(width = 800, height=600, frameRate=15)]
-
-
var littleTxt:TextField = TextField(addChild(new TextField()));
-
with (littleTxt){
-
defaultTextFormat = new TextFormat("_sans", 10);
-
width = stage.stageWidth-20;
-
height = stage.stageHeight-20;
-
multiline = true;
-
wordWrap = true;
-
text ="";
-
textColor = 0x444444;
-
selectable = false;
-
x = y = 10;
-
}
-
-
var txt:TextField = TextField(addChild(new TextField()));
-
with (txt){
-
defaultTextFormat = new TextFormat("_sans", 90);
-
autoSize = "center";
-
x = 0
-
y = stage.stageHeight / 2 - 61
-
width = stage.stageWidth;
-
selectable = false;
-
text = "loading";
-
}
-
-
var selectWords:Array = [];
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
function onLoop(evt:Event):void {
-
if (selectWords.length> 0){
-
var word:String = selectWords[int(Math.random() * selectWords.length)];
-
txt.text = word;
-
littleTxt.appendText(word+" ");
-
}
-
}
-
-
var loader:URLLoader = new URLLoader();
-
var req:URLRequest = new URLRequest("http://search.twitter.com/search.atom");
-
var vars:URLVariables = new URLVariables();
-
vars.q = "i want";
-
// results per page
-
vars.rpp = "50";
-
vars.page = 1;
-
vars.lang = "en";
-
-
req.data = vars;
-
req.method = URLRequestMethod.POST;
-
loader.load(req);
-
loader.addEventListener(Event.COMPLETE, onLoaded);
-
function onLoaded(evt:Event):void{
-
var searchData:XML = new XML(loader.data);
-
var atom:Namespace = searchData.namespace("");
-
default xml namespace = atom;
-
var titles:String = "";
-
for each(var entry:XML in searchData.entry){
-
titles += entry.title.toString();
-
}
-
var index:int = 0;
-
var words:Array = titles.split(" ");
-
for (var i:int = 0; i<words.length; i++){
-
// exclude a few things
-
if (words[i].match(/RT|\@|\#|http/g).length == 0){
-
selectWords[index++] = words[i];
-
}
-
}
-
}
This snippet searches twitter for the phrase "I want" and then displays the results randomly word by word in a somewhat hypnotic way.
5 Comments
This doesnt work properly (the layout) when I do it from a flex builder as3 project.
try tracing out your stage.stageWidth and stage.stageHeight values… you may need to add a delay to make sure they are properly populated…. I’ll check it in flex real quick to see if it happens to me…
just tested it in flex… works fine with a fixed width/height swf… just don’t forget to add this:
[SWF(width = 800, height=600, frameRate=15)]
and if you want to scale the swf use those hardcoded values 800, 600 rather than reading the stage width and height… if you want to scale the swf and not the text you’ll need to do something a tad different…
you should get on twitter. Even if you have an automated tweet that happens when you update, there are a lot of people that would really regular updates on your work here ( myself included )
- best
Brendan
hmmm the automated twitter thing is a good idea… since people have tweetdeck and stuff running… I may do that in the next day or two. Thanks for the idea Brendan.