Multiple Keypresses

I did search the forums better this time and found nothing on this particula topic - I’m trying to figure out how to have an event on multiple keypresses rather than just one. For example I have:


on (keyPress “<Left>”) {

loadText=new loadVars();
loadText.load(“audiophile.txt”);
loadText.onLoad = function(success) {
if (success) {
// trace(success);
MainBox.html = true;
MainBox.htmlText = this.audiophileText;
}
}
}


But rather than just on the “Left” key, I want it to be Left + 1 (holding them down at the same time). How can I do that?

You just add an “if” statement inside the “if LEFT” statement:
if (key is left) {
if (key is 1) {
do whatever…
}
}

Obviously, this is not the proper code, but I’m sure you can take it from here…

That didn’t work… When I changed my coding to that, It said “(” expected…

Ugh. This is so tiring.

make it a movieclip, and use:


onClipEvent (enterFrame) {
	if (Key.isDown(Key.LEFT)) {
		trace("LEFT IS PRESSED");
	}
	if (Key.isDown(Key.RIGHT)) {
		trace("RIGHT IS PRESSED");
	}
	if (Key.isDown(Key.UP)) {
		trace("UP IS PRESSED");
	}
	if (Key.isDown(Key.DOWN)) {
		trace("DOWN IS PRESSED");
	}
}

instead of on(key)…

should work…

Ugh. That only screws up the entire thing. I have no idea what to do here and I’m inches away from freaking out :-/ I tried to turn it into a movie clip, but the thing is it had been working before when I just had it set to on (keyPress) - then when I tried to switch it around, nothing worked! The problem is - what am I supposed to turn into a movie clip - all I want to do is load text into a box when 2 keys are pressed! ahsdjfkgvkdlksjg

wow…a thank-you for the people who tried to HELP might have be nice

I’m really sorry - I don’t mean to come off as rude - I really do appreciate it and love all of you, I’m just not thinking straight and having a rough week, but I shouldn’t be taking it at on you wonderful folk - please don’t take me too seriously, and yes, THANK YOU.

did you solve your problem? that just dozn’t make sence

onKeyDown = function () {
	if (Key.isDown(Key.LEFT) && Key.isDown("1".charCodeAt(0))) {
		loadText = new loadVars();
		loadText.load("audiophile.txt");
		loadText.onLoad = function(success) {
			if (success) {
				// trace(success);
				MainBox.html = true;
				MainBox.htmlText = this.audiophileText;
			}
		};
	}
};
Key.addListener(this);

Ahhh, thank you Claudio! Sends yummy foods

This appears to be working except for:

Error Scene=Scene 1, layer=Text, frame=24:Line 1: Statement must appear within on handler
this.onKeyDown = function () {

Total ActionScript Errors: 1 Reported Errors: 1

Gah! I took it out of the button’s actionscript and put it on the main timeline and it’s working fine now. Man, it’s always the silliest things :-/ If only Flash would TELL you. But we couldn’t be so lucky! :stuck_out_tongue:

Thank you immensely Claudio, RvGaTe, and deQue. I really appreciate it!

Why not try:
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT) and (Key.isDown(Key.RIGHT)) {
trace(“Left and right have been pressed?”);
}
is what what u wanted?

Ugh. Still having issues :-/ Here’s what I have:

onKeyDown = funtion () {
if (Key.isDown(Key.LEFT) && Key.isDown(“46”.charCodaAt(0))) {
loadText = new LoadVars();
loadText.load(“audiophile.txt”);
loadText.onLoad = function(success) {
if (success) {
//trace(success),
MainBox.html = true;
MainBox.htmlText = this.audiophileText;
Key.addListener();
}
};
}
};

And I have it on the main timeline… I get “this script contains no errors” yet nothing happens when I test it… Does it need to be associated with a button? Or a movie clip?

That script is not the one i posted before.

samotboy’s is the easyest/shortest.
Maybe you’ve tried and it didnt work. Thats because there’s a Typing Mistake in it.

onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT) and Key.isDown(Key.RIGHT)) {
trace(“Left and right have been pressed?”);
}

works.