You guys probably already know how to do this but can you help me with something? Its for a school project. How can I make it so the arrow keys each do something when you press them? Its in flash and we need to use action script. If you can't help thats fine.

Offline
Well... As in... This?

Offline
Oh, Math MIGHT know, I don't. I'll tell him

Offline
I'm going to go ahead and assume you're using AS3. Put this on the stage, or inside your document class:
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDown)
stage.addEventListener(KeyboardEvent.KEY_UP,keyUp)
function keyDown(e:KeyboardEvent):void
{
if(e.keyCode == Keyboard.RIGHT)
{
//The right arrow key was pressed
}
//Repeat with Keyboard.LEFT, Keyboard.UP, Keyboard.DOWN
}
function keyUp(e:KeyboardEvent):void
{
//You can basically do the same thing with the keyUp event
//The keyCode property of a KeyboardEvent tells you which key was pressed.
}Hope that's clear!

Offline
JJROCKER wrote:
Where should I put that script? The backround?
Yeah, just put that one the first frame of your movie. In AS3 you can't apply scripts directly to a MovieClip (you could with the last version of AS, which was a nifty Scratch-like feature).

Offline
JJROCKER wrote:
then what do I do?
Well, it depends. If you're trying to make a character move, you might create a variable "xVelocity" and manipulate it whenever the left or right keys are pressed. Then have the character's x position change every frame based on the velocity:
addEventListener(Event.ENTER_FRAME,function(e:Event):void{
character.x += xVelocity;
xVelocity *= .98;
})
Offline
Dude, you really need to learn some simple code samples, from reading this thread you don't really know anything.
First of all, no one even knows what version of actionscript, and what development tool you are using so no one can really answer you.
You can 2 options: AS2, very very easy, but less powerful and less structured
or AS3, more difficult but more powerful and better structured, recommended for those who want to learn proper programming.
If you want to do AS3 you need a copy of adobe/macromedia flash, for AS3 you can use flashdevelop.
Last edited by archmage (2011-05-25 19:13:50)
Offline
Ok, and what version of actionscript are you using, AS2 and AS3 are completely different.
Offline
It depends, heres my basic recommendations
AS2: Super easy, lets basically anyone code but its less powerful and not recommended for professionals. At this point in time I recommend it for young people who are not too serious about programming.
AS3: A tad harder than AS2, but it pays off because it is far more structured and powerful. I recommend it for any one who want to code seriously and at a professional level, it also makes it also to learn other popular languages including java and c++.
I am just going to assume you fall in to the first group of people so pick AS2.
Makes programs with the code from these resources as practice and you are good to go on your merry way to make games.
first http://www.newgrounds.com/portal/view/366346
second http://www.newgrounds.com/portal/view/344206
For the first link learn it all, seriously, do this, its all essential stuff.
For the second link you should learn all the basic and intermediate topics. The advanced is not really needed in most cases but it teaches things like basic 3d wireframes.
Last edited by archmage (2011-05-25 22:44:34)
Offline