Skip to main content
Participating Frequently
October 10, 2012
Question

If xml data is undefined, skip frames in timeline?

  • October 10, 2012
  • 1 reply
  • 538 views

Hi,

I am currently working on a twitter stream that accesses tweets from an online XML file (TweetRiver). My client wants the .swf to read the XML file and determine a) how many tweets are given in a said XML file and b) if only 3 (out of a possible 7) tweets are in the XML file, skip frames to a closing message across the stream. The problem I am having is that when I put in a if/else statement that will gotoAndPlay a certain frame if a variable is undefined, it reads the code from the beginning and doesn't show the tweets that ARE defined. In short, if three tweets are provided from the XML, I want AS3 to allow those tweets to run through the timeline and then when it gets to the fourth tweet, it reads as undefined, and calls the closing message to happen. That way, regardless of whether 1 or 6 tweets are in the XML file, it will show them and as soon as it doesn't have a tweet to send through, it ends.

Here is my code thus far -- I would DEARLY appreciate any help or pointers. I have been at this for hours and cannot figure out anything.

function Tweet()

{

    this.setTweet = function (t)

    {

        this.tweet = t;

    }

    ;

    this.getTweet = function ()

    {

        return this.tweet;

    }

    ;

}

var tweets = new Array();

var loadCount = 0;

var tweetLines = 1;

var tweet1 = "";

var tweet2 = "";

var tweet3 = "";

var tweet4 = "";

var tweet5 = "";

var tweet6 = "";

var tweet7 = "";

var tweet8 = "";

var i = 0;

if (i < 😎

{

    var myTweet = new Tweet();

    tweets.push(myTweet);

    ++i;

}

var feedOne = new XML();

var tweetXML = new XML();

feedOne.ignoreWhite = true;

feedOne.onLoad = function (loaded)

{

    if (loaded)

    {

                    myXML = feedOne.childNodes[0].childNodes;

                    tweets[0]=mx.xpath.XPathAPI.selectSingleNode(myXML[0], "/status/text").firstChild.nodeValue+"  -@"+mx.xpath.XPathAPI.selectSingleNode(myXML[0], "/status/user/screen_name").firstChild.nodeValue;

                    tweets[1]=mx.xpath.XPathAPI.selectSingleNode(myXML[1], "/status/text").firstChild.nodeValue+"  -@"+mx.xpath.XPathAPI.selectSingleNode(myXML[1], "/status/user/screen_name").firstChild.nodeValue;

                    tweets[2]=mx.xpath.XPathAPI.selectSingleNode(myXML[2], "/status/text").firstChild.nodeValue+"  -@"+mx.xpath.XPathAPI.selectSingleNode(myXML[2], "/status/user/screen_name").firstChild.nodeValue;

                    tweets[3]=mx.xpath.XPathAPI.selectSingleNode(myXML[3], "/status/text").firstChild.nodeValue+"  -@"+mx.xpath.XPathAPI.selectSingleNode(myXML[3], "/status/user/screen_name").firstChild.nodeValue;

                    tweets[4]=mx.xpath.XPathAPI.selectSingleNode(myXML[4], "/status/text").firstChild.nodeValue+"  -@"+mx.xpath.XPathAPI.selectSingleNode(myXML[4], "/status/user/screen_name").firstChild.nodeValue;

                    tweets[5]=mx.xpath.XPathAPI.selectSingleNode(myXML[5], "/status/text").firstChild.nodeValue+"  -@"+mx.xpath.XPathAPI.selectSingleNode(myXML[5], "/status/user/screen_name").firstChild.nodeValue;

                    tweets[6]=mx.xpath.XPathAPI.selectSingleNode(myXML[6], "/status/text").firstChild.nodeValue+"  -@"+mx.xpath.XPathAPI.selectSingleNode(myXML[6], "/status/user/screen_name").firstChild.nodeValue;

                    tweets[7]=mx.xpath.XPathAPI.selectSingleNode(myXML[7], "/status/text").firstChild.nodeValue+"  -@"+mx.xpath.XPathAPI.selectSingleNode(myXML[7], "/status/user/screen_name").firstChild.nodeValue;

                    gotoAndPlay(5);

 

    }

 

}

;

var randomOne = Math.floor(Math.random() * 100001);

feedOne.load("https://api.twitter.com/1/lists/statuses.xml?slug=team&owner_screen_name=twitter&include_entities=true");

stop();

_____________________________________________________

(on a seperate frame)

_____________________________________________________

finalText.txtTweet1.htmlText="Join the conversation on Twitter!;

ft = new TextFormat();

ft.font = "TungstenSemibold";

ft.size = 40;

finalText.txtTweet1.setTextFormat(ft);

THANKS SO MUCH FOR ANY HELP.    

This topic has been closed for replies.

1 reply

sethrrAuthor
Participating Frequently
October 10, 2012

Also, the tweets are being read and displayed correctly. I am just trying to figure out how to stop them from showing when they are undefined.

Thanks!