Deleting a movie clip

Okay so first off a little background on what I’m trying to do:

Only been working with flash/as3 for about 2 months now so I’m still a little green but in a nutshell, I make interactive Flash presentations, aimed at educators as a tool to make their teaching seem a bit more interactive with their pupils, and we are in the process of developing a tool that will allow our users to create their own flash presentations similar to the ones that we provide for them.

One of the features I have is the ability to delete something off the screen which they may have added accidentally or no longer want on the screen. This is done by simulating something similar to the recycle bin.

They can click and drag items onto the recycle bin and it removes them from the stage, however as you might know, the movie clip for that item is still in memory, so when the presentation is exported (it exports as an xml file) the “deleted” movie clip is still there.

When exporting the presentation, the xml elements are generated by looking at the children of the container movie clip for different types of movie clips
(static images, images with rollover effect, animations).

I know the problem with that, and according to another post I must set the movie clip to null in order to get around this. But here’s my problem:

I have a click listener on the stage objects - which enables the drag and drop, when dropped, the listener calls a function to check if the movie clip has been dropped in the bin, and passes the mouse event onto the function.

function checkHitArea(evt:Event)
{
if(evt.currentTarget.hitTestObject(delete_area))
{
	evt.target.parent.removeChild(evt.target)
}

So yes, it removes the child from the display list, however, I cannot set to null, as evt.currentTarget is read-only. Is there a way that I can access the original movie clip that is completely obvious that I am missing? Or should I be going about this in a completely different way?

The movie clips are created by the program when the user adds in a image/animation/external file and so it doesn’t have an instance name, i.e.

User browses to a file (using FileReference)
It creates a new movie clip, adds the selected file to as it’s child, applies the mouse event listeners and then adds the movie clip it’s appropriate container. So it hasn’t got an instance name to access it with.

Example



        imageLoader.load(imageRequest);
	var mc:ImageCreator = new ImageCreator( 0, 0,"assets/images/"+fileRef2.name);	
	imageHolder.addChild(mc);
	mc.addEventListener(MouseEvent.MOUSE_DOWN, dragImage);
	mc.addEventListener(MouseEvent.MOUSE_UP, stopDragImage);

This is all very complicated after I read over the post so let me know if I’m chattering complete nonsense or suggest a simpler method of deleting from memory if you know of one.

Thanks for any help

Patrick