CaptianKirk
21 posts
|
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;
}
}
}
|
|
|
DrYoshiyahu
678 posts
|
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.
|
|
|
BluePriest
470 posts
|
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?
|
|
|
CaptianKirk
21 posts
|
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
|
|
|
BluePriest
470 posts
|
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?
|
|
|
CaptianKirk
21 posts
|
It was in the last frame, but I removed it when it wasn’t working. Would it have worked?
|
|
|
BluePriest
470 posts
|
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.
|
|
|
CaptianKirk
21 posts
|
I tried adding the removeMovieClip(). It still doesn’t work, At the end it just sticks to the player and repeats again into infinity.
|
|
|
BigJM
468 posts
|
Is the Egg added at runtime or in the IDE?
|
|
|
Lime_
358 posts
|
|
|
|
BigJM
468 posts
|
|
|
|
CaptianKirk
21 posts
|
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?
|
|
|
RTL_Shadow
1020 posts
|
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);
|
|
|
BluePriest
470 posts
|
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.
|
|
|
BraydenBlack
271 posts
|
There’s no ‘parent’ in as2 but there is ‘_parent’.
|
|
|
stage_phrite
42 posts
|
add
this.swapDepths(_parent.getNextHighestDepth());
inside the if statement before you call the removeMovieClip function.
|
|
|
Aesica
951 posts
|
^ 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
{
}
|
|
|
BigJM
468 posts
|
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.
|
|
|
Aesica
951 posts
|
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:
|
|
|
stage_phrite
42 posts
|
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
|