# Flash as2 Need help with my function() code please

**URL:** https://forum.kirupa.com/t/flash-as2-need-help-with-my-function-code-please/331756
**Category:** flash
**Created:** [October 13, 2013, 8:53pm UTC](https://forum.kirupa.com/t/flash-as2-need-help-with-my-function-code-please/331756 "2013-10-13T20:53:17Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Jason\_Scholz](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@Jason\_Scholz](https://forum.kirupa.com/u/Jason_Scholz)
#### Post date: [October 13, 2013, 8:53pm UTC](https://forum.kirupa.com/t/flash-as2-need-help-with-my-function-code-please/331756/1 "2013-10-13T20:53:17Z")

</div>

Below is my code. All I am trying to do is, when I press the SPACE key, the character doesn’t keep going up. The spacebar is acting like a turbo button. If I press the space bar once, the character jumps, if I hold down the space bar, the character continues to keep going up. How to I make this so when the player presses the space or holds down the space, you will only execute a jump?

```php
class Hero extends MovieClip
{
    var velocity;
    var isJumping;
    var jumpSpeed;
    var startY;
    
    function onLoad()
    {
        velocity = 10;
        isJumping = false;
        jumpSpeed = 0;
        startY = _y;
    }
    
    function onEnterFrame()
    {
        if(Key.isDown(Key.RIGHT))
        {
            this.gotoAndStop(2);
            _x = _x + velocity;            
        }
        else if(Key.isDown(Key.LEFT))
        {
            this.gotoAndStop(3);
            _x = _x -+ velocity;
        }
        else
        {
            this.gotoAndStop(1);
        }
        
        if(isJumping)
        {
            _y += jumpSpeed;
            jumpSpeed += 1;
            if(_y >+ startY)
            {
                _y = startY;
                isJumping = false;
            }
        }
        
        if(Key.isDown(Key.SPACE))
        {
            isJumping = true;
            jumpSpeed = -5;
        }
    }
}

```
