# Easy key press question but im dumb

**URL:** <https://forum.kirupa.com/t/easy-key-press-question-but-im-dumb/25981>\
**Category:** flash\
**Created:** [July 18, 2003, 5:32am UTC](https://forum.kirupa.com/t/easy-key-press-question-but-im-dumb/25981 "2003-07-18T05:32:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dAEL](https://avatars.discourse-cdn.com/v4/letter/d/df705f/32.png) [@dAEL](https://forum.kirupa.com/u/dAEL)\
**Post date:** [July 18, 2003, 5:32am UTC](https://forum.kirupa.com/t/easy-key-press-question-but-im-dumb/25981/1 "2003-07-18T05:32:33Z")

</div>

Okay i am messing with action script and i have it when u press space, it reverses gravity, but when u release space, it returns to normal. So far that works, but i have it when it hits a block on the stage, it stops moving.

```auto
onClipEvent (enterFrame) {
	if (Key.isDown(Key.SPACE)) {
	gravity = -2;
	}
	else {
		gravity = 2;
	}
}

```

okay now if i leave out the else part the ball will fly up and not coem back down when i release space, but with the “else” bit, it sinks through the block that it hits.

Heres everything ive got, jsut make a circle, instance name “ball”, put a block under it, instance name “block”. thats my setup, all of these actions go into the ball.

```auto
onClipEvent (load) {
	gravity = 2 ;
	speedx = 0 ;
	speedy = 0 ;
}
onClipEvent (enterFrame) {
	speedy = speedy + gravity ;
	this._x += speedx/1 ;
	this._y += speedy/1 ;
}
onClipEvent (enterFrame) {
	if (_root.ball, hitTest(_root.block)) {
		speedy = 0;
		speedx = 0;
		gravity = 0;
	}
}
onClipEvent (enterFrame) {
	if (Key.isDown(Key.SPACE)) {
	gravity = -2;
	}
	else {
		gravity = 2;
	}
}

```

I know its messy and could really be cleaned up, but im learning. Thanks in advance for any help 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 18, 2003, 10:58am UTC](https://forum.kirupa.com/t/easy-key-press-question-but-im-dumb/25981/2 "2003-07-18T10:58:02Z")

</div>

You can’t have 3 enterFrames at the same time 🙂 Put everything in 1 handler.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 18, 2003, 3:24pm UTC](https://forum.kirupa.com/t/easy-key-press-question-but-im-dumb/25981/3 "2003-07-18T15:24:56Z")

</div>

still doesnt fix the problem, when the ball hits the block, it still get pullled through it. im almost positive that somethnig has to come after “else”, like the releasing of teh spac bar. I jsut dont know teh code to do that.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 18, 2003, 4:20pm UTC](https://forum.kirupa.com/t/easy-key-press-question-but-im-dumb/25981/4 "2003-07-18T16:20:27Z")

</div>

```auto
if (_root.ball, hitTest(_root.block)) {

```

thats interesting syntax 🙂 try this:

```auto
if (_root.block.hitTest(_root.ball._x,_root.ball._y)) {

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 18, 2003, 6:17pm UTC](https://forum.kirupa.com/t/easy-key-press-question-but-im-dumb/25981/5 "2003-07-18T18:17:24Z")

</div>

Ha, my bad everyone, what I wa trying to do was 2 clashing ideas that wouldnt work together, so thanks for the help anyway.
