Desperately need help with AS3 and Twitter Feed!!!!
hi all,
i have taken on developer , trying add twitter feed flash application. twitter feed shows, first title , loops. doesn't show other tweets, first title , repeats on , on again. please me i'm desperate fix it.
here's source code twitter.as
i using flash develop render main.swf, i'm sure code below twitter feed wrong it's not showing more 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;
/**
* ...
* @author 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 use proxy due security sandbox issues if call twitter url directley 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; < tweetlist.length(); i++)
{
tweetitem = tweetlist[i].*::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!");
}
}
}
first of all, tweetlist xmllist length 1. use e4x notation instead of old children() here, might suggest changing this:
var tweetlist:xmllist = twitterxml.children();
in gettweets() method to:
var tweetlist:xmllist = twitterxml.channel.item;
then have items. did output of them:
for (var i:int = 0; < tweetlist.length(); i++)
{
trace(tweetlist[i].title);
}
also, had no trouble calling twitter directly flash using:
var loader:urlloader = new urlloader();
loader.load(new urlrequest("https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=ppc_creative"));
loader.addeventlistener(event.complete, gettweets);
however, there typo in had posted - had space in url - after c in c reative...
More discussions in ActionScript 3
adobe
Comments
Post a Comment