|
-
Auto-Refresh.....
Hi all, further from my last post I now need a section of code to auto-refresh every 30 seconds or so. So far my code takes hex codes out of tweets containing a certain hashtag, and draws a square of that hex code colour. If someone were to tweet a new set of hexcodes while you were looking at the site, you would have to manually refresh the page to see the new squares. Here is my code so far, I'm hoping this is simple to do! I'll be so grateful for any help.
Actionscript Code:
import flash.net.URLLoader;
var myXMLLoader:URLLoader = new URLLoader(); var myXML:XML; myXMLLoader.load(new URLRequest("http://search.twitter.com/search.rss?q=%23twitmosaic")); myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void{ myXML = new XML(e.target.data); trace('FROM FUNCTION:'+ myXML.channel.item[0].title); trace (myXML.channel.item.length()); //tweetsArray[0] = myXML.channel.item[0].title; for (var l:int = 0; l < myXML.channel.item.length();l++) { trace(l); splitStrings(l); } chooseColour(); }
var hexes:Array = []; var squareX:int = 275; var squareY:int = 200; var countX:int = 0;
function splitStrings(currentTweet: int):void{ hexes.clear; var bigString:String = myXML.channel.item[currentTweet].title; var tags:Array = bigString.split(" "); for (var i:int =0; i < tags.length; i++){ var tag:String = tags[i].substring(1); //remove first char, which is "#" trace('TAG '+tag); if (tag == 'twitmosaic'){ trace('twitmosaic ignored'); } else if(hexes.length < 100){ hexes.push(tag); trace('added to array ' +hexes); } else{ trace('array full'); } } }
//finishedHex = 0x += 6 numbers variable
function checkPosition():void{ if (countX == 10){ countX = 0; squareX = 275; squareY += 25; } }
function chooseColour():void{ for(var i=0;i<hexes.length;i++){ var aHexVariable = hexes[i]; trace(aHexVariable); var finishedHex = '0x'+aHexVariable; checkPosition(); drawSquare(finishedHex); } }
function drawSquare(currentColour: int):void{ var square:Sprite = new Sprite(); addChild(square); square.graphics.beginFill(currentColour); square.graphics.drawRect(0,0,25,25); square.graphics.endFill(); squareX += 25; square.x = squareX; square.y = squareY; countX ++; }
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|