A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: (CS3)Animated mc with keydown

Threaded View

  1. #1
    Member
    Join Date
    Dec 2004
    Posts
    68

    (CS3)Animated mc with keydown

    Hopefully this is a small problem.

    I am working on a simple scrolling game. When the right key is pressed, the background scrolls and the character MC advances to the second frame of the man MC which contains an animation of the character walking. When the key is released, the background stops scrolling and the character returns to frame one of the man MC which he is just standing.

    Code:
    stop();
    function man_walks(e:KeyboardEvent):void {
    	if (e.keyCode==Keyboard.RIGHT) {
    		man_mc.gotoAndStop(2);
    	}
    }
    stage.addEventListener(KeyboardEvent.KEY_DOWN, man_walks);
    
    function stop_man(e:KeyboardEvent):void {
    	man_mc.gotoAndStop(1);
    }
    stage.addEventListener(KeyboardEvent.KEY_UP, stop_man);
    The problem I am having is that the walking animation does not play completely or loop. It plays for a few frames then stops.

    I think the problem is that the script (gototAndStop(2); ) repeats as long as the key is pressed, meaning it continues to return and stop on frame 2 causing the walk cycle to pause.

    Is this what is causing the walk cycle not to animate? How do I get around this?

    I’ve attached a small example showing the problem.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center