Skip navigation
Claunchster
Currently Being Moderated

AS3 iOS Twitter Reader not working

Feb 8, 2012 9:13 PM

Tags: #class #action_script_3;ios;

I created a Twitter Feed reader using a tut from fladev.com.  By itself, it works GREAT! However when I try to incoroporate it into my fla for compiling into my ipa it doesn't work in my swf.  I know that if I compile the twitter reader at runtime with my main fla that it won't work in my ipa because my swf has a class as running in it. But when I try putting my twitter reader directly into my main fla I get nothing! My scene loads but it pulls down no data. Here is my class code that I am using:

 

package fladev.twitter

{

          import flash.display.Loader;

          import flash.display.Sprite;

          import flash.display.MovieClip

          import flash.events.Event;

          import flash.events.SecurityErrorEvent;

          import flash.net.URLLoader;

          import flash.net.URLRequest;

          import flash.text.TextField;

          import flash.events.MouseEvent;

 

  public class MainClass extends Sprite

          {

                    public var content_txt:TextField;

                    public var posted_txt:TextField;

                    public var info_txt:TextField;

                    public var name_txt:TextField;

                    public var btnhome:MouseEvent;

 

  private static const USERNAME:String = "mytwitterid";

                    private static const URL:String = "http://pathtomyphp.com/proxy.php";

  private static const REQUEST:String = URL + USERNAME;

 

                    private var urlLoader:URLLoader;

                    private var xml:XML;

                    private var loader:Loader;

                    private var num:Number = 5;

 

                    public function MainClass() {

                              urlLoader = new URLLoader();

                              urlLoader.load(new URLRequest(REQUEST));

                              urlLoader.addEventListener(Event.COMPLETE, displayInfo);

                              urlLoader.addEventListener(SecurityErrorEvent.SECURITY _ERROR, onSecurity);

                    }

 

                    private function onSecurity(e:SecurityErrorEvent):void

                    {

 

                    }

 

                    private function displayInfo(e:Event):void

                    {

                              xml = new XML(e.target.data);

                              content_txt.htmlText = getContent(0) +  getContent(1) +  getContent(2)+ getContent(3);

                               info_txt.text = "Followers: " + xml.status[num].user.followers_count + "; " + "Following " + xml.status[num].user.friends_count + "; " + "Tweets " + xml.status[num].user.statuses_count + ";";

 

  name_txt.text = xml.status[num].user.screen_name;

 

  loader = new Loader();

                              loader.load(new URLRequest(xml.status[num].user.profile_image_url));

                              addChildAt(loader, 1);

                              loader.x = 116;

                              loader.y = 102;

                    }

 

                    private function getContent(num:Number) {

  var posted:String = xml.status[num].created_at;

 

                              var content:String = "<font color='#224466'><a href=" + '"http://twitter.com/' + USERNAME + "/statuses/" + xml.status[num].id + '" target="_blank">' + xml.status[num].text + "</a></font><br/><font size='9'>" +"Posted on: " + posted.substr(0, posted.length - 11) + "; " + "From: " + xml.status[num].source + "</font><br/><br/>";

  return content;

                    }

          }

 

}

 

Like I said, on its own, it works great, just not when I try to create a new scene in an existing fla.


Thanks in advance for any advice you can give me.  I'm a little bit of an as3 newbie, so please bare with me . . .

 
Replies
  • kglad
    62,001 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 8, 2012 10:10 PM   in reply to Claunchster

    is MainClass your document class?

     
    |
    Mark as:
  • kglad
    62,001 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 9, 2012 7:36 AM   in reply to Claunchster

    when you use MainClass as your document class does it work the way you expect?

     

    if yes, and you're trying to change it to a non-document class, you need to use a stage reference to access those textfields and you need to add twitterReader to the stage asap.   but that would be a different error than the one you're seeing.

     

     

    private function displayInfo(e:Event):void

            {

                var _root:MovieClip = MovieClip(this.root);  // assuming you add this class instance to the main timeline before loading is complete.

                xml = new XML(e.target.data);                   

                _root.content_txt.htmlText = getContent(1) +  getContent(2)+ getContent(3) + getContent(4);   

                //trace(xml);

                //show some info about the user

                _root.info_txt.text = "Followers: " + xml.status[num].user.followers_count + "; " + "Following " + xml.status[num].user.friends_count + "; " + "Tweets " + xml.status[num].user.statuses_count + ";";

               

                //display the user account

                _root.name_txt.text = xml.status[num].user.screen_name;

               

                //create a loader for picture

                loader = new Loader();

                loader.load(new URLRequest(xml.status[num].user.profile_image_url));

                _root.addChildAt(loader, 1);

                loader.x = 116;

                loader.y = 102;

            }

     
    |
    Mark as:
  • kglad
    62,001 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 9, 2012 1:19 PM   in reply to Claunchster

    if you were using MainClass as your document class, there should have been no problems.  were there?

     
    |
    Mark as:
  • kglad
    62,001 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 9, 2012 1:55 PM   in reply to Claunchster

    start over.  download the files from your tutorial.  any problem if you use the files from the tutorial?

     
    |
    Mark as:
  • kglad
    62,001 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 9, 2012 2:44 PM   in reply to Claunchster

    ok, now start with the sample fla from that website,

     

    1.  remove the document class,

    2.  change the code in MainClass to the class i showed and

    3.  add a MainClass instance to the fla's main timeline using:

     

    var mc:MainClass=new MainClass();

    addChild(mc);

     

    4.  test.

     
    |
    Mark as:
  • kglad
    62,001 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 9, 2012 9:56 PM   in reply to Claunchster

    put MainClass in the same directory with your fla, swf, html

     
    |
    Mark as:
  • kglad
    62,001 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 10, 2012 5:45 AM   in reply to Claunchster

    use:

     

     

    // timeline
    var mc:MainClass=new MainClass();

    addChild(mc);

     

     

    // MainClass:

    package

    {

              import flash.display.Loader;

              import flash.display.Sprite;

              import flash.display.MovieClip

              import flash.events.Event;

              import flash.events.SecurityErrorEvent;

              import flash.net.URLLoader;

              import flash.net.URLRequest;

              import flash.text.TextField;

     

           public class MainClass extends Sprite

              {

                        public var content_txt:TextField;

                        public var posted_txt:TextField;

                        public var info_txt:TextField;

                        public var name_txt:TextField;

     

                        private static const USERNAME:String = "ctistechapps";

                        private static const URL:String = "http://preview.fladev.com/how-to-build-a-flash-actionscript-3-0-twitte r-widget/proxy.php?url=";

                        private static const REQUEST:String = URL + USERNAME;

     

                        private var urlLoader:URLLoader;

                        private var xml:XML;

                        private var loader:Loader;

                        private var num:Number = 1;//display first post info, you can use also ?count=5

     

                        public function MainClass() {

                                  urlLoader = new URLLoader();

                                  urlLoader.load(new URLRequest(REQUEST));

                                  urlLoader.addEventListener(Event.COMPLETE, displayInfo);

                                  urlLoader.addEventListener(SecurityErrorEvent.SECURITY _ERROR, onSecurity);

                        }

     

                        private function onSecurity(e:SecurityErrorEvent):void

                        {

     

                        }

     

                        private function displayInfo(e:Event):void

            {

                var _root:MovieClip = MovieClip(this.root);  // assuming you add this class instance to the main timeline before loading is complete.

                xml = new XML(e.target.data);                  

                _root.content_txt.htmlText = getContent(0) +  getContent(1)+ getContent(2) + getContent(3);  

                //trace(xml);

                //show some info about the user

                _root.info_txt.text = "Followers: " + xml.status[num].user.followers_count + "; " + "Following " + xml.status[num].user.friends_count + "; " + "Tweets " + xml.status[num].user.statuses_count + ";";

              

                //display the user account

                _root.name_txt.text = xml.status[num].user.screen_name;

              

                //create a loader for picture

                loader = new Loader();

                loader.load(new URLRequest(xml.status[num].user.profile_image_url));

                _root.addChildAt(loader, 1);

                loader.x = 116;

                loader.y = 102;

            }

     

                        private function getContent(num:Number) {

                                  //show just month, day and hour

                                  var posted:String = xml.status[num].created_at;

     

                                  var content:String = "<font color='#224466'><a href=" + '"http://twitter.com/' + USERNAME + "/statuses/" + xml.status[num].id + '" target="_blank">' + xml.status[num].text + "</a></font><br/><font size='9'>" +"Posted on: " + posted.substr(0, posted.length - 11) + "; " + "From: " + xml.status[num].source + "</font><br/><br/>";

                                  //return all info

                                  return content;

                        }

              }

     

    }

     
    |
    Mark as:
  • kglad
    62,001 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 10, 2012 7:31 AM   in reply to Claunchster
     
    |
    Mark as:
  • kglad
    62,001 posts
    Jul 21, 2002
    Currently Being Moderated
    Feb 10, 2012 8:17 AM   in reply to Claunchster

    i'm not sure.  i think your fla might have had some setting that wasn't allowing it to see the MainClass file in the same directory as the flash files.

     

    i am sure the fla from that website had some setting that caused a problem with paths.  i didn't realize it until i made those files this morning.  i couldn't determine the problematic setting so i created a new fla (with standard publish settings) and copied the frames from that website's fla to the new fla at which point everything worked, as expected.

     

    p.s.  please mark helpful/correct responses.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points