Hello, not sure the title is the most exact. but i’m on day 2 of learning as3 and not sure what the problem is exactly.
i’ve been putting together a script to parse twitter feeds via xml, add the html code to link any hyperlinks in the post and throw each resulting post into one of two textareas (box0 & box1).
unfortunatly it is printing all 3 (the amount so far posted) posts into each text box.
any tips on how to fix this code to a) put 1 post per box and b) limit the amount of posts it pulls from the xml, would be much appreciated.
thanks in advance for looking at the horrificly messy code
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
public class Twitter_Main extends MovieClip
{
public function Twitter_Main():void
{
initButton();
initTwit();
}
private function initButton():void
{
followBtn.buttonMode = true;
}
private function down(e:MouseEvent):void
{
followBtn.gotoAndStop(3);
followBtn.removeEventListener(MouseEvent.MOUSE_DOWN, down);
followBtn.addEventListener(MouseEvent.MOUSE_UP, follow);
}
private function follow(e:MouseEvent):void
{
navigateToURL(new URLRequest("http://twitter.com/HotPinkMag"), "_blank");
followBtn.removeEventListener(MouseEvent.MOUSE_UP, follow);
}
private function initTwit():void
{
var l:URLLoader = new URLLoader();
l.addEventListener(Event.COMPLETE, loaded);
l.load(new URLRequest("http://www.etherealdesign.co.uk/mc/twit.xml"));
}
private function loaded(e:Event):void
{
e.currentTarget.addEventListener(Event.COMPLETE, loaded);
var xml:XML = new XML(e.currentTarget.data);
var list:XMLList = new XMLList(xml.status.text);
var boxArray:Array = new Array();
for(var i:int = 0; i < 2; ++i){
/*boxArray* = this.getChildByName("box" + i);
boxArray*.textBox.appendText(list*);
*/
// ******************START parse**************************
var test:String = new String (xml.status.text);
trace(test);
var aWords:Array = test.split(" ");
var finalString:String = ""; //
var len:int = aWords.length;
for(var n:int = 0; n<len; n++)
{
var word:String = aWords[n];
finalString += " " + checkWord(word); // Run the word through a checkWord method, and tack the
// return value onto the end of our finalString (along with a space character, to space the words out)
}
function checkWord(word:String):String
{
if(word.indexOf("http:") == 0)
{
// This word starts with "http:" at index 0 (the beginning of the word)
// Wrap it in html href (anchor) tags:
return "<a href='" + word + "'>" + word + "</a>";
} else if (word.indexOf("@") == 0) {
// This word starts with "@" at index 0 (the beginning of the word)
var justTheName:String = word.substr(1, word.length); // Remove the "@" from the username
// We do this because we need to link to http://www.twitter.com/untoldent (for example),
// not http://www.twitter.com/@untoldent
// Wrap it in html href (anchor) tags:
return "<a href='http://www.twitter.com/" + justTheName + "'>" + word + "</a>";
} else {
// There's nothing special about this word. Return it as-is.
return word;
}
}
//******************************stop parse*****************************
boxArray* = this.getChildByName("box" + i);
boxArray*.textBox.htmlText = finalString;
}
}
}
}