# I can't remove a mouseListener

**URL:** <https://forum.kirupa.com/t/i-cant-remove-a-mouselistener/216804>\
**Category:** flash\
**Created:** [February 20, 2007, 7:01pm UTC](https://forum.kirupa.com/t/i-cant-remove-a-mouselistener/216804 "2007-02-20T19:01:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![4Lb3Rt0](https://avatars.discourse-cdn.com/v4/letter/4/71e660/32.png) [@4Lb3Rt0](https://forum.kirupa.com/u/4Lb3Rt0)\
**Post date:** [February 20, 2007, 7:01pm UTC](https://forum.kirupa.com/t/i-cant-remove-a-mouselistener/216804/1 "2007-02-20T19:01:27Z")

</div>

I have a proble with a “simple” mouseListener.

I’ve create a class. I’ve attached the class to a movieClip. The movieClip is used in a swf file I called “0\_gioco.swf”.  
“0\_gioco.swf” is loaded into “main.swf”.  
In main.swf I have a botton to exit (remove) from “0\_gioco.swf” and then I can reload it.

The problem is that when I reload “0\_gioco.swf” it doesn’t work because the mouseListener that is called in the class has not be removed.

Any idea?

Thanks.

Alberto.

The code:

[SIZE=3] **abbinaSpot.as** [/SIZE]  
[…]  
public function abbinaSpot() {  
Mouse.removeListener(this.\_parent.mouseListener);  
Mouse.removeListener(this.\_parent.pointer.mouseListener);  
delete mouseListener;

```
    mouseListener = new Object;
    mouseListener._parent = this;
    
    mouseListener.onMouseMove = function () {
        this._parent._x=this._parent._parent._xmouse;
        this._parent._y=this._parent._parent._ymouse;
    };
    mouseListener.onMouseDown = function () {
        trace("mouse giu"+this);
        this._parent.controlla();
    };        

    Mouse.addListener(mouseListener);

```

}

public function controlla() {

```
    this._parent.outSpot="controllato";
    this.cliccato="nulla";
    trace("e' uguale a nulla? "+this.cliccato)

```

[…]

[SIZE=3]\*\*main.fla

\*\*[SIZE=2]function mappa(){  
chiudi.\_visible=false;  
this.inMappa=true;  
suonoBase();  
carico(“mappa”);  
[/SIZE][/SIZE]}  
[SIZE=3][/SIZE]function caricaGioco(){  
[…]  
carico(gioco+"/"+gioco+"\_gioco")  
}

function carico (chi:String) {  
dove.removeMovieClip();  
\_root.createEmptyMovieClip(“dove”, doveDepth);  
my\_mcl = new MovieClipLoader();  
theListener = new Object();  
my\_mcl.addListener( theListener );  
my\_mcl.loadClip(chi+".swf", dove);  
[…]
