A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Movie Clip Not Playing?

  1. #1
    Junior Member
    Join Date
    Jan 2009
    Posts
    13

    Movie Clip Not Playing?

    I'm still a flash noob (I've only been working with it for a few months) but I'm trying to put a game together and I'm still at the very beginning stages. Right now I'm still working on having my character move around the map corresponding to the keyboard arrows being pressed. The way I have it set up is the character on the main timeline is mc "Guy". Inside mc sprite are mc's guyup at frame 1, guyright at frame 2, guydown at frame 3, and guyleft at frame 4. Inside guyup, for instance, is a graphic of the character facing up at frame 1, frame 2-3 contain an instance of the character taking a step up with his right foot and frames 4-5 contain him taking a step forward with his left foot. The same concept for right, down, and left.

    The script on the main timeline is;
    PHP Code:
    stop();
    var 
    up:Boolean false;
    var 
    right:Boolean false;
    var 
    down:Boolean false;
    var 
    left:Boolean false;
    var 
    mainSpeed:Number 3;

    stage.addEventListener(KeyboardEvent.KEY_DOWNcheckKeysDown);
    function 
    checkKeysDown(event:KeyboardEvent):void {
        if (
    event.keyCode == Keyboard.UP) {
            
    up true;
        }
        if (
    event.keyCode == Keyboard.RIGHT) {
            
    right true;
        }
        if (
    event.keyCode == Keyboard.DOWN) {
            
    down true;
        }
        if (
    event.keyCode == Keyboard.LEFT) {
            
    left true;
        }
    }

    stage.addEventListener(KeyboardEvent.KEY_UPcheckKeysUp);
    function 
    checkKeysUp(event:KeyboardEvent):void {
        if (
    event.keyCode == Keyboard.UP) {
            
    up false;
        }
        if (
    event.keyCode == Keyboard.RIGHT) {
            
    right false;
        }
        if (
    event.keyCode == Keyboard.DOWN) {
            
    down false;
        }
        if (
    event.keyCode == Keyboard.LEFT) {
            
    left false;
        }
    }

    stage.addEventListener(Event.ENTER_FRAMEwalk);
    function 
    walk(event:Event):void {
        if (
    up == true) {
            
    Guy.y-= mainSpeed;
            
    Guy.gotoAndStop(1);
            
    Guy.GuyUp.gotoAndStop(2);
        }
        if (
    up == false) {
            
    Guy.GuyUp.gotoAndStop(1);
        }
        if (
    right == true) {
            
    Guy.x+= mainSpeed;
            
    Guy.gotoAndStop(2);
            
    Guy.GuyRight.gotoAndPlay(2);
        }
        if (
    right == false) {
            
    Guy.GuyRight.gotoAndStop(1);
        }
        if (
    down == true) {
            
    Guy.y+= mainSpeed;
            
    Guy.gotoAndStop(3);
            
    Guy.GuyDown.gotoAndPlay(2);
            
    Guy.GuyUp.gotoAndPlay(1);
        }
        if (
    down == false) {
            
    Guy.GuyDown.gotoAndStop(1);
        }
        if (
    left == true) {
            
    Guy.x-= mainSpeed;
            
    Guy.gotoAndStop(4);
            
    Guy.GuyLeft.gotoAndPlay(2);
        }
        if (
    left == false) {
            
    Guy.GuyLeft.gotoAndStop(1);
        }

    The only other code is inside the movieclips guyup, etc. On the last frame it says gotoAndPlay("2"); so as to continue the continuation of the walking.
    My problem is that when I press an arrow key, the guy will move in the corresponding direction, but the movie clip wont play. Instead of going rightstep leftstep rightstep leftstep etc, he goes rightstep and stays like that while still sliding across the screen.

    I've tried for a very long time to figure this one out on my own but I just cant. :/ If any of you have any ideas that'd be awesome. Thanks in advance!

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    You're telling your guy to go to the beginning of a given walk cycle every frame - try something like this:

    PHP Code:
    if (up){ 
        
    Guy.-= mainSpeed;
        if(
    Guy.currentFrame != 1Guy.gotoAndStop(1);
        if(
    Guy.GuyUp.currentFrame == 1Guy.GuyUp.gotoAndPlay(2);
    } else {
        
    Guy.GuyUp.gotoAndStop(1); 


  3. #3
    Junior Member
    Join Date
    Jan 2009
    Posts
    13
    Hmmmm. This is weird. Now when I hit the up key the guy jumps in between either frames 2 and 1(rightstep, facingup) or frames 4 and 1 (leftstep, facingup).

    So SOMETHING different is happening because before it never got anywhere near frame 4. hm.


    Edit: I just noticed that sometimes when I let go of the arrow key, the character goes rightstep leftstep rightstep faceup. That's the only time I've seen him go back and forth between the two steps.

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