0
\$\begingroup\$

I am not new to AS3 and Flash but new to Flash timeline animations and controlling them with AS3. Had posted a similar question last week but the solution did not work. Hope someone could help me out here.

I am trying to control two different animations separately for one of my horse gameobjects inside the timeline through AS3.

For now, I have inserted really basic keyframes that hold all my animation frames. I have labelled them appropriately. Please look at the image below. These are not full animations, for now I am just playing around and testing it out.

enter image description here

I have named all the frames labels like "startwalk" "endwalk" "startTurnBack" and so on..

Now I want to control these animations and play them individually using AS3. I have added an enter_frame listener and started with a basic code as below but it does not seem to be working.

// this is the Event.ENTER_FRAME named gameLoop
private function gameLoop(event : Event) : void {
            trace(" current label " +horseTwo.currentLabel);
            var currLabel:String = horseTwo.currentLabel;
            var next:String;
            next = currLabel;
            horseTwo.gotoAndPlay(next);
            if(currLabel == "endwalk"){
                horseTwo.stop();
            }
        }

Nothing gets played. But if I do horseTwo.play(), it plays the animation throughout which is not what I want. I want to be able to control the keyframes via labels separately each for Walk, TurnBack and few more animations. Anyone got any ideas?

\$\endgroup\$
2
\$\begingroup\$

Put the horse animation on play and remove the horseTwo.gotoAndPlay(next); line from the event listener.

The problem is the horseTwo.gotoAndPlay(next); line. With that you are always returning to the beginning of the current label, end the animation never goes forward. The animation plays automatically when it is on play. So you dont need the var next:String; and next = currLabel; lines either. The event listener will stop it on label "endwalk".

In my test the code works with these changes.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.