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 [RESOLVED] Twitter Updates via php/xml
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] Twitter Updates via php/xml

  1. #1
    Senior Member
    Join Date
    Oct 2004

    resolved [RESOLVED] Twitter Updates via php/xml

    Hi all,

    I'm trying (desperately) to re-work the code here (AS3) to AS2...

    First time I'm using sharedObject and also, bit confused about calling the .xml file via the php.

    Here's the actionscript:

    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
    //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:
    function loadTwitterDataFromFlashCookie() {
        // Call up the Twitter data from the Flash cookie on the user's machine:
        cachedTwitterData = SharedObject.getLocal("twitter");
        var timeStamp:Date =;
        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");
            } 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 =;
        } 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.
    function saveTwitterDataToFlashCookie() {
        flushStatus = cachedTwitterData.flush(10000);
        if (flushStatus == true) {
            trace("********* save complete. ***********\n");
        } 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;
        getTwitter.onLoad = function(success:Boolean) {
            if (success) {
            } 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: = new Date();
        twitterXML = new XML;
        // Store the twitterXML data: = twitterXML;
        // (Try to) save the whole shebang the user's Flash cookie:
    function showTwitterStatus() {
        // Uncomment these lines if you want to see all the fun stuff Twitter sends you:
        // Prep the text field to hold our latest Twitter update:
        twitter_txt.wordWrap = true;
        twitter_txt.autoSize = true
        // Populate the text field with the first element in the status.text nodes:
        twitter_txt.text = twitterXML;

    And here's the php:
    PHP Code:
    = isset($_REQUEST["twitterId"]) ? $_REQUEST["twitterId"] : '';
    $twitterId == "" ){
    $file file_get_contents("" $twitterId  ".xml" );
    Please, please, please, help me get this project off the ground!

    Many thanks for any input.

  2. #2
    Senior Member
    Join Date
    Oct 2004
    Ok, I've managed to get this working... if interested, please see my next thread for script.

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