Desperately need help with AS3 and Twitter Feed!!!!
Hi all,
I have taken over from another developer and am trying to add a twitter feed to my flash application. The twitter feed shows, but only the first title and loops. It doesn't show the other tweets, just the first title and repeats over and over again. Please help me with this as i'm desperate to fix it.
Here's my source code for Twitter.as
I am using Flash Develop to render the main.swf, but I'm sure the code below for the twitter feed is wrong as it's not showing more then 1 tweet.
package src.main
{
import com.greensock.TweenMax;
import com.theppc.cmstools.CmsVars;
import com.theppc.cmstools.TextTool;
import com.theppc.visualtools.DrawBox;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.errors.IOError;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.events.TimerEvent;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.text.TextFieldAutoSize;
import flash.utils.Timer;
import src.utils.TitleBlock;
import com.greensock.easing.Back;
import com.greensock.easing.Strong;
import src.Main;
import src.utils.HandleXml;
/**
* ...
* @7111211 Joshua King
*/
public class TwitterBox extends MovieClip
{
private var _title:TitleBlock;
private var _bg:Sprite
private var _width:int;
private var _height:int;
private var _tweetholder:MovieClip;
private var _txt:ContentTxt;
private var _mask:Sprite;
private var _user:String = 'PPC_Creative';
private var _tweetcount:int = 5;
private var _tweets:Array = [];
private var _times:Array = [];
private var _gap:Number = 55;
private var _tweetmove:int = 0;
public function TwitterBox(_w:int, _h:int)
{
_width = _w;
_height = _h;
init();
}
private function init():void
{
_bg = new Sprite();
addChild(_bg);
_bg.graphics.lineStyle(1,0x00ccff);
_bg.graphics.beginFill(0xFFFFFF);
_bg.graphics.drawRect(0,0,_width,_height);
_bg.graphics.endFill();
_tweetholder = new MovieClip();
_tweetholder.y = 55;
_tweetholder.x = 5;
addChild(_tweetholder);
_mask = new Sprite();
_mask.graphics.beginFill(0xF09FFF);
_mask.graphics.drawRect(0,_gap,_width,_height - _gap - 5);
_mask.graphics.endFill();
addChild(_mask);
_tweetholder.mask = _mask;
_txt = new ContentTxt();
_txt.txt.text = '';
_txt.alpha = 0;
_txt.txt.width = 537;
_txt.txt.height = _height - _gap - 5;
_tweetholder.addChild(_txt);
addContentboxes();
}
private function addContentboxes():void
{
_title = new TitleBlock(Main._sitedata['text'][5].child, 547);
addChild(_title);
addTweets();
}
public function addTweets():void
{ /*
var urlReq:URLRequest = new URLRequest(_url);
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, getTweets);
loader.addEventListener(IOErrorEvent.IO_ERROR, IOError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, SError);
loader.load(urlReq);
*/
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, getTweets);
var url:String = "https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=PPC_Creative";
//have to use a proxy due to security sandbox issues if you call this twitter url directley from flash
var req:URLRequest = new URLRequest(CmsVars.PHP_ROOT + 'rssProxy.php?rss=' + url)
trace(CmsVars.PHP_ROOT + 'rssProxy.php?rss=' + url);
loader.load(req)
}
private function getTweets(evt:Event):void
{
var twitterXML:XML = new XML(evt.target.data);
var tweetList:XMLList = twitterXML.children();
var tweetItem:String;
var timeItem:String;
var _counter:int = 0;
_tweetmove = 0;
_tweets = [];
for (var i:int = 0; i < tweetList.length(); i++)
{
tweetItem = tweetList.*::title;
trace(tweetItem);
if (tweetItem != "")
{
_tweets.push(tweetItem);
_counter++
if (_counter >= _tweetcount)
{
break;
}
}
}
moveTweet();
}
private function moveTweet():void
{
_txt.alpha = 0;
TextTool.setText(_txt.txt, _tweets[_tweetmove], true);
TweenMax.to(_txt, 1, { delay:1, alpha:1, overwrite:0 } );
TweenMax.to(_txt, 1, { delay:12, alpha:0, overwrite:0, onComplete:moveTweet } );
_tweetmove++
if (_tweetmove >= _tweets.length) _tweetmove = 0;
}
private function IOError(e:Event):void
{
trace("io error!");
}
private function SError(e:Event):void
{
trace("security error!");
}
}
}
