# removeEventListener function will nicht

**URL:** https://forum.kirupa.com/t/removeeventlistener-function-will-nicht/264009
**Category:** flash
**Created:** [June 22, 2008, 12:18am UTC](https://forum.kirupa.com/t/removeeventlistener-function-will-nicht/264009 "2008-06-22T00:18:07Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zoimt](https://avatars.discourse-cdn.com/v4/letter/z/f08c70/32.png) [@zoimt](https://forum.kirupa.com/u/zoimt)
#### Post date: [June 22, 2008, 12:18am UTC](https://forum.kirupa.com/t/removeeventlistener-function-will-nicht/264009/1 "2008-06-22T00:18:07Z")

</div>

Good morning!  
I am at daggers drawn with the following.

```php

function onMouseclick(e:MouseEvent):void {
	if(e.target == buttonHome) {
		var noEventListener:Array = new Array("buttonFolioDraft", "buttonFolioPhot", "buttonFolio2",
		disattachEventListener(buttonArray, noEventListener);
	}
}

```

and:

```php
function disattachEventListener(array:Array, filter:Array):void {
/** Remove EventListener from all elements of an Array that names are matching one
of the filter Strings **/
	var disattach:Array = new Array();
	for(var i:uint = 0; i < array.length; i++) {
		
		for(var j:uint = 0; j < filter.length; j++) {
			
			if(array*.name.substring(0, filter[j].length) == filter[j]) {
				trace("yuppy!");
				disattach.push(array*);
			}
		}
	}
	
	for(var i:uint = 0; i < disattach.length; i++) {
			
			disattach*.removeEventListener(MouseEvent.ROLL_OVER, setActiveWindow(), false);
			disattach*.removeEventListener(MouseEvent.ROLL_OUT, setActiveWindow());
			disattach*.removeEventListener(MouseEvent.CLICK, setActiveWindow());
			disattach*.buttonMode = false;
	}
}

function setActiveWindow():void {
// just empty atm
	trace("here: ActiveWindow");
}

```

The output gives me the following:

TypeError: Error #2007: Parameter listener must be non-null.  
at flash.events::EventDispatcher/removeEventListener()  
at 09\_fla::MainTimeline/disattachEventListener()  
at 09\_fla::MainTimeline/onMouseclick()

Since I am completely sure I added to each of those MCs each three EventListener, I checked out EventDispatcher in the API lang. ref. for removeEventlistener but no matter beeing unsure I understood what the third parameter now really achieves, I tried both states with the same result.  
Best regards,  
zoimt

---

<div class="post-metadata">

### Author: ![DiamondDog](https://avatars.discourse-cdn.com/v4/letter/d/74df32/32.png) [@DiamondDog](https://forum.kirupa.com/u/DiamondDog)
#### Post date: [June 22, 2008, 7:33am UTC](https://forum.kirupa.com/t/removeeventlistener-function-will-nicht/264009/2 "2008-06-22T07:33:23Z")

</div>

There’s a bracket missing from the way you’ve declared your noEventListener array. (I’m assuming that’s just the way you’ve cut and paste your code.)

I’m also assuming those ‘yuppy’ traces are appearing no problem.

What happens if you use ‘setActiveWindow’ instead of ‘setActiveWindow()’ ?

ie

```auto
[COLOR=#000000][COLOR=#007700]for(var [/COLOR][COLOR=#0000bb]i[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]uint [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]0[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#0000bb]i [/COLOR][COLOR=#007700]< [/COLOR][COLOR=#0000bb]disattach[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]length[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#0000bb]i[/COLOR][COLOR=#007700]++) { 
             
            [/COLOR][COLOR=#0000bb]disattach[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]i[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]removeEventListener[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]MouseEvent[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]ROLL_OVER[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]setActiveWindow[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]false[/COLOR][COLOR=#007700]); 
            [/COLOR][COLOR=#0000bb]disattach[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]i[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]removeEventListener[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]MouseEvent[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]ROLL_OUT[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]setActiveWindow[/COLOR][COLOR=#007700]); 
            [/COLOR][COLOR=#0000bb]disattach[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]i[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]removeEventListener[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]MouseEvent[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]CLICK[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]setActiveWindow[/COLOR][COLOR=#007700]); 
            [/COLOR][COLOR=#0000bb]disattach[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]i[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]buttonMode [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]false[/COLOR][COLOR=#007700]; 
    } [/COLOR][/COLOR]

```

instead of

```auto
[COLOR=#000000][COLOR=#007700]for(var [/COLOR][COLOR=#0000bb]i[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]uint [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]0[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#0000bb]i [/COLOR][COLOR=#007700]< [/COLOR][COLOR=#0000bb]disattach[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]length[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#0000bb]i[/COLOR][COLOR=#007700]++) { 
             
            [/COLOR][COLOR=#0000bb]disattach[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]i[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]removeEventListener[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]MouseEvent[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]ROLL_OVER[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]setActiveWindow[/COLOR][COLOR=#007700](), [/COLOR][COLOR=#0000bb]false[/COLOR][COLOR=#007700]); 
            [/COLOR][COLOR=#0000bb]disattach[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]i[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]removeEventListener[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]MouseEvent[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]ROLL_OUT[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]setActiveWindow[/COLOR][COLOR=#007700]()); 
            [/COLOR][COLOR=#0000bb]disattach[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]i[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]removeEventListener[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]MouseEvent[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]CLICK[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]setActiveWindow[/COLOR][COLOR=#007700]()); 
            [/COLOR][COLOR=#0000bb]disattach[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]i[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#0000bb]buttonMode [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]false[/COLOR][COLOR=#007700]; 
    } [/COLOR][/COLOR]

```

---

<div class="post-metadata">

### Author: ![Alex\_Lexcuk](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@Alex\_Lexcuk](https://forum.kirupa.com/u/Alex_Lexcuk)
#### Post date: [June 22, 2008, 8:46am UTC](https://forum.kirupa.com/t/removeeventlistener-function-will-nicht/264009/3 "2008-06-22T08:46:14Z")

</div>

if want avoid error "must be non-null "  
code tester

```auto

if (disattach* != null) disattach*.removeEventListener(MouseEvent.ROLL_OVER, setActiveWindow, false);

```

---

<div class="post-metadata">

### Author: ![zoimt](https://avatars.discourse-cdn.com/v4/letter/z/f08c70/32.png) [@zoimt](https://forum.kirupa.com/u/zoimt)
#### Post date: [June 22, 2008, 4:54pm UTC](https://forum.kirupa.com/t/removeeventlistener-function-will-nicht/264009/4 "2008-06-22T16:54:45Z")

</div>

Thanks for replying.  
@ DiamondDog: Yes it was a copy paste error, my bad. The source actually goes like:

```php
var noEL:Array = new Array("buttonFolioDraft", "buttonFolioPhot", "buttonFolio2",
							"buttonFolio3");

```

Anyway, the other hints didnt help, either, just added the if (disattach\* != null) line to the code and tried to call the function witout () but I still get following error when executing:  
TypeError: Error #2007: Parameter listener must be non-null.  
at flash.events::EventDispatcher/removeEventListener()  
at 09\_fla::MainTimeline/disattachEventListener()  
at 09\_fla::MainTimeline/onMouseclick()

So what i came up with was that this is not working because one of the Strings nested in the filter array might be longer than the actual name of one of the elements inside the other array (array:Array… hm in this case it is a confusing variable name^^) but it still gives me that sh\*\*.  
Maybe I have to go for a different approach.
