Forum Topic: moving with arrow keys

(101 views • 6 replies)

This topic is 1 page long.

<< < > >>
Questioning

PsyGuy08

Reply To Post Reply & Quote

Posted at: 11/7/09 02:07 AM

PsyGuy08 LIGHT LEVEL 06

Sign-Up: 09/27/09

Posts: 1

Can somebody explain to me how to make a symbol move when I press the corresponding arrow keys? Thanks..

-who are you and why the hell are you still reading this? who am I? where am I?! WHAT THE F-

BBS Signature

None

AMOE1st

Reply To Post Reply & Quote

Posted at: 11/7/09 02:11 AM

AMOE1st LIGHT LEVEL 03

Sign-Up: 01/09/07

Posts: 104

you really should check out the AS:Main thing before asking...


None

grafik2d

Reply To Post Reply & Quote

Posted at: 11/7/09 09:38 AM

grafik2d NEUTRAL LEVEL 10

Sign-Up: 06/29/04

Posts: 176

http://www.newgrounds.com/collection/fla shtutorials.html

A little search never hurt anyone, try it sometime instead of mindlessy posting for help.


None

Yambanshee

Reply To Post Reply & Quote

Posted at: 11/7/09 09:40 AM

Yambanshee DARK LEVEL 11

Sign-Up: 10/05/08

Posts: 1,587

and mention ur AS version

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

None

Kenney

Reply To Post Reply & Quote

Posted at: 11/7/09 09:48 AM

Kenney NEUTRAL LEVEL 17

Sign-Up: 03/16/02

Posts: 2,354

Well, if you use AS2 you can simple paste this code on the MovieClip:

onClipEvent(load){
	speed = 5; // Defines the speed variable
}

onClipEvent(enterFrame){
	if(Key.isDown(Key.LEFT)){ // If 'LEFT' key is pressed
		_x -= speed; // Add 'speed' to X position
	}else if(Key.isDown(Key.RIGHT)){ // If 'RIGHT' key is pressed
		_x += speed; // Subtract 'speed' from X position
	}
	
	if(Key.isDown(Key.UP)){ // If 'UP' key is pressed
		_y -= speed; // Subtract 'speed' from Y position
	}else if(Key.isDown(Key.DOWN)){ // If 'DOWN' key is pressed
		_y += speed; // Add 'speed' to Y position
	}
}

Visit my website: Kenney.nl


Happy

blubfaceproduction

Reply To Post Reply & Quote

Posted at: 11/7/09 09:50 AM

blubfaceproduction LIGHT LEVEL 07

Sign-Up: 08/01/09

Posts: 15

If you're in AS 2.0, here's how you make it happen. Put this code on the symbol you want to move:
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.UP)) {
_y -= speed;
}
if (Key.isDown(Key.DOWN)) {
_y += speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
speed = 10;
}

Blubfaceproduction - the Best Flash on Newgrounds except for all the others


None

grafik2d

Reply To Post Reply & Quote

Posted at: 11/7/09 07:31 PM

grafik2d NEUTRAL LEVEL 10

Sign-Up: 06/29/04

Posts: 176

At 11/7/09 09:50 AM, blubfaceproduction wrote: If you're in AS 2.0, here's how you make it happen. Put this code on the symbol you want to move:
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.UP)) {
_y -= speed;
}
if (Key.isDown(Key.DOWN)) {
_y += speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
speed = 10;
}

I strongly suggest you avoid using this method. Putting code on moviclip might seem easier at first, but as you progress it will only drag you down and mess up your projects. All you need to do is to give an instance name to your clip and put your code inside functions on the main timeline like this

var speed:Number=10;
this.onEnterFrame=function(){
yourFunction();
}

function yourFunction(){
//your code
if (Key.isDown(Key.LEFT)) { this.yourMC._x -= speed;}
if (Key.isDown(Key.UP)) { this.yourMC._y -= speed;}
if (Key.isDown(Key.DOWN)) { this.yourMC._y += speed;}
if (Key.isDown(Key.RIGHT)) {this.yourMC._x += speed;}

}


All times are Eastern Standard Time (GMT -5) | Current Time: 01:04 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!