PDA

View Full Version : [AS3] dance matt / arrow help


kizzab
02-23-2009, 02:16 PM
Hey first of all a big hello to every one on ActionScipt! I'm very new to 3.0 And flash so please bare with me! This is a great website and i suspect your receive lots of nasty script questions from me! :P

Basically at the moment i have created a character in several different poses and made them a movie clip... Im basically trying to make the animation play on a key press then return to the characters normal state..

Im trying to make a game where by a line of arrows go across the stage and a certain area is red... when the arrow is in this "red" the user pressed that arrow and if done correctly the character will run this animation and a score will be added... im trying to get this completed for friday as its part of a huge flash game / environment im involved with in a team at university! So far i have linked the character to the action script and tried this code which is wrong!!

and help would be much appreciated as im really stuck!

var timmyJump:Boolean = false;

stage.addEventListener(Event.ENTER_FRAME, run);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);

function keyPressed(event:KeyboardEvent):void {
switch (event.keyCode) {
case Keyboard.UP :
timmyJump = true;
break;
}
}

function keyReleased(event:KeyboardEvent):void {
switch (event.keyCode) {
case Keyboard.UP :
timmyJump = false;
break;
}
}


Thanks for your time, and hi...

Kieren

Ciubhran
02-23-2009, 02:26 PM
use the real integer values of the keys (instead of the pre-defined ones (Keyboard.UP and such)), that solved one of the problems I had when implementing my movement function in as3.

http://people.uncw.edu/tompkinsj/112/FlashActionScript/keyCodes.htm

kizzab
02-23-2009, 02:40 PM
thanks for quick reply i'm very new to all of this but ill give this ago and see how i do :)

kizzab
02-24-2009, 01:34 PM
basically i have created 4 movie clips with a character doing 4 different actions..
im trying to get the character "timmy_mc" to do the actions "timmylk_mc" etc etc on a arrow key press...

basically when the user presses one of the arrow keys i wanted it to do that action then return to its normal state..

im using AS3 and have tried several different things but dont know where im going wrong! any help and maybe a brief description of how this was achieved would be great.. i have given it ago with some tutorials but really havent much sense of it!

at first i tried something like

timmy.onEnterFrame = function() {
if (Key.isDown(Key.RIGHT)) {
gotoAndPlay

this is old and wrong! so i tried something along the lines of

var timmyJump:Boolean = false;

stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);

function keyPressed(event:KeyboardEvent):void {
switch (event.keyCode) {
case Keyboard.UP :
timmyJump = true;
break;
}
}

function keyReleased(event:KeyboardEvent):void {
switch (event.keyCode) {
case Keyboard.UP :
timmyJump = false;
break;
}
}


i know im still going wrong but any help would be great

bluemagica
02-24-2009, 04:35 PM
function keyReleased(event:KeyboardEvent):void
{
if(event.keyCode==32) //32 is space, i forgot arrow
{
timmyJump = false;
}
else if(event.keyCode==97) // use a ascii chart to get key values
}

// You can also do trace(event.keyCode); to get the codes and use them as needed