PDA

View Full Version : Making a movie clip remove itself?


hockeyb47
05-18-2008, 12:13 AM
I'm working on a project for English, and the task is to create a slideshow. I coded it in ActionScript 2.0 and everything works fine, up until it reaches about a dozen images. The program starts to lag, so I decided to just kill off a movie clip after a few images.

Here's a quick rundown:

First, we load the XML file containing the image URLs. Easy enough.
Second, we start the timer that counts down 10 seconds to each slide. This timer will trigger an imageSwap event.
Third, an imageHandler clip hears this event and responds by setting the next URL, then fires off an imageReady event.
Fourth, an imagePlayer clip hears THIS event and responds by creating a new image and animating it in. It creates a new movie clip with

var pic = createEmptyMovieClip("pic"+nextDepth,nextDepth);

then loads the image into it. Then it animates a falling photograph.

So that's where I need help. I need to get the new clip to disappear after a while. I tried something like:

clip.onEnterFrame = function() { //code to disappear after a few slides }

but to no avail. I know it's the function that's not happening, because I always put traces in my maybe-bad functions.

I was also thinking about letting imagePlayer decrement the alpha each time it made a new clip, then use removeMovieClip(theClip) when a clip's alpha reaches 0. But how would I go about doing that without O(N) complexity every time?

Thanks for any help in advance.

Conlor
05-18-2008, 12:25 AM
dude, what a coincidence, I just got help for this about 10 minutes ago for a project I'm worrking on...weird.

Anywys, here is the code you use:
this.createEmptyMovieClip("square_mc", the_mc.getDepth());
square_mc.swapDepths(10000)
square_mc.removeMovieClip();

I don't completly understand it, but the guy who gave it to be said the empty movie clip is created over the old one (in this case, your picture), then the last line of code deletes the new random object...if that helps. Here is the link to that post if I explained it crappy:
http://www.actionscript.org/forums/showthread.php3?t=171012

hockeyb47
05-18-2008, 12:48 AM
The only problem with that code would be that it would make the movie clip disappear instantly, which looks pretty bad in a visual application. Actually, I read that post and figured out what I was doing wrong. Turns out, I had to call removeMovieClip from the clip I wanted to remove. I ended up just fading it out as a new picture was animating in.

Thanks for the reply!