Skip to main content
New Participant
April 17, 2019
Question

How to play looping animation in ActionScript through certain range of frames?

  • April 17, 2019
  • 2 replies
  • 1343 views

I have to do a project for college where a character is placed in the scene and has a walking animation for left and right as well as some others. All of the animations are contained within the character symbol. I'm trying to get it so that when the character is moving it plays from the correct frame and then loops back to that frame when it reaches the end of that specific animation (e.g walkRight_Start to walkRight_End), but using goToAndPlay I can only get it to start at the correct frame and then play through all of the frames instead of stopping and going back to the start once it reaches the frame I want.

I tried fixing this by having this code in an enter frame event:

function character_enterFrameHandler(event: Event):void

{

if (characterMoving_Right == true)

{

if (character.currentFrame <= "rightWalk_End")

{

character.nextFrame();

}

else

{

character.gotoAndStop("rightWalk_Start");

}

}

}

but it won't work; the character just plays the animation once and then stops? Does anyone know how to fix this problem? Thanks

    This topic has been closed for replies.

    2 replies

    kdmemory
    Inspiring
    April 17, 2019

    Hi Saoirseg

    While ClayUUID rightfully suggests to put looping animation cycles in its own dedicated movieclip, your approach of having all animations contained in one character symbol might also make sense in some cases.

    Your attempt with enterFrame seems odd though:

    function character_enterFrameHandler(event: Event):void {

        if (characterMoving_Right == true) {

            if (character.currentFrame <= "rightWalk_End") {

                character.nextFrame();

            } else {

                character.gotoAndStop("rightWalk_Start");

            }

        }

    }

    First of all it seems too much of an overhead to have this ticking each FPS and secondly is there a frame after "rightWalk_End" to further go with nextFrame()? And thirdly: gotoAndStop("rightWalk_Start")? Stop? How can it loop when being stopped?

    Anyway, having already the variable characterMoving_Right, a Boolean I presume, why not putting in frame "rightWalk_End" the code

    if (characterMoving_Right) {

        gotoAndPlay("rightWalk_Start");

    }

    ?

    Klaus

    Brainiac
    April 17, 2019

    The fact that you're already trying to use scripting to fight Animate's default behavior should have been your first clue that you're Doing It Wrong.

    Put each looping animation cycle in its own looping clip. That's what they're for.