# Removing an mc only if a condition is met

**URL:** <https://forum.kirupa.com/t/removing-an-mc-only-if-a-condition-is-met/328751>\
**Category:** flash\
**Created:** [June 13, 2012, 3:43pm UTC](https://forum.kirupa.com/t/removing-an-mc-only-if-a-condition-is-met/328751 "2012-06-13T15:43:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wolher](https://avatars.discourse-cdn.com/v4/letter/w/8491ac/32.png) [@wolher](https://forum.kirupa.com/u/wolher)\
**Post date:** [June 13, 2012, 3:43pm UTC](https://forum.kirupa.com/t/removing-an-mc-only-if-a-condition-is-met/328751/1 "2012-06-13T15:43:04Z")

</div>

Hi There,  
this is my first post here at Kirupa. I’m trying to remove an mc only if a condition is met, the problem is that it dissapears because I’m not leaving AS enough time to adding it to the stage and removing it. Below is a copy of my code.

import flash.display.Loader;  
import flash.net.URLRequest;

var myObject:Object = new Object();  
var myArray:Array = [“redBall”,“blueBall”,“greenBall”];  
var myChildren:Array = new Array();  
var myLoader:Loader;  
var myURLRequest:URLRequest;  
var \_click:uint;  
var posX:Number = 6;  
var flag:Boolean;

// declare my object  
myObject = {idx:Number,loc:String,mc:Sprite};

stage.addEventListener(Event.ENTER\_FRAME, \_counter);  
// when click is 3 ;  
function \_counter(e:Event)//e:Event  
{  
if(\_click \> 1) stage.removeEventListener(Event.ENTER\_FRAME, \_counter);  
picksSWF(\_click);  
}

function picksSWF(f:Number)  
{  
//loaders and requests constructors  
myLoader = new Loader();  
myURLRequest = new URLRequest();  
//feeding myObject loc with the movieClip name  
myObject.loc = myArray[f];  
//feeding the url with the loc  
myURLRequest.url = myObject.loc + “.swf”;  
//running the loader  
myLoader.load(myURLRequest);  
// feeding myObject.mc with the Loader which is a movieClip  
myObject.mc = myLoader;  
myChildren[f] = myObject.mc;  
// adding myObject.mc to stage  
addChild(myChildren[f]);  
trace(“it just added the mc”);  
// feeding the idx with the variable  
myObject.idx = f;  
// feeding the loaded movies array  
myChildren[f] = myObject.mc;  
trace("myChildren[f] = "+myChildren.join())  
// putting elements on stage  
myLoader.x = posX;  
trace("posX = “+posX+” myLoader.x = "+myLoader.x)  
trace(\_click)  
// \_click continues  
// adds value to position  
if (flag)  
{  
trace(“flag”);  
removeChild(myChildren[f-1]);  
[//stage.removeEventListener](https://stage.removeEventListener)(Event.ENTER\_FRAME, \_counter);  
}

```
posX += 30;
_click++;
trace(_click);
flag = true;

```

}

Thanks a lot.
