PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Flash8 Please help debug my Twitter code - it's mostly working!!
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Please help debug my Twitter code - it's mostly working!!

  1. #1
    Senior Member
    Join Date
    Oct 2004
    Location
    London
    Posts
    186

    Unhappy Please help debug my Twitter code - it's mostly working!!

    Please help me!! Maybe this will be useful to others trying to do the same thing. I'm importing the last 5 tweets into Flash, but saving the data in a sharedObject.

    The code works when I bypass the 'loadTwitterDataFromFlashCookie' function and go straight to the 'loadTwitterXML();' function. If I use the 'loadTwitterDataFromFlashCookie' at the start, it traces:

    256 levels of recursion were exceeded in one action list.
    This is probably an infinite loop.
    Further execution of actions has been disabled in this movie.


    I'm using setInterval later on in the code to create a 'typewriter' effect. I don't know if it's this, or something else causing the problem?!

    Please, please help!!

    Actionscript Code:
    var twitterXML:XML; // This holds the xml data
    var cachedTwitterData:SharedObject; // This stores the data loaded from the Flash cookie
    var twitterPHPScriptPath:String;
    var myTwitterID:String;
    var wereAllowedToWriteToTheFlashCookie:Boolean; // You can use this value to decide whether or not to make repeated save attempts
    var intervalId:Number;
    var count:Number = 0;
    var duration:Number = 5000;
     
    //Put your Twitter username here.  For example, ours is "untoldEnt" :
    myTwitterID = "aneemal";
    // Put the path to your php script here:
    twitterPHPScriptPath = "tweet.php";
    wereAllowedToWriteToTheFlashCookie = true; // (let's be optimistic until we discover otherwise)
    // Check to see if the user has already retrieved the Twitter updates and stored them in a Flash cookie:
    loadTwitterDataFromFlashCookie();
    //loadTwitterXML();
     
    function loadTwitterDataFromFlashCookie() {
        // Call up the Twitter data from the Flash cookie on the user's machine:
        cachedTwitterData = SharedObject.getLocal("twitter");
        var timeStamp:Date = cachedTwitterData.data.timeStamp;
        if (timeStamp != null) {
            // The timeStamp variable is in there, which means we've retrieved Twitter info for this user at some point.
            // Now let's check the timeStamp. If the last time we grabbed Twitter data was too long ago, let's grab fresh info:
            if (hasExpired(timeStamp)) {
                // The most recent copy of the Twitter data in the Flash cookie is old!  Let's get some fresh data:
                trace("cookie has expired!  let's get some fresh data");
                loadTwitterXML();      
            } else {
                // It hasn't been very long since we grabbed a fresh copy of the Twitter data. Let's just use what we've got in the Flash cookie:
                trace("cookie is fresh. display the data.");
                twitterXML = cachedTwitterData.data.twitterXML;
                showTwitterStatus();
            }
        } else {
            // If there's no timeStamp variable in there, then the cookie's empty.  We need to hit Twitter to grab our data for the first time.
            loadTwitterXML();              
        }          
    };
     
    function saveTwitterDataToFlashCookie() {
        flushStatus = cachedTwitterData.flush(10000);
        if (flushStatus == true) {
            trace("********* save complete. ***********\n");
            finishedHandlingTwitterData();
        } else if (flushSatus == false) {
            trace("User denied permission -- value not saved.\n");
            wereAllowedToWriteToTheFlashCookie = false;
        }
    };
     
    function finishedHandlingTwitterData() {
        trace("Twitter data saved.");
    };
     
    function hasExpired(timeStamp:Date) {
        // Store the date RIGHT NOW, to compare against the Flash cookie timeStamp:
        var now:Date = new Date();
        // Let's say that the cookie expires after 1 hour, 0 minutes and zero seconds:
        var expiryHours:Number = 1;
        var expiryMinutes:Number = 0;
        var expirySeconds:Number = 0;
     
        // Store some handy conversion values:
        var msPerHour:Number = 3600000;
        var msPerMinute:Number = 60000;
        var msPerSecond:Number = 1000;
     
        // Multiply those values to get the expiry time in milliseconds:
        var expiryTime:Number = (expiryHours * msPerHour) + (expiryMinutes * msPerMinute) + (expirySeconds * msPerSecond);
     
        // Return whether or not the timeStamp is past the expiry date:
        return (now.getTime() - timeStamp.getTime() > expiryTime)
    };

    function loadTwitterXML() {
        var getTwitter:XML = new XML();
        getTwitter.ignoreWhite = true;
        xmlnodes = [];
        tweets = [];
        getTwitter.onLoad = function(success:Boolean) {
            if (success) {
                //trace(getTwitter.firstChild.childNodes);
                newNode = this.firstChild.childNodes.length;
                for (i = 0; i < newNode; i++) {
                    xmlnodes.push(this.firstChild.childNodes[i]);
                    //xmlnodes.push(this.firstChild.childNodes[i])
                    if (xmlnodes[i].childNodes[2].nodeName == "text") {
                        // it's a tweet, process it
                        //trace(xmlnodes[i].childNodes[2].firstChild.nodeValue);
                        tweets.push(xmlnodes[i].childNodes[2].firstChild.nodeValue);
                    } else {
                        twitter_txt.text = "Error connection with Twitter.";
                    }
                }
                //trace (tweets);
                _global.maxtweet = tweets.length;
                trace (_global.maxtweet);
                finishLoadingXML();
            } else {
                trace ("Error loading php");
            }
        }
        getTwitter.load(twitterPHPScriptPath + "?twitterId=" + myTwitterID);           
    };
     
    function finishLoadingXML() {
        // Populate the xml object with the xml data:
        cachedTwitterData = SharedObject.getLocal("twitter");
        // Set the date/time RIGHT NOW:
        cachedTwitterData.data.timeStamp = new Date();
        twitterXML = tweets;
        // Store the twitterXML data:
        cachedTwitterData.data.twitterXML = twitterXML;
        // (Try to) save the whole shebang the user's Flash cookie:
        saveTwitterDataToFlashCookie();
        showTwitterStatus();
    };

    var q:Number = 1;
    var typeSpeed:Number = 20; // time between letters in milliseconds;

    function type():Void {
        tweet_mc.twitter_txt.text = myTweet.substring(0, q);
        q++;
        if (q == myTweet.length) {
            //trace("finished");
            q=0;
            intervalId = setInterval(_root,"executeCallback",duration);
            clearInterval(typeInterval);
        }
    };

    function executeCallback():Void {
        clearInterval(intervalId);
        if (count < _global.maxtweet) {
            trace(count);
            myTweet = twitterXML[count];
            typeInterval = setInterval(_root, "type", typeSpeed, myTweet);
        } else {
            count = 0;
            executeCallback();
        }
        count++;
    };
     
    function showTwitterStatus() {
        twitter_txt.wordWrap = true;
        twitter_txt.autoSize = true
        var curr:String = twitterXML[count];
        executeCallback();
    };
    Last edited by aneemal; 03-07-2010 at 05:48 AM.

  2. #2
    Senior Member
    Join Date
    Oct 2004
    Location
    London
    Posts
    186
    Any ideas? Should I upload the .Fla?

  3. #3
    Senior Member
    Join Date
    Oct 2004
    Location
    London
    Posts
    186

    Desperate!

    Please, please, please...

    I'm uploading the file... I really need to get this working. I have it working locally, on my localhost, but as soon as I change the url paths to absolute, I get that same error message as above.

    I would really appreciate any help... I can pay something toward your time, if need be? Is that allowed here?

    Here is the php:
    PHP Code:
    <?php
     
    $twitterId 
    = isset($_REQUEST["twitterId"]) ? $_REQUEST["twitterId"] : '';
    if( 
    $twitterId == "" ){
                    exit;
    }
    $file file_get_contents("http://twitter.com/statuses/user_timeline/" $twitterId  ".xml?count=5" );
    echo 
    $file;
     
    ?>
    Attached Files Attached Files

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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center