# Making a generated movieclip self destruct (remove from screen) after x seconds?

**URL:** https://forum.kirupa.com/t/making-a-generated-movieclip-self-destruct-remove-from-screen-after-x-seconds/291909
**Category:** flash
**Created:** [July 7, 2009, 12:54pm UTC](https://forum.kirupa.com/t/making-a-generated-movieclip-self-destruct-remove-from-screen-after-x-seconds/291909 "2009-07-07T12:54:49Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Gemixin](https://avatars.discourse-cdn.com/v4/letter/g/ebca7d/32.png) [@Gemixin](https://forum.kirupa.com/u/Gemixin)
#### Post date: [July 7, 2009, 12:54pm UTC](https://forum.kirupa.com/t/making-a-generated-movieclip-self-destruct-remove-from-screen-after-x-seconds/291909/1 "2009-07-07T12:54:49Z")

</div>

I’m making a game where little parcels appear and if they aren’t dragged to the correct zone within 5 seconds, they disappear and the player loses points.

The problem i’m having is that i’m generating the movieclip parcel objects as follows:

function generateMCByString(id:String):MovieClip  
{  
var mcObj:Object = null;  
mcObj = getDefinitionByName(id.toString());  
return (new mcObj()) as MovieClip;  
}

Then creating the movieclip and adding it to the screen depending on certain conditions as follows:

```
    mc = generateMCByString(currentParcel); 
    mc.value = currentParcel;
    addChild(mc); 
    mc.x = 386.9; 
    mc.y = -100;

    mc.addEventListener(MouseEvent.MOUSE_DOWN, dragStarter);
    mc.addEventListener(MouseEvent.MOUSE_UP, dragStopper);
   
     tweenMove0 = new Tween(mc, "y", None.easeOut, -100, 238, 3, true);  

```

currentParcel is 1 of 3 (randomly selected) movieclip names (redParcel, yellowParcel and orangeParcel).

What I need to do is add some code to say “after a movieclip has been generated…if it is still here in 5 seconds time…”

It sounds simple but I can’t figure it out for the life of me! I’ve tried setInterval with something like:

timedProcess = setInterval(timeCheck, 5000);

but how can I pass the actual movieclip “handle” along with the function so that timeCheck knows which movieclip to delete?

Any suggestions gratefully received!

Thanks
