0

I'm creating flash game and I have animations for character movements. How correctly setup animations to play It only 1 time after action? For example: If I click "Space" button - character jumping and "Jumping" animation starts playing forever, if character stay on the ground jumping animation continue playing. How to stop It when character stay on the ground? Or if I use attack animation It loop forever too. In normal state character should use Hero.gotoAndStop("staying");

Here is my jumping code:

    if (Hero.y_speed > 0 && Hero.hitTestObject(ground))
    {
        Hero.y_speed = 0;
        Hero.x_speed = 0;
        if (space)
        {
            if (true)
            {
                Hero.gotoAndStop("jumping");//here starts jumping animation loop non stop
                stop(); //this not working
                Hero.y_speed = -20;
            }
            else
            {

            }
        }
    }
  • What is on the frame labeled "jumping" ? Is there a MovieClip of a jumping animation ? – prototypical Sep 19 '13 at 22:54
  • Yes, It's MovieClip of jumping animation (with ~40 frames) –  Sep 19 '13 at 22:58
  • and a `stop()` on the last frame of your animation. Your current `stop()` after `Hero.gotoAndStop("jumping");` is referring to whatever `this` would be. – Ronnie Sep 19 '13 at 23:03

2 Answers2

2

You need to put a stop(); on the last frame of the MovieClip, so that the MovieClip stops playing once the playhead reaches there.

Simon Trewhella
  • 2,124
  • 3
  • 23
  • 23
  • Thank you for answer, Is It possible to make that after jumping animation continue "staying" animation? For now It just stops on the last frame on the jumping animation. –  Sep 19 '13 at 23:14
  • Thank you for this. This answer helped me with a huge headache. – Michael Arnold Jan 20 '16 at 15:22
0

Given that there is an MovieClip on the frame, you need to tell that MovieClip containing the jump animation to stop.

You would need to have a stop on the last frame of that animation. You'd put that stop on that animation's timeline.

edited to answer comment :

You could probably use a line like this to switch to the "staying" animation when complete.

parent.gotoAndStop("staying");

In this case you wouldn't need to have a stop as the playhead would be moving off of that animation in going to the staying animation.

I think this particular post : flash event listener for movieclip end?

gives a particularly good example of extending a MovieClip giving it a much welcomed ANIMATION_COMPLETE event. So if you are looking to handle things via code exclusively, that would be a good direction to choose.

Community
  • 1
  • 1
prototypical
  • 6,731
  • 3
  • 24
  • 34
  • Thank you for answer, Is It possible to make that after jumping animation continue "staying" animation? For now It just stops on the last frame on the jumping animation. –  Sep 19 '13 at 23:15
  • Thank you, this worked for me. But now I have problem, I have 3 different attack animations and when I use 1, if for example I try to use second attack first animation cancels and start playing second. I need to make that while playing animation impossible to cancel till It end.Possible to make It? –  Sep 20 '13 at 10:05
  • You need to ask another question, this one has been answered. Doing development step by step in the comments is not useful to the community. – prototypical Sep 20 '13 at 16:54