Originally Posted by
***musica***
Hello All
I'm adding a twitter feed to an older flash site that use's AS2, the code below works fine in AS3 but I need it translated into AS2 for obvious reasons...
Can anybody help me with this! I need this translated into AS2 ?? :-/
Thank you in advance
Code:
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("twitter.php"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
var myXML:XML=new XML(e.target.data);
tweet_1.text=myXML.status[0].text;
tweet_2.text=myXML.status[1].text;
tweet_3.text=myXML.status[2].text;
}
PHP Code:
package
{
/**********************************************
*
* This fun Twitter widget is brough to you
* by Untold Entertainment Inc, and
* peanut butter! Peanut butter: a gooey,
* yummy snack that might kill you.
*
* http://www.untoldentertainment.com
*
**********************************************/
// Here are all the goodies you're going to need
import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLLoader;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
public class Main extends MovieClip
{
private var twitterXML:XML; // This holds the xml data
public function Main()
{
// Put your Twitter username here. For example, ours is "untoldEnt" :
var myTwitterID:String = "myTwitterID";
// Put the path to your php script here:
var twitterPHPScriptPath:String = "http://www.yourdomain.com/thePathToYourPHPScript";
// Fire the loadTwitterXML method, passing it the url to your Twitter info:
loadTwitterXML(twitterPHPScriptPath + "?twitterId=" + myTwitterID);
}
private function loadTwitterXML(URL:String):void
{
var urlLoader:URLLoader = new URLLoader();
// When all the junk has been pulled in from the url, we'll fire finishedLoadingXML:
urlLoader.addEventListener(Event.COMPLETE, finishLoadingXML);
urlLoader.load(new URLRequest(URL));
}
private function finishLoadingXML(e:Event = null):void
{
// All the junk has been pulled in from the xml! Hooray!
// Remove the eventListener as a bit of housecleaning:
e.target.removeEventListener(Event.COMPLETE, finishLoadingXML);
// Populate the xml object with the xml data:
twitterXML = new XML(e.target.data);
showTwitterStatus();
}
private function showTwitterStatus():void
{
// Uncomment this line if you want to see all the fun stuff Twitter sends you:
//trace(twitterXML);
// Prep the text field to hold our latest Twitter update:
twitter_txt.wordWrap = true;
twitter_txt.autoSize = TextFieldAutoSize.LEFT;
// Populate the text field with the first element in the status.text nodes:
twitter_txt.htmlText = twitterXML.status.text[0];
}
}
}
And PHP File:
PHP Code:
<?php
$twitterId = isset($_REQUEST["twitterId"]) ? $_REQUEST["twitterId"] : '';
if( $twitterId == "" ){
exit;
}
$file = file_get_contents("http://twitter.com/statuses/user_timeline/" . $twitterId . ".xml" );
echo $file;
?>