# Why is my monkey not jumping

**URL:** <https://forum.kirupa.com/t/why-is-my-monkey-not-jumping/332146>\
**Category:** flash\
**Created:** [February 14, 2014, 10:29pm UTC](https://forum.kirupa.com/t/why-is-my-monkey-not-jumping/332146 "2014-02-14T22:29:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![o111](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/o111/32/2123_2.png) [@o111](https://forum.kirupa.com/u/o111)\
**Post date:** [February 14, 2014, 10:29pm UTC](https://forum.kirupa.com/t/why-is-my-monkey-not-jumping/332146/1 "2014-02-14T22:29:24Z")

</div>

Hey,

I’m playing around with a platform game. I had all the basic controls almost done when my monkey decided he didn’t want to jump anymore. Basically nothing happens when I now press UP. It doesn’t even go to the jumping-animation frame inside the player\_mc.

I think something is saying he can’t jump, so the “canJump” thing doesn’t work.

Was following this tutorial: [URL=“[http://www.youtube.com/watch?v=B8FLQVODzgcGreat](http://www.youtube.com/watch?v=B8FLQVODzgcGreat)”][http://www.youtube.com/watch?v=B8FLQVODzgc](http://www.youtube.com/watch?v=B8FLQVODzgc)

Great if anyone wants to look at this. Here’s a picture for inspiration:

Anyway, here is the code I’ve got down:

```auto
import flash.events.KeyboardEvent;

var KeyThatIsPressed:uint;
var RightKeyIsDown:Boolean = false;
var LeftKeyIsDown:Boolean = false;
var UpKeyIsDown:Boolean = false;
var DownKeyIsDown:Boolean = false;

var playerSpeed:Number = 12;
var gravity:Number = 2;
var yVelocity:Number = 0;
var canJump:Boolean = false;

stage.addEventListener(KeyboardEvent.KEY_DOWN, PressAKey);
stage.addEventListener(KeyboardEvent.KEY_UP, ReleaseAKey);

// PressAKey function here

function PressAKey(event:KeyboardEvent):void

{

    if(event.keyCode == Keyboard.RIGHT)
    {
        
        RightKeyIsDown = true;
        
    }
    
    if(event.keyCode == Keyboard.LEFT)
    {
        
        LeftKeyIsDown = true;
        
    }
    
    if(event.keyCode == Keyboard.UP)
    {
        
        UpKeyIsDown = true;
        
    }
    
    if(event.keyCode == Keyboard.DOWN)
    {
        
        DownKeyIsDown = true;
        
    }

}

// ReleaseAKey function here

function ReleaseAKey(event:KeyboardEvent):void

{
    
    {
        
        RightKeyIsDown = false;
        
    }
    
    if(event.keyCode == Keyboard.LEFT)
    {
        
        LeftKeyIsDown = false;
        
    }
    
    if(event.keyCode == Keyboard.UP)
    {
        
        UpKeyIsDown = false;
        
    }
    
    if(event.keyCode == Keyboard.DOWN)
    {
        
        DownKeyIsDown = false;
        
    }
    
}

player_mc.addEventListener(Event.ENTER_FRAME, moveThePlayer);

function moveThePlayer(event:Event):void

{
    
    if(RightKeyIsDown)
    {
        
        player_mc.x += playerSpeed;
        player_mc.scaleX = 1;
        player_mc.gotoAndStop(2);
        
    }
    
    if(LeftKeyIsDown)
    {
        
        player_mc.x -= playerSpeed;
        player_mc.scaleX = -1;
        player_mc.gotoAndStop(2);
        
    }
    
    if(UpKeyIsDown && canJump)
    {
        
        yVelocity = -30;
        canJump = false;
        player_mc.gotoAndStop(3);
        
    }

    
    if(!RightKeyIsDown && !LeftKeyIsDown && !UpKeyIsDown)
    
    {
    
        player_mc.gotoAndStop(1);
        
    }    
    
    }
    
    yVelocity += gravity;

    if(! floor_mc.hitTestPoint(player_mc.x, player_mc.y, true))
    
    {
    
        player_mc.y += yVelocity;
    
    }    
    
    if(yVelocity > 20)
        
    {
        
        yVelocity = 20;
        
    }
    
    for (var i:int = 0; i<10; i++)
    
    {
        
        if (floor_mc.hitTestPoint(player_mc.x, player_mc.y, true))
            
        {
            
            player_mc.y--;
            yVelocity = 0;
            canJump = true;
        }
        
    }

```
