Skip navigation
helpAnoobOut
Currently Being Moderated

remove event listener help.

Aug 10, 2011 10:31 AM

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();

 

 
Replies
  • kglad
    63,126 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 10, 2011 10:43 AM   in reply to helpAnoobOut

    removing your complete listener will stop the updates from appearing but won't stop them from downloading.  it's your loader.load() that you want to stop from executing and that code appears to be in some other location.

     
    |
    Mark as:
  • kglad
    63,126 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 10, 2011 10:53 AM   in reply to helpAnoobOut

    stop executing your load() method.  from looking at your coding style my guess is that load() method is attached to some movieclip frame that executes repetitively (but i can't be sure).  stop that timeline from playing.

     
    |
    Mark as:
  • kglad
    63,126 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 10, 2011 12:29 PM   in reply to helpAnoobOut

    when you want to remove your listener use:

     

     

    loader.removeEventListener(Event.COMPLETE, loadComplete);

     
    |
    Mark as:
  • kglad
    63,126 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 10, 2011 4:41 PM   in reply to helpAnoobOut

     

     

    but i only want to remove the event when oneof the other buttons is pressed, so would i put it into the button function?

    exactly.

     
    |
    Mark as:
  • kglad
    63,126 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 10, 2011 5:23 PM   in reply to helpAnoobOut

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

    }

     
    |
    Mark as:
  • kglad
    63,126 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 11, 2011 7:05 AM   in reply to helpAnoobOut

    there's no magic refresh code unless you want to reload your main app.  that will refresh your app just like using your browser's reload button.

     
    |
    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