Key Press

Hi,

I’m trying to use key press to “move” my character in flash…instead of the one like http://www.kirupa.com/developer/mx/movement_keys.htm
…what I want to achieve is to use the left and right keys to rotate the object…when I press right…it turns clockwise…and when i press left…it turn anti-clockwise…

So…anyone knows how it could be done?? :hair:

There might be better ways as I’m no ASguru, but you could do it like this:

supposed the targetmc has an instance name of myMC, put this in the main timeline:


speed = 2;

_root.onEnterFrame = function(){
	if(Key.isDown(Key.RIGHT)) {
		_root.myMC._rotation += speed;
	} 
	else if (Key.isDown(Key.LEFT)) {
		_root.myMC._rotation -= speed;
	}
}

Thanks…the rotation works…but there’s a slightly problem here…

For example…when my MC has rotated 90 clockwise…I would wan it to move to the right using my right key…and not rotate even more…how can this be acheived?

try this:


speed = 4;

_root.onEnterFrame = function(){
	if(Key.isDown(Key.RIGHT)) {
		if(_root.myMC._rotation >= 90){
			_root.myMC.rotation = 90;
			_root.myMC._x += speed;
		}
		else _root.myMC._rotation += speed;
	} 
	else if (Key.isDown(Key.LEFT)) {
		if(_root.myMC._rotation <= -90){
			_root.myMC.rotation = -90;	
			_root.myMC._x -= speed;	
		}
		else _root.myMC._rotation -= speed;
	}
}

I hope this is what you’re looking for?

it doesn’t seem to work…

actually…what i gave was an example… what if I jus want the right and left keys to rotate…and the up key to move forward and down key to reverse?

Eg: If i had rotate my MC 90 degrees clockwise, how to get it to move right (which is forward) using the up key?

It works actually…but that’s not what i want.

What I actually want is that user can freely navigate the character…using up and down keys to move forward and reverse, left and right keys to rotate…=|

try making the object a movie clip, have it play certain frames when the user presses left, as in
onKeyPress(<left>) {
gotoAndPlay(10);
}
(for example)…
and when they press up and down, the movie clip can move up and down…and i’m pretty sure you know how to do that

play certain frames? but that’s not what i wanted. Instead of preset animation, I want the MC to move according to the user key presses…

ya i get it…and it’s possible with a mc…but try it with the code first…it’ll probably be less of a headache

hmm…how can i get this key press effect using AS?

http://www.jump-tomorrow.com/

Pls help…i’m still a newbie…=|