# Trouble using a function

**URL:** <https://forum.kirupa.com/t/trouble-using-a-function/123191>\
**Category:** Uncategorized\
**Created:** [September 21, 2004, 1:42pm UTC](https://forum.kirupa.com/t/trouble-using-a-function/123191 "2004-09-21T13:42:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoMan](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@JoMan](https://forum.kirupa.com/u/JoMan)\
**Post date:** [September 21, 2004, 1:42pm UTC](https://forum.kirupa.com/t/trouble-using-a-function/123191/1 "2004-09-21T13:42:08Z")

</div>

Hello again. Well, I decided to put my jumping code into a function instead of a onClipEvent handler, but something is wrong. When I press the space bar(jumping key), he keeps on moving up until I release the key. Here is the code:

```php

_root.onEnterFrame = function() {
 jumping();
 vel_y = 0;
 jump = false;
};
function jumping() {
 if (Key.isDown(Key.LEFT)) {
  hero._x -= 5;
 }
 if (Key.isDown(Key.RIGHT)) {
  hero._x += 5;
 }
 if (Key.isDown(Key.SPACE) && !jump) {
  vel_y = 10;
  jump = true;
 }
 if (jump == true) {
  vel_y -= 1;
  if (vel_y<=-10) {
   vel_y = -10;
  }
  hero._y -= vel_y;
 }
 if (_root.ground.hitTest(hero._x, hero._y+15, true)) {
  vel_y = 0;
  jump = false;
 }
 if (!_root.ground.hitTest(hero._x, hero._y+15, true) && !jump) {
  fall += 1;
  if (fall>10) {
   fall = 10;
  }
  hero._y += fall;
 }
}

```

If anyone could please help me, I would be very grateful. Thanks in advance!

peace
