im making this app, and i have it connect to the twitter api, but then say the facbook button or any of them is pressd the tweets are still displayed. Im sure its simple to remove a event listener, i know it exists but i have never done it so i have no idea how to do it... Can someone show me please?
This is my code(dont worry about the top too much, its just buttons twitter is near the bottom) :
stop();
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import com.adobe.serialization.json.JSON;
import flash.text.TextFieldAutoSize;
import flash.text.TextField;
Backbtn.addEventListener(MouseEvent.CLICK, goBack1);
function goBack1(event:MouseEvent):void
{
MovieClip(this.root).gotoAndPlay(1,"Scene 1");
}
TFbtn.addEventListener(MouseEvent.CLICK, goFacebookFromTwitter);
function goFacebookFromTwitter(e:MouseEvent):void
{
MovieClip(this.root).gotoAndPlay(1,"Scene 3");
}
TGbtn.addEventListener(MouseEvent.CLICK, goGalleryFromTwitter);
function goGalleryFromTwitter(e:MouseEvent):void
{
MovieClip(this.root).gotoAndPlay(1,"Scene 4");
}
TUbtn.addEventListener(MouseEvent.CLICK, goUpdatesFromTwitter);
function goUpdatesFromTwitter(e:MouseEvent):void
{
MovieClip(this.root).gotoAndPlay(1,"Scene 5");
}
TPbtn.addEventListener(MouseEvent.CLICK, goProfileFromTwitter);
function goProfileFromTwitter(e:MouseEvent):void
{
MovieClip(this.root).gotoAndPlay(1,"Scene 6");
}
TMbtn.addEventListener(MouseEvent.CLICK, goMoreFromTwitter);
function goMoreFromTwitter(e:MouseEvent):void
{
MovieClip(this.root).gotoAndPlay(1,"Scene 7");
}
FollowMebtn.addEventListener(MouseEvent.CLICK, goFollow);
function goFollow(event:MouseEvent):void
{
MovieClip(this.root).gotoAndPlay(1,"Scene 6");
}
//twitter api //twitter api //twitter api //twitter api //twitter api //twitter api
var loader:URLLoader = new URLLoader(new URLRequest("https://api.twitter.com/1/statuses/user_timeline.json?screen_name=Scot tMitchell"));
loader.addEventListener(Event.COMPLETE, loadComplete);
function loadComplete(e:Event):void {
processData(e.target.data);
}
function processData(data:String):void {
var tweets:Array = JSON.decode(data) as Array;
for(var i:int=0;i<7;i++){
var tf:TextField=new TextField();
var positionA:Array=[ [20,90], [20,140], [20,190], [20,240], [20,290], [20,330], [20,380] ];
addChild(tf);
//tf.multiline=true;
//tf.width=100;
//positionA.wordWrap=true;
positionA.width=280;
tf.wordWrap=true;
tf.width=280;
tf.height=40;
tf.textColor= 0xFF530D;
tf.text = tweets[i].text;
tf.autoSize="left";
tf.x=positionA[i][0];
tf.y=positionA[i][1];
}
}
stop();
also, whilst your willing to share your knowledge,
how would i make a refresh button? so when the user presses the button it refreshes the tweets, it makes the user feel that the top tweet is the latest even though i know it is.
And can i add a preloder to the twitter code? because when i test the app there is like a 5 - 10 second tim where the tweets are loading that there is nothing to display..
I know i ask alot of questions on this forum, its because i dont believe too much in watching tutorials, i think they teach you how to copy, not how to programme if you understand what i mean? i am a noob but once i hear it/do it a few times then i understand it. Once this is complete i will post a link onto the forum showing what i have accomplished, i think its great i only started as3 about a month ago and i have accomplished much!
Anyways thanks for your help.
the urlloader class has a progressevent that you can use:
var loader:URLLoader = new URLLoader(new URLRequest("https://api.twitter.com/1/statuses/user_timeline.json?screen_name=Scot tMitchell"));
loader.addEventListener(Event.COMPLETE, loadComplete);
loader.addEventListener(ProgressEvent.PROGRESS,progressF):
function progressF(e:ProgressEvent):void{
// use e.bytesLoaded and e.bytesTotal to display the load-progress of your twitter feed
}
function loadComplete(e:Event):void {
processData(e.target.data);
}
North America
Europe, Middle East and Africa
Asia Pacific