Arrow key script not working :'(

here is my code


_root.onEnterFrame = function() {
	if (Key.isDown(38)) {
		function(){this._y+=mapspeed;
	}
}

here are the errors it produces

Scene=main, Layer=buttons, Frame=1: Line 8: Statement block must be terminated by ‘}’
_root.onEnterFrame = function() {

Scene=main, Layer=buttons, Frame=1: Line 12: Syntax error.
}

i’m still learning about AS’s syntax so please bare with me and my constant syntax blunders =)

thx

fixed it … thank you … i just left off the } at the end lol

i could hear lostinbeta in my head telling me to make sure all open parens are closed … lol

thx

I was using my psychic ability to help you fix it. Yeah… that was it :beam:

here is the final script i came up with if anyone is interested
yes it works =)
just put it on the frame’s actions

mapspeed is a variable set on the first frame … it’s default value is 5


//this is the control function for the arrowkey map controls
//up arrow
_root.onEnterFrame = function() {
	if (Key.isDown(38)) {
		_root.map._y+=mapspeed;
	}
//down arrow
	if (Key.isDown(40)) {
		_root.map._y-=mapspeed;
	}
//left arrow
	if (Key.isDown(37)) {
		_root.map._x+=mapspeed;
	}
//right arrow
	if (Key.isDown(39)) {
		_root.map._x-=mapspeed;
	}
}

another way to do it which doesnt take up as much space is


mapspeed = 3
_root.map.onEnterFrame = function(){
	this._x += (Key.isDown(Key.RIGHT)-Key.isDown(Key.LEFT))*mapspeed;
	this._y += (Key.isDown(Key.DOWN)-Key.isDown(Key.UP))*mapspeed;
}

Just making sure you know:

You have the Up key go down and the Down key go up. And Left goes right and Right goes left.

Also, Kirupa had a few tutorials on Keyboard movement. If you are interested in checking them out you can here…

http://www.kirupa.com/developer/mx/movement_keys.asp

http://www.kirupa.com/developer/actionscript/xymove.asp

Or to go in reverse directions like you have it set to do now…

mapspeed = 3;
_root.map.onEnterFrame = function() {
	this._x += (Key.isDown(Key.LEFT)-Key.isDown(Key.RIGHT))*mapspeed;
	this._y += (Key.isDown(Key.UP)-Key.isDown(Key.DOWN))*mapspeed;
};

yes i’m aware it makes the symbol move opposite the direction pressed but that makes the user appear to be going that direction. so they press the key in the direction the want to look and that direction is revealed. i felt it made it feel more natural.

thx for the other script but i probably shouldn’t use it since i don’t understand it

is that obfuscated beta? wtf is obfuscated?

lol … sorry if that’s a silly question but as is my first experience coding anything except html

thanks

*Originally posted by lostinbeta *
**Or to go in reverse directions like you have it set to do now…

mapspeed = 3;
_root.map.onEnterFrame = function() {
	this._x += (Key.isDown(Key.LEFT)-Key.isDown(Key.RIGHT))*mapspeed;
	this._y += (Key.isDown(Key.UP)-Key.isDown(Key.DOWN))*mapspeed;
};

**

that could be more easily accomplised by negating the variable :wink:

Oh yeah, like it was really much harder to switch it around…lol. I just dragged then dropped the code where I wanted.

Senocular… I will let you cover what obfuscated is for Shuga.

you can use the same function for both forward and backward directions by negating the speed =)

obfuscated: (ob-fe skat) adjective - To make so confused or opaque as to be difficult to perceive or understand. In terms of flash see this.