Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Desperately need help with AS3 and Twitter Feed!!!!

New Here ,
Jan 31, 2013 Jan 31, 2013

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;

          /**

           * ...

           * @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 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!");

                    }

          }

}

TOPICS
ActionScript
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Jan 31, 2013 Jan 31, 2013

First of all, your tweetList XMLList length is only 1. I like to use E4X notation instead of the old children() as you are here, so I might suggest changing this:

var tweetList:XMLList = twitterXML.children();

in your getTweets() method to:

var tweetList:XMLList = twitterXML.channel.item;

Then you have all your items. I just did like so to output all of them:

for (var i:int = 0; i < tweetList.length(); i++)

{

      trace(tweetList.title);

}

Also, I had no trouble calling Twitter directly from Flash usin

...
Translate
Guest
Jan 31, 2013 Jan 31, 2013

First of all, your tweetList XMLList length is only 1. I like to use E4X notation instead of the old children() as you are here, so I might suggest changing this:

var tweetList:XMLList = twitterXML.children();

in your getTweets() method to:

var tweetList:XMLList = twitterXML.channel.item;

Then you have all your items. I just did like so to output all of them:

for (var i:int = 0; i < tweetList.length(); i++)

{

      trace(tweetList.title);

}

Also, I had no trouble calling Twitter directly from 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 is a typo in what you had posted - you had a space in the URL - after the C in C reative...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 31, 2013 Jan 31, 2013

Thanks dmeN for your help. I'm going to try and fix the problem tomorrow hopefully. Your message has helped a lot and I hope tomorrow I can fix it and have a good Friday! Thanks again

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2013 Feb 01, 2013
LATEST

I tried this today and it worked perfectly! Thanks so so so so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines