Easy key press question but im dumb

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.

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.

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 :slight_smile:

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

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.

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

thats interesting syntax :slight_smile: try this:

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

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