A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Moving back a certain number of Frames

  1. #1
    Member
    Join Date
    Jan 2004
    Location
    in a cave w/ wireless internet
    Posts
    95

    Moving back a certain number of Frames

    Hey,

    I'm trying to go back a certain number of frames (let's say 20) after I hit the "Left" keyboard key.

    PHP Code:
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard

    function 
    keyEvent e:KeyboardEvent )
    {
        switch ( 
    e.keyCode ) {
            case 
    Keyboard.LEFT :
                
    prevFrame();

            case 
    Keyboard.RIGHT :
                
    nextFrame();
        
        }
    }

    stage.addEventListener KeyboardEvent.KEY_DOWNkeyEvent ); 
    That is what i have right now, but rather than simply having it go back one frame using (prevFrame(), i want it to jump back 20 frames. So if I was at frame 40, and hit the "left" button, then i'd go back to frame 20.

    Any ideas? I'm a completely noob by the way I'm just beginning with AS3.

    Thanks so much!
    Cheers !
    BOB

  2. #2
    Senior Member
    Join Date
    Feb 2006
    Location
    Düsseldorf, Germany
    Posts
    142
    hey,

    it is quite easy:

    Actionscript Code:
    gotoAndPlay ( currentFrame + 20 );

    p.s. just add some checkings:
    Actionscript Code:
    value > 0 and value < totalFrames
    --
    there is a place for those who dare to dream...

    Flash Developer
    VISTAPARK GMBH
    BÄRENSTRASSE 11-13
    D-42117 WUPPERTAL

  3. #3
    Member
    Join Date
    Jan 2004
    Location
    in a cave w/ wireless internet
    Posts
    95
    It worked perfectly, thank you so much
    Cheers !
    BOB

  4. #4
    Member
    Join Date
    Jan 2004
    Location
    in a cave w/ wireless internet
    Posts
    95

    Follow-up

    Hey,

    I just had a quick follow-up. Let's say I only want the timeline to jump back 9 frames when I hit "Left" all the time EXCEPT when i'm at a frame-label called "entry-slide" and another frame-label called "rivalry-slide", whereby the timeline would only go backwards 1 frame.

    This is what I have:
    PHP Code:
    function keyEvent e:KeyboardEvent )
    {
        switch ( 
    e.keyCode ) {
            case 
    Keyboard.LEFT :
                if (
    currentLabel != "entry_slide" or "rivalry_slide") {
                    
    gotoAndPlay currentFrame 1);
                }
                else{
                
    gotoAndPlay currentFrame );
                }
            case 
    Keyboard.RIGHT :
                
    nextFrame();
                
        
        }
    }

    stage.addEventListener KeyboardEvent.KEY_DOWNkeyEvent ); 
    But this is not working.... any ideas?

    Thanks!
    Cheers !
    BOB

  5. #5
    Member
    Join Date
    Jan 2004
    Location
    in a cave w/ wireless internet
    Posts
    95
    I realized the or doesn't work, so this is what i've setup, instead. In the particular instances where it needs to go back one frame, i just call the actual frame label, I still can't get it to work properly though .

    PHP Code:
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard

    function 
    keyEvent e:KeyboardEvent )
    {
        switch ( 
    e.keyCode ) {
            case 
    Keyboard.LEFT :
                if (
    currentLabel != "entry_slide") {
                    
    gotoAndPlay ("forces_slide");
                }
                if (
    currentLabel != "rivalry_slide") {
                    
    gotoAndPlay ("entry_slide");
                }
                
                else {
                
    gotoAndPlay currentFrame );
                }
            case 
    Keyboard.RIGHT :
                
    nextFrame();
                
        
        }
    }

    stage.addEventListener KeyboardEvent.KEY_DOWNkeyEvent ); 
    Cheers !
    BOB

  6. #6
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;
    
    function keyEvent( e:KeyboardEvent ) {
    
    	switch ( e.keyCode ) {
    		case Keyboard.LEFT :
    			if (currentFrameLabel=="entry_slide") {
    				gotoAndPlay( currentFrame - 1 );
    			} else if (currentFrameLabel=="rivalry_slide") {
    				gotoAndPlay( currentFrame - 1 );
    			} else {
    				gotoAndPlay( currentFrame - 9 );
    			}
    			break;
    
    		case Keyboard.RIGHT :
    			nextFrame();
    			break;
    
    		default :
    			break;
    
    	}
    }
    
    stop();
    stage.addEventListener( KeyboardEvent.KEY_DOWN, keyEvent );

  7. #7
    Member
    Join Date
    Jan 2004
    Location
    in a cave w/ wireless internet
    Posts
    95
    Thank you for all your help!
    Cheers !
    BOB

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