469,934 Members | 1,873 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

Twitter xml value not loading into FOR loop (AS2)

This is my first post on your site, so let me begin by thanking all you geniuses who so thoughtfully and effectively answer frequently asked questions that until now I have been able to find solutions to my Actionscript quarries without having needed to ask a question myself. Kudos! The problem I’m having is quite specific to my context but I will try to make it as general as I can to make it relevant to other users scenarios as well. Right of the bat, my project makes use of Actionscript 2 and works with XML, Twitter API, and a FOR loop. The basic thing in which I am trying to achieve is to create a flash widget for my website that captures my last four tweets from the online XML using Twitter API and outputs it into my dynamic text boxes on stage. This all works fine. The next step I plan to take is to pull all the profile pictures of all my followers and display them tiled (or randomly placed) on stage. Before I get into that I’m trying something a little simpler with the follower count. Basically I access my follower count from the online Twitter XML and trace it to make sure I have the number. Then, using the follower count number - in the form of a variable called “follower_count”- I try to load that many instances of a movie-clip (from my library) onto stage using a FOR loop. Everything seems to be working fine including the loop; however, the variable “follower_count” is returning a value of “0” when placed in the loop instead of my actual follower count from the XML. I’ve tested this exact code with any specific number representing the condition instead of “follower_count” and it works just as I expect it to. But now I am confused as to why the “follower_count” is not working even though when I trace it, it returns the correct number of followers I have. I am really drawing a blank on this one and I feel as though I have tried just about everything. Please if any of you have any advice to offer me I would greatly appreciate it.

Many Thanks

Expand|Select|Wrap|Line Numbers
  1. var loadXML:XML = new XML();
  2. loadXML.ignoreWhite = true;
  3. loadXML.onLoad = processXML;
  4. //loadXML.load("twitter.php"); //used when swf in placed on server
  5. loadXML.load("http://twitter.com/statuses/user_timeline.xml?screen_name=sabctoo");
  7. function processXML(loaded:Boolean)
  8. {
  9.     if(loaded)
  10.     {
  12.         var node = this.firstChild;
  13.         tweet_1.text = node.childNodes[0].childNodes[2].firstChild;
  14.         tweet_2.text = node.childNodes[1].childNodes[2].firstChild;
  15.         tweet_3.text = node.childNodes[2].childNodes[2].firstChild;
  16.         tweet_4.text = node.childNodes[3].childNodes[2].firstChild;
  18.         var follower_count = node.childNodes[9].childNodes[11].childNodes[9].firstChild;// Creates variable
  19.         trace(follower_count); //loads variable into output
  21.         follower_count_txt.text = follower_count;// show follower count in text box
  23.     }
  25.     else 
  26.     {
  27.         error_txt.text = "Error loading XML file";
  28.     }   
  30.                 for (i=0; i<follower_count; i++) // <-- problem occurs here
  31.                     {
  32.                     _root.attachMovie("tweep_mc", "tweep"+i+"_mc", i);
  33.                     _root["tweep"+i+"_mc"]._x = 150 + random(500);
  34.                     _root["tweep"+i+"_mc"]._y = 150 + random(500);
  35.                     trace(i); 
  36.                     }
  38.                 trace(i);
  39. }
  41. follow_btn.onRelease = function()
  42. {
  43.     getURL("http:///twitter.com/sabctoo");
  44. }
Apr 19 '12 #1
0 1797

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Chris | last post: by
5 posts views Thread by Kurt Bauer | last post: by
3 posts views Thread by Gustavo Randich | last post: by
1 post views Thread by sksksk | last post: by
1 post views Thread by HaLo2FrEeEk | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.