# Problem removing eventListener/function?

**URL:** <https://forum.kirupa.com/t/problem-removing-eventlistener-function/301440>\
**Category:** Uncategorized\
**Created:** [December 9, 2009, 10:53am UTC](https://forum.kirupa.com/t/problem-removing-eventlistener-function/301440 "2009-12-09T10:53:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tim\_bwfc](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tim\_bwfc](https://forum.kirupa.com/u/tim_bwfc)\
**Post date:** [December 9, 2009, 10:53am UTC](https://forum.kirupa.com/t/problem-removing-eventlistener-function/301440/1 "2009-12-09T10:53:15Z")

</div>

Hi there i have a problem with trying to remove animated clouds i have created when i enter a new ‘scene’ or frame.

Here is an example of what im trying to say:

import fl.transitions.Tween;  
import fl.transitions.easing.\*;  
import fl.transitions.TweenEvent;

var xspeed:Number = (Math.random() \* 0.9);  
var cloud\_array:Array = new Array();

//Clouds Moving Left  
for (var i:Number = 0; i \< 5; i++) {  
setCloud();  
}  
//draw cloud. set in random position  
var cloud\_mc:MovieClip;  
function setCloud():void {  
var cloud\_mc:MovieClip = new MovieClip();  
cloud\_mc.graphics.lineStyle(1, 0xD6D2D2, 1);  
cloud\_mc.alpha = 0.7;  
cloud\_mc.graphics.beginFill( 0xD6D2D2, 10 );  
cloud\_mc.graphics.moveTo(0,70);  
cloud\_mc.graphics.curveTo(20,50, 40,60);  
cloud\_mc.graphics.curveTo(70,30, 90,60);  
cloud\_mc.graphics.curveTo(130,50,140,70);  
cloud\_mc.graphics.curveTo(130,110,90,100);  
cloud\_mc.graphics.curveTo(60,110,40,100);  
cloud\_mc.graphics.curveTo(10,110,0,70);  
cloud\_mc.graphics.beginFill( 0x990000, 10 );

```
cloud_mc.x = stage.stageWidth*Math.random();
cloud_mc.y = 0.2*stage.stageHeight*Math.random();
//cloud_mc.rotation = Math.random() *360;
addChild(cloud_mc);
cloud_array.push(cloud_mc);

```

}

stage.addEventListener(Event.ENTER\_FRAME, doCloud);

function doCloud(event:Event):void {  
for (i = 0; i \< 5; i++) {  
var cloud\_mc = cloud\_array\*;

```
	if (cloud_mc.alpha &lt; 0) {
		setCloud();
	}
	cloud_mc.x -= xspeed*Math.random();
}

```

}

I am able to use removeChild(…) for other movie clips that i have created that do not use eventListeners eg:

var circle:Sprite = new Sprite();  
circle.graphics.beginFill(0xFFFFFF);  
circle.graphics.drawCircle(0,0,40);  
circle.graphics.endFill();  
addChild(circle);  
var myTween:Tween = new Tween(circle, “x”,Strong.easeOut,10,400,20,true);

var myTween2:Tween = new Tween(circle, “y”,Strong.easeOut,200,100,20,true);

Basically i want to get rid of those clouds when i enter a new scene! Be great if anyone could help!

Many Thanks

Tim
