How to remove an event listener

I have a series of buttons. When a button is clicked a component (instructorView) is loaded into a container named passageContainer:
passageContainer.addChild(instructorView);
Each time I load a new component, I remove the old component first:
passageContainer.removeAllChildren();
The component includes an eventListener which is triggered when a key is pressed.
The first time I load a component and press a key the event is triggered once.
The second time the event is triggered twice.
The third time the event is triggered three times, and so on.
I'm almost certain that the eventListeners are not being removed although the components are removed. So the event listeners execute multiple times.
Is it possible for the eventListeners to remain after the components have been removed? If so, how can I remove them?
Thanks!

It means the components are still in the memory, they are tightly coupled, you need to do makesure that the event listeners are loosely coupled/weakreferenced.
http://www.selikoff.net/2010/09/21/flex-event-handlers-and-weak-references/
(OR) you have to remove the listeners manually, by doing this.removeEventLIstener(...... on each and every component to all the events that are registered in the component before you remove it from the memory.
Message was edited by: saisri2k2

Similar Messages

  • How to remove an event listener of Enter Frame

    basically, i doing a three level game. 1st level is dodging the stone from sky, Secondly, samsh the wolf head. However, when i enter leve1 2 game, it show me an error.
    TypeError: Error #2007: Parameter hitTestObject must be non-null.as:113  Cant access to null object or reference.as.83
    I think due to when i enter level 2, the object is not available anymore, so happen this errors,izzit? how i gonna fix this?
    package
              import flash.display.MovieClip;
              import flash.events.KeyboardEvent;
              import flash.ui.Keyboard;
              import flash.events.Event;
              import flash.events.MouseEvent;
              import flash.ui.Mouse;
              import flash.utils.Timer;
              import flash.events.TimerEvent;
              import flash.events.Event;
              public class level1 extends MovieClip
                        var vx:int;
                        var vy:int;
                        var collisionHasOccurred:Boolean;
                        var score:uint;
                        public function level1()
                                  init();
                        function init():void
                                  //Initialize variable
                                  vx=0;
                                  vy=0;
                                  collisionHasOccurred=false;
                                  stone.stop();
                                  score=0;
                                  optionPage.visible=false;
                        //Add event listeners
                        stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
                        stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
                        addEventListener(Event.ENTER_FRAME, onEnterFrame);
                        wolf2.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
                        function onKeyDown(event:KeyboardEvent):void
                                  if(event.keyCode==Keyboard.LEFT)
                                            vx=-5;
                                  else if (event.keyCode==Keyboard.RIGHT)
                                            vx=5;
                                  else if (event.keyCode==Keyboard.UP)
                                            vy=-5;
                                  else if (event.keyCode==Keyboard.DOWN)
                                            vy=5;
                        function onKeyUp(event:KeyboardEvent):void
                                  if (event.keyCode==Keyboard.LEFT || event.keyCode==Keyboard.RIGHT)
                                            vx=0;
                                  else if (event.keyCode==Keyboard.DOWN || event.keyCode==Keyboard.UP)
                                  vy=0;
                        function onEnterFrame(event:Event):void
                                  trace(player);
                                  trace(cursor);
                                  trace(aaa);
                                  trace(wolf2);
                                  trace(wolf);
                                  //Move the player
                                  player.x+=vx;  <-------------------------------------------------------------this is line 83
                                  player.y+=vy;
                                  //collision detection
                                  if (stone.hitTestObject(player))
                                  player.gotoAndStop(3);
                                  health.meter.width-=2;
                                  if (! collisionHasOccurred)
                                            score++;
                                            messageDisplay.text=String(score);
                                            collisionHasOccurred=true;
                        else
                                  player.gotoAndStop(1);
                                  collisionHasOccurred=false;
                        if (health.meter.width <=1)
                                  New.text="Game Over!";
                                  stop();
                                  fl_CountDownTimerInstance_3.stop();
                        if (player.hitTestObject(wall))   <-------------------------------------------------this is line 113
                                  player.x-=vx;
                                  player.y-=vy;
                        if (player.hitTestObject(wallA))
                                  player.x-=vx;
                                  player.y-=vy;
                        if (player.hitTestObject(wallB))
                                  player.x-=vx;
                                  player.y-=vy;
                        if (player.hitTestObject(wallC))
                                  player.x-=vx;
                                  player.y-=vy;
                        if (player.hitTestObject(wallD))
                                  player.x-=vx;
                                  player.y-=vy;
                        if (player.hitTestObject(wallE))
                                  player.x-=vx;
                                  player.y-=vy;
                        if (player.hitTestObject(wallF))
                                  player.x-=vx;
                                  player.y-=vy;
                        if (player.hitTestObject(wallG))
                                  player.x-=vx;
                                  player.y-=vy;
                        if (player.hitTestObject(wallH))
                                  player.x-=vx;
                                  player.y-=vy;
                        function fl_MouseClickHandler(event:MouseEvent):void
                        score++;
                        aaa.text=String(score);
                        trace("Mouse clicked");

    instead of:
    if (player.hitTestObject(wall))
    use:
    if(player&&wall){
    if (player.hitTestObject(wall))

  • How to add exiting event listener in javascript

    I am trying to figure out how to add an event listener in javascript for the exiting event when the red x is clicked on a Windows window (top right corner).
    I found this among adobe documentation, but it does not work:
    var app = air.NativeApplication.nativeApplication;
    app.addEventListener(air.Event.EXITING, closeHandler);
    function closeHandler(event) {
      alert("Goodbye.");
    And yes I have the AIRAliases.js included.
    Thanks

    The code posted above is from page 10 of the "HTML Developer’s Guide for ADOBE AIR (prerelease updated 11/16/2009)".
    I am actually exiting the program because I only have one window open and I click on the red x in the top right corner to shut it down... in theory, the example above provided by Adobe, should interrupt the exit sequence by displaying an alert box amd then shut the program down.
    Here's the excerpt from the manual...
    unload events (for body and frameset objects)
    Adobe AIR 1.0 and later
    In the top-level frameset or body tag of a window (including the main window of the application), do not use the unload event to respond to the window (or application) being closed. Instead, use exiting event of the NativeApplication object (to detect when an application is closing). Or use the closing event of the NativeWindow object (to detect when a window is closing). For example, the following JavaScript code displays a message ("Goodbye.") when the user closes the application:
    var app = air.NativeApplication.nativeApplication;
    app.addEventListener(air.Event.EXITING, closeHandler);
    function closeHandler(event)
    alert("Goodbye.");
    However, scripts can successfully respond to the unload event caused by navigation of a frame, iframe, or top-level window content.
    Note: These limitations may be removed in a future version of Adobe AIR.

  • [svn:bz-trunk] 23085: Fix test to explicitly remove an event listener after the test is finished .

    Revision: 23085
    Revision: 23085
    Author:   [email protected]
    Date:     2011-10-21 07:49:33 -0700 (Fri, 21 Oct 2011)
    Log Message:
    Fix test to explicitly remove an event listener after the test is finished. Not doing this was causing the test to throw an RTE.
    Modified Paths:
        blazeds/trunk/qa/apps/qa-regress/testsuites/mxunit/tests/messagingService/security/stream ing-amf/MessagingAuthProSendTest.mxml

    Thanks for the ideas regarding beforeInvoke, Ben.  I will try to check that out.  In my situation, here's essentially how my script is working...
    BeforeSave is invoked.
    Script makes a change to the document, which should be captured in the saved file.
    Document saves.
    Document appears saved for a moment, and then appears unsaved (asterisk in the document title).
    My biggest problem is that this behavior isn't consistent.  I have dozens of users, all running the same script, and the problem only occurs with certain users and at random times. I can move a problematic document from a user's machine to a different machine, and the problem doesn't occur there.  It's very difficult to troubleshoot because I can't reproduce it consistently.

  • How to remove complex event listeners

    circDraw.addEventListener(Event.ENTER_FRAME,function(e:Event){expand(e.target); },false,0,true);
    function expand(obj):void {
         obj.height+=3;
         obj.width+=3;
        How would I add a line here to remove that event?

    The more I look at that code the more I wonder about it.  First I questioned why the function was not called directly in the event listener like it normally would be (since it appears to be utilizing the event.target), then I wondered why an ENTER_FRAME event is being cancelled as soon as it seemingly starts. Is circDraw the obj of the function?  If so, why it isn't all that just reduced to being...
         circDraw.height+=3;
         circDraw.width+=3;
    with no listeners or functions involved.
    Maybe you have an explanation that I can't see from what is shown.

  • How to send the Event Listener arguments in AS3?

    In MXML
    <mx:Button click="clickHandler();"
    mouseDown="downHandler(event);" mouseOver="overHandler(btn);"
    mouseMove="moveHandler('RAJAN');"/>
    but AS3
    var btn:Button = new Button();
    btn.addEventListener(MouseEvent.CLICK, clickHandler, flase,
    0, true);
    only this kind of AS3 event only added, any other possibility
    to pass the arguments to handler function.
    please help.

    From that link:
    If you define an event listener inline (inside the MXML tag),
    you can add any number of parameters as long as the listener
    function's signature agrees with that number of parameters.
    If you add a listener with the addEventListener() method (in
    ActionScript), you cannot pass any additional parameters to the
    listener function, and that listener function can declare only a
    single argument, the Event object (or one of its subclasses).
    To pass additional parameters to listener functions defined
    in AS, you must define the parameters in the listener function and
    then call some other method passing it the additional parameters in
    the call from the listener.
    You can also define your own custom events, and then you are
    free to define what args your event listeners take, and access the
    data from the event object.

  • How to remove Action Event programatically

    Can i remove the Action Event programatically. Please provide the query for the same.

    Hi ,
    you can not remove Action Event programatically, although you can try to modify theexisting event using below code
    trashCanImageBean.setFireActionForSubmit ("delete",
    params, paramsWithBinds,false, false);
    so that the previous event may stop working , I never tried this , but an attempt can be done .
    Thanks
    Pratap

  • How to remove duplicate events in my ical icloud calendars?

    OS X 10.9.1
    I have too much duplicate events in my icloud calendars.
    How can I remove them automatically?
    Is there any App available that works?
    Thanks

    Thats a good tip Reggie.
    For anyone else reading this post, keep in mind that if you see "duplicates" with the MobileMe calendar it may mean you are seeing two separate copies of the same calendar.  Before spending time deleting individual events read this article: http://support.apple.com/kb/TS3505

  • How to Remove Spacebar event from JFormattedTextField/JTextField

    Hello Friend,
    I have problem about JTextField.I want to remove or unregister Spacebar event from JTextField.
    I have used KeyMap,InputMap,also.
    So please help me

    Hello Friends,
    That is not ficiable for me.Actuall that JTextField is already use Document listener and focus listener and HexFormatter.
    In sort i am making a JFormattedTextField as Hex JTextField which will validate only 0-9 and a-f And A-F will be valide entry and remail it will ignore.
    I have made that one .but we require output like
    45 56 89 a4 59
    Here space will generate by programmer not user,he will enter only data....so i want remove space bar
    i have used this way but that is not working
    KeyMap space=txtBox.getKeymap()
    KeyStroke stroke=KeyStroke.getKeyStroke
    (KeyEvent.VK_SPACE,0);
    space.removeKeyStrokeBinding(stroke);
    but this not working

  • How to remove upcoming events from iCal's day view

    Is there any way to remove the Upcoming Events list (on the left) from the Day view in iCal?
    They are distracting!

    Are these the components you need?
    I may have misunderstood.

  • Removing an event listener from buttons

    Hi.
    I´d like to know if it´s necessary to remove event listeners from buttons.
    I know it's good practice to remove event listeners when its use is over.
    But it´s necessary to remove event listeners for buttons as well?
    Thanks

    it's necessary if you want to ready your buttons for gc.

  • Cant remove enterframe event listener in control animation

    Hi
    I am trying to create a simple play, stop, rewind. fforward controller. I have the slideShow and the Control in the same time line.
    As the enterframe event is nested inside a function it will rewind but then none of the other buttons will work as I am not able to removeEventListener for the enterframe event. Thanks for looking. Regards
    stop();
    btnStop.addEventListener(MouseEvent.CLICK,StopSlideShow)
    btnPlay.addEventListener(MouseEvent.CLICK,PlaySlideShow)
    btnRewind.addEventListener(MouseEvent.CLICK,RewindSlideShow)
    function PlaySlideShow(e:MouseEvent):void
    play();
    function StopSlideShow(e:MouseEvent):void
    stop();
    function RewindSlideShow(e:MouseEvent):void
    addEventListener(Event.ENTER_FRAME,keeprewinding);
    function keeprewinding(e:Event):void
      prevFrame();
    if(currentFrame ==1)
    removeEventListener(Event.ENTER_FRAME,keeprewinding);

    stop();
    btnStop.addEventListener(MouseEvent.CLICK,StopSlideShow);
    btnPlay.addEventListener(MouseEvent.CLICK,PlaySlideShow);
    btnRewind.addEventListener(MouseEvent.CLICK,RewindSlideShow);
    function PlaySlideShow(e:MouseEvent):void
    removeEventListener(Event.ENTER_FRAME,keeprewinding);
    play();
    function StopSlideShow(e:MouseEvent):void
    removeEventListener(Event.ENTER_FRAME,keeprewinding);
    stop();
    function RewindSlideShow(e:MouseEvent):void
    addEventListener(Event.ENTER_FRAME,keeprewinding);
    function keeprewinding(e:Event):void
    if (currentFrame == 1)
      removeEventListener(Event.ENTER_FRAME,keeprewinding);
    prevFrame();

  • How to remove event listener when all the MoviClip are off the stage

    Hi i am newbie to as3,
        I am creating animation using as3 in which i duplicate the circle ten time,then pushing into an array and giving random motion. When all the duplicate object goes outside the stage then i should remove the event listener. But right now when one duplicate object goes off the stage the event listener is removed. Thanks in advance

    //---------code for creating random bubble movement------//
    var bubbleNo:Number = 10;
    var vx:Number = .3;
    var vy:Number = .5;
    var bubbles:Array = new Array();
    var bubbleRadius:Number = 9;
    var myColor:ColorTransform = this.transform.colorTransform;
    init();
    function init():void {
    for(var i:Number = 0; i<bubbleNo; i++){
              var bubble = new newBall();
    bubble.x = Math.random() * stage.stageWidth;
    bubble.y = Math.random() * stage.stageHeight;
    //bubble.color = Math.random
    //trace("bubble.x=="+bubble.x+"bubble.y=="+bubble.y);
    bubbles.push(bubble);
    myColor.color = Math.random() * 0xFFFFFF
    bubble.transform.colorTransform = myColor;
    addChild(bubble);
              addEventListener(Event.ENTER_FRAME,createBubble);
    //addEventListener(Event.ENTER_FRAME,createBubble);
    function createBubble(event:Event):void{
    for(var k:Number = bubbles.length-1; k>0; k--){
              var bubble = (newBall)(bubbles[k]);
              bubble.x += vx;
              bubble.y += vy;
              if(bubble.x - 18 > stage.stageWidth || bubble.x + 18 < 0  || bubble.y - 18 > stage.stageHeight || bubble.y + 18 < 0){
                        removeChild(bubble);
                        bubbles.splice(k, 1);
                        //trace("out"+bubbles.length);
                        if(bubbles.length <= 0 );
                                  removeBubble();
                                  trace(bubbles.length);
                                  //removeEventListener(Event.ENTER_FRAME,createBubble)
                        trace("all Bubbles cleared");
                        function removeBubble():void{
                                  removeEventListener(Event.ENTER_FRAME,createBubble)

  • Can't remove event listener from Image

    I'm clearly missing something and would appreciate some help.  I'm trying to run an event handler when an Image completes loading,  then remove the handler so that it won't  run again should the image be reloaded later.
    The problem that I'm having is that the event handler simply wont' go away, despite calling removeEventListener on the Image object.
    The following example demonstrates the problem (the example doesn't actually do anything useful...it's just the shortest example to demonstrate the problem).  (To run the  app, you'll have to provide any ol' JPEG file named "myImage.jpg" in the "src" directory of your project).
    What I expect to happen is :
         1) on startup, the image loads and loadComplete() runs.
         2)  loadComplete removes the event Listener so that subsequent re-loads won't re-fire the handler.  I only want the handler to  run once.
         3) "loadComplete" shoudl  be displayed in the Debug console.
         4) A button click should display only "Changing  Image" in the Debug console
    What I get instead is that the loadComplete handler isn't  removed, and every  time I click the button, loadComplete runs when the image is re-loaded   (i.e., every button click results in both "Change Image" AND "loadComplete"  being displayed in the Debug console).
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
        <mx:Image width="655" height="181" source="myImage.jpg" id="myImage" autoLoad="true" scaleContent="true" complete="loadComplete()" x="100" y="100"/>
        <mx:Button x="100" y="341" label="Button" click="click(event)"/>
        <mx:Script>
            <![CDATA[
                private function loadComplete():void
                    trace ("loadComplete");
                    myImage.removeEventListener("complete", loadComplete);
                private function click(evt:Event):void
                    trace ("Changing Image");
                    myImage.load("myImage.jpg");    //  Reload same image; it's just an example
            ]]>
        </mx:Script>
    </mx:Application>

    Hi,
    You can remove only event listeners that you added with the addEventListener() method in an ActionScript block. You cannot remove an event listener  that was defined in the MXML tag, even if it was registered using a call  to the addEventListener()method that was made inside a tag attribute.
    Check this page for reference.
    http://livedocs.adobe.com/flex/3/html/help.html?content=events_05.html
    You can modify the code a bit a get it working
    <mx:Image width="655" height="181" id="myImage" scaleContent="true"
              x="100" y="100"
              creationComplete="myImage_creationCompleteHandler(event)"/>
    private function myImage_creationCompleteHandler(event:FlexEvent):void
         myImage.addEventListener("complete",myImage_completeHandler);
         myImage.load("myImage.jpg");
    private function myImage_completeHandler(event:Event):void
         myImage.removeEventListener("complete",myImage_completeHandler);

  • How to remove a node apps listener from CRS.

    We have a node apps in type of listener offline shown from crs_stat -t:
    ldctrdb01|PDAMLDV11|/u01/crs/product/10.2.0/bin $ crs_stat -t
    Name Type Target State Host
    ora....11.inst application ONLINE ONLINE ldctrdb01
    ora....12.inst application ONLINE ONLINE ldctrdb02
    ora....LDV1.db application ONLINE ONLINE ldctrdb02
    ora....SM1.asm application ONLINE ONLINE ldctrdb01
    ora....01.lsnr application ONLINE OFFLINE
    ora....01.lsnr application ONLINE ONLINE ldctrdb01
    ora....b01.gsd application ONLINE ONLINE ldctrdb01
    ora....b01.ons application ONLINE ONLINE ldctrdb01
    ora....b01.vip application ONLINE ONLINE ldctrdb01
    ora....SM2.asm application ONLINE ONLINE ldctrdb02
    ora....02.lsnr application ONLINE OFFLINE
    ora....02.lsnr application ONLINE ONLINE ldctrdb02
    ora....b02.gsd application ONLINE ONLINE ldctrdb02
    ora....b02.ons application ONLINE ONLINE ldctrdb02
    ora....b02.vip application ONLINE ONLINE ldctrdb02
    I want to delete it from the list by using netca. But this listener would not be able to show from netca. The netca can only show the other listener that is currently used and also shown in the crs_stat. How to remove the offline listener from crs_stat list?
    Thanks for advice!

    I run the netca from both $ORACLE_HOME and $ASM_HOME earlier. But now, none of the home can detect the listener to be deleted. However, if I try to add a listener with that name, the netca replied with " the listener already exist...".
    We have a symbolic link from $ORACLE_HOME/network/admin to $ASM_HOME/network/admin ($TNS_ADMIN) for the files tnsnames.ora and listener.ora.

Maybe you are looking for