# How To Remove Listener

**URL:** <https://forum.kirupa.com/t/how-to-remove-listener/272901>\
**Category:** flash\
**Created:** [October 9, 2008, 7:44am UTC](https://forum.kirupa.com/t/how-to-remove-listener/272901 "2008-10-09T07:44:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stii](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@stii](https://forum.kirupa.com/u/stii)\
**Post date:** [October 9, 2008, 7:44am UTC](https://forum.kirupa.com/t/how-to-remove-listener/272901/1 "2008-10-09T07:44:10Z")

</div>

hi everyone,

I have no idea how to remove a listener.  
The script below is an instance where i have 2 buttons on stage.

When i click btn1, it will load an image, while it is loading,  
if i click btn2, i want it to remove the listener and delete the URL request.

but what i currently have can’t achieve that.  
I know ther’s something wrong at my else statement, but no idea how to phrase it.

can anyone help??

basically i want the image to stop loading when i click btn2.  
THanks in advance guys

* * *

* * *

* * *

import flash.events.MouseEvent;

btn1.addEventListener(MouseEvent.CLICK,thumbClick1);  
btn2.addEventListener(MouseEvent.CLICK,thumbClick2);

function thumbClick1(evt:MouseEvent):void {  
loadImage(0);  
}

function thumbClick2(evt:MouseEvent):void {  
loadImage(1);  
}

function loadImage(something:Number) {  
if (something == 0) {  
var objLoader:Loader = new Loader();  
var objFileToLoad:URLRequest = new URLRequest(“[http://people.mozilla.com/~faaborg/files/20061210-newCar/newCar.jpg\_large.jpg](http://people.mozilla.com/~faaborg/files/20061210-newCar/newCar.jpg_large.jpg)”);  
objLoader.load(objFileToLoad);  
objLoader.contentLoaderInfo.addEventListener(Event.INIT, imageLoaded);  
objLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);

```
	function imageLoaded($event:Event):void {
		this.addChild(objLoader);
	}
	function showProgress($event:ProgressEvent):void {
		trace(Math.round(($event.bytesLoaded / $event.bytesTotal) * 100) + " percent loaded so far...");
	}
} else {
	objLoader.contentLoaderInfo.removeEventListener(Event.INIT, imageLoaded);
	objLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, showProgress);
}

```

}

* * *

* * *
