Remove animation after completion

20 posts

Flag Post

I can’t remove an animation when it’s finished. It’s all written in AS2. The object is like a missile. I’m trying to get the animation to start when the object hits the player or falls to the ground. Then remove itself after the animation completes. But, it won’t remove itself. Help!

Here’s my code:

class Egg extends MovieClip
{
	var hit:Boolean = false;

	function onLoad()
	{
		stop();
	}

	function onEnterFrame()
	{
		if (this._currentframe == this._totalframes)
		{
			this.removeMovieClip();
		}
		if (hit == false)
		{
			this._y += 10;
		}
		if (hit == true)
		{
			this._x = _root.player._x;
		}
		if (this.hitTest(_root.player))
		{
			play();
			if (hit == false)
			{
				hit = true;
				this._y + 40;
				_root.player.updateHealth(-10);
			}
		}
		if (_y > 500)
		{
			play();
			hit = true;
		}
	}
}
 
Flag Post

I hate telling anyone to code on the timeline, but what you can do is simply remove the movieclip on the movieclip’s last frame.

 
Flag Post

put a trace in to make sure its even registering that the current frame is == to the total frame


if (this._currentframe == this._totalframes)
		{
trace('current == total');
			this.removeMovieClip();
		}

Im guessing you have it stopped because this IS the explosion? and the egg explodes once it hits something?

 
Flag Post
Originally posted by DrYoshiyahu:

I hate telling anyone to code on the timeline, but what you can do is simply remove the movieclip on the movieclip’s last frame.

I tried doing just that with this code at the last frame of the movieclip.

removeMovieClip(this)
Originally posted by BluePriest:

put a trace in to make sure its even registering that the current frame is == to the total frame


if (this._currentframe == this._totalframes)
		{
trace('current == total');
			this.removeMovieClip();
		}

Im guessing you have it stopped because this IS the explosion? and the egg explodes once it hits something?

Originally posted by BluePriest:

put a trace in to make sure its even registering that the current frame is == to the total frame


if (this._currentframe == this._totalframes)
		{
trace('current == total');
			this.removeMovieClip();
		}

Im guessing you have it stopped because this IS the explosion? and the egg explodes once it hits something?

I used the trace. It returned: “current == total”

Thanks

 
Flag Post
Originally posted by CaptianKirk:
Originally posted by DrYoshiyahu:

I hate telling anyone to code on the timeline, but what you can do is simply remove the movieclip on the movieclip’s last frame.

I tried doing just that with this code at the last frame of the movieclip.

Wait the code you showed us is just in the last frame of the egg?

 
Flag Post

It was in the last frame, but I removed it when it wasn’t working. Would it have worked?

 
Flag Post

Generally its not a good idea to make anything in the frames at all. You should have everyhting controlled by classes. If you got my trace like you said you did, then your code is registering except for the removemovieclip. What DrYoshiyahu was saying is keep all your code wherever you had it (hopefully in a class) and on the last frame of your egg timeline, put in this.removeMovieClip(); and nothing else.

 
Flag Post

I tried adding the removeMovieClip(). It still doesn’t work, At the end it just sticks to the player and repeats again into infinity.

 
Flag Post

Is the Egg added at runtime or in the IDE?

 
Flag Post

 
Flag Post

?

 
Flag Post
Originally posted by BigJM:

Is the Egg added at runtime or in the IDE?

The egg is added at runtime.

Also, why would a removeMovieClip() not work?
 
Flag Post
Originally posted by CaptianKirk:
Originally posted by BigJM:

Is the Egg added at runtime or in the IDE?

The egg is added at runtime.

Also, why would a removeMovieClip() not work?


I haven’t used AS2 in like, 3 years or so, but could it be parent.removeMovieClip(this); instead? I’m not sure if AS2 has the parent property but in AS3 you would do:

parent.removeChild(this);

 
Flag Post

Theres no parent in as2. Only in 3.

Whats the code look like that adds the egg to the screen?

Edit
If the file works, but not as expected, upload it to fastswf.com so that we can take a look at it to see exactly what is happening.

 
Flag Post

There’s no ‘parent’ in as2 but there is ‘_parent’.

 
Flag Post

add

this.swapDepths(_parent.getNextHighestDepth());

inside the if statement before you call the removeMovieClip function.

 
Flag Post

^ That isn’t the problem, I don’t think. Besides, if memory serves, that function is supposed to be used like this: movieClipOne.swapDepths(movieClipTwo); …but then again, it’s AS2, so who knows, maybe a movieclip is just as valid a parameter as an integer.

Anyway, to the OP: So if I’m following this right, your missile is also the explosion (ugh) and, upon hitting the player, plays the explosion animation and is supposed to remove itself once it’s done exploding. My questions to you are:

1) Does it properly play through the explosion animation?
2) If so, does it just sit on the stage, stopped at the last frame of its animation?

this.removeMovieClip(); is being correctly used in the code you posted, and you’ve already verified that the segment of code containing it is being reached at the correct time. The only thing that remains is this: Are you coding on the timeline, in frames? You should never do this, and only code in classes. AS2 is known for doing completely illogical and unexplainable things like this, so that extra bit of complexity is the only thing I can think of that might be screwing you over.

PS: Not related to your question, but


if (hit == true)
{
}

if (hit == false)
{
}

Are better used like so:


if (hit) // true
{
}

if (!hit) // false
{
}

 
Flag Post
Originally posted by Aesica:

^ That isn’t the problem, I don’t think. Besides, if memory serves, that function is supposed to be used like this: movieClipOne.swapDepths(movieClipTwo); …but then again, it’s AS2, so who knows, maybe a movieclip is just as valid a parameter as an integer.

The function is overloaded (in Flash’s way) and can accept either a MovieClip or Number. That would be the solution if the movie clip is at a negative depth (such as those added in the IDE) because movie clips at a negative depth cannot be removed with removeMovieClip. That’s why I asked if it was added at runtime or in the IDE.

 
Flag Post

Ooh, my bad then, as I think I’ve only tried to use swapDepths once or twice—typically to make crap generated by an enemy appear behind it rather than on top of it.. D:

 
Flag Post
Originally posted by Aesica:

Ooh, my bad then, as I think I’ve only tried to use swapDepths once or twice—typically to make crap generated by an enemy appear behind it rather than on top of it.. D:

And this is why you read the documentation if you are unsure, so you don’t go looking silly :p