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

AS3 iOS Twitter Reader not working

Community Beginner ,
Feb 08, 2012 Feb 08, 2012

Copy link to clipboard

Copied

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 . . .

TOPICS
ActionScript

Views

3.4K

Translate

Translate

Report

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

Community Expert , Feb 10, 2012 Feb 10, 2012

Votes

Translate

Translate
Community Expert ,
Feb 08, 2012 Feb 08, 2012

Copy link to clipboard

Copied

is MainClass your document class?

Votes

Translate

Translate

Report

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
Community Beginner ,
Feb 09, 2012 Feb 09, 2012

Copy link to clipboard

Copied

Yessir . . . when I remove it as my document class and try to import it on the timeline using this:

//--------------------------

  import fladev.twitter.MainClass;

            var twitterReader:MainClass = new MainClass();

//--------------------------

I still get a no twitter info and I get this in my output:

//--------------------------

TypeError: Error #1085: The element type "link" must be terminated by the matching end-tag "</link>".

          at fladev.twitter::MainClass/displayInfo()[myfolder\src\MainClass.as:56]

          at flash.events::EventDispatcher/dispatchEventFunction()

          at flash.events::EventDispatcher/dispatchEvent()

          at flash.net::URLLoader/onComplete()

//--------------------------

Not sure if this helps or adds to the confusion.

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 09, 2012 Feb 09, 2012

Copy link to clipboard

Copied

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;

        }

Votes

Translate

Translate

Report

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
Community Beginner ,
Feb 09, 2012 Feb 09, 2012

Copy link to clipboard

Copied

Okay, so I made the changes you suggested and now I get a bunch of "1180: Call to a possibly undefined method gotoAndStop" errors, which completely baffles me.  My swf won't generate because of these errors so I don't know how the changes have effected my fla.

So I decided to try to put my twitterReader in a MovieClip. MainClass is no longer my document class and is now linked instead to my twitterReader MovieClip extending it to a Sprite and I now get the same error as before with this:

TypeError: Error #1085: The element type "link" must be terminated by the matching end-tag "</link>".

 

          at fladev.twitter::MainClass/displayInfo()[myfolder\src\MainClass.as:56]

          at flash.events::EventDispatcher/dispatchEventFunction()

          at flash.events::EventDispatcher/dispatchEvent()

          at flash.net::URLLoader/onComplete()

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 09, 2012 Feb 09, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Community Beginner ,
Feb 09, 2012 Feb 09, 2012

Copy link to clipboard

Copied

Yeah, I was getting that "1180: Call to a possibly undefined method gotoAndStop" error.

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 09, 2012 Feb 09, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Community Beginner ,
Feb 09, 2012 Feb 09, 2012

Copy link to clipboard

Copied

Nope, no problems at all.  I can get it to pull my twitter feeds and everything. Problems begin occurring when I try to use it in another project, whether it be on a different frame on the timeline, a different scene etc.  I can load the twitreader swf in my project with no problems as well. But because I am trying to use this in an iOS app I'm building I can't load it because ti has script to it so it has to be contained in the main as best as I can tell.

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 09, 2012 Feb 09, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Community Beginner ,
Feb 09, 2012 Feb 09, 2012

Copy link to clipboard

Copied

Alright, so I re-downloaded the sample files, I changed this part MainClass code:

private function displayInfo(e:Event):void

        {

            var _root:MovieClip = MovieClip(this.root);

            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;

        }

I removed MainClass as the document class. and added this:

var mc:MainClass=new MainClass();

addChild(mc);

on the main timeline.

When I test this is what pops up in my Compiler Errors:

Scene 1, Layer 'Actions', Frame 1, Line 11180: Call to a possibly undefined method MainClass.
Scene 1, Layer 'Actions', Frame 1, Line 11046: Type was not found or was not a compile-time constant: MainClass.

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 09, 2012 Feb 09, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Community Beginner ,
Feb 10, 2012 Feb 10, 2012

Copy link to clipboard

Copied

I put MainClass in the same folder as the fla (it was in a subfolder in the same directory) and I still get the 1180 and 1046 errors.  Just to confirm, I have this in the first frame of the timeline:

var mc:MainClass=new MainClass();

addChild(mc);

and here is what I have for MainClass:

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;

 

       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-twitter-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;

                    }

          }

 

}

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2012 Feb 10, 2012

Copy link to clipboard

Copied

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;

                    }

          }

 

}

Votes

Translate

Translate

Report

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
Community Beginner ,
Feb 10, 2012 Feb 10, 2012

Copy link to clipboard

Copied

Done, but I am still getting the 1046 and 1180 errors.

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2012 Feb 10, 2012

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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
Community Beginner ,
Feb 10, 2012 Feb 10, 2012

Copy link to clipboard

Copied

HOLY FREAKIN' AWESOME!  Yes!  It now works in my other fla as well!  Thank You! Thank You! Thank You!  So, kglad, what was it that I was doing wrong?  I can't help but to be a little perplexed at the turn of events.

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2012 Feb 10, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Community Beginner ,
Feb 10, 2012 Feb 10, 2012

Copy link to clipboard

Copied

LATEST

Thanks again for all your help!

Votes

Translate

Translate

Report

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