Hello People,
This is my first post here. I am currently trying to make a flash based game. In my codes below line of code:
if(RightKeyisDown)
{
Jason.x+=speed;
Jason.scaleX =0.63;
Jason.gotoAndStop(2);
The (2) frame in movieclip JASON contains a walking animation, however, I believe my arrow keys are simply reapeating the events when I hold it down, so my animation never plays.
How do I get my loop to actually play? I tried putting the* gotoAndStop* in my *PressAKey *definition function, but the animation only plays once.
Thanks in advance. Sorry if this comes off as a NEWB question
-------------- line of codes -----------------------
import flash.events.KeyboardEvent;
import flash.events.Event;
var RightKeyisDown:Boolean = false;
var LeftKeyisDown:Boolean = false;
var UpKeyisDown:Boolean = false;
var DownKeyisDown:Boolean = false;
var speed: Number = 7
var gravity: Number = 1;
var yVelocity: Number = 0;
var jumping: Boolean = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN, PressAKey);
stage.addEventListener(KeyboardEvent.KEY_UP, ReleaseAKey);
/// Key Reactions
function PressAKey(event: KeyboardEvent): void
{
if(event.keyCode == Keyboard.RIGHT)
{
RightKeyisDown = true;
}
if(event.keyCode == Keyboard.LEFT)
{
LeftKeyisDown = true;
}
if(event.keyCode == Keyboard.UP)
{
UpKeyisDown = true;
}
if(event.keyCode == Keyboard.DOWN)
{
DownKeyisDown = true;
}
}
function ReleaseAKey (event: KeyboardEvent): void
{
if(event.keyCode == Keyboard.RIGHT)
{
RightKeyisDown = false;
}
if(event.keyCode == Keyboard.LEFT)
{
LeftKeyisDown = false;
}
if(event.keyCode == Keyboard.UP)
{
UpKeyisDown = false;
}
if(event.keyCode == Keyboard.DOWN)
{
DownKeyisDown = false;
}
}
/// Moving Jason
Jason.addEventListener(Event.ENTER_FRAME, moveJason);
function moveJason(event:Event): void
{
if(RightKeyisDown)
{
Jason.x+=speed;
Jason.scaleX =0.63;
Jason.gotoAndStop(2);
}
if(LeftKeyisDown)
{
Jason.x-=speed;
Jason.scaleX =-0.63;
Jason.gotoAndStop(2);
}
if(DownKeyisDown)
{
Jason.gotoAndStop(3);
}
{
if(!RightKeyisDown&&!LefyKeyisDown&&!DownKeyisDown&&!UpKeyisDown)
Jason.gotoAndPlay(1)
}
if(UpKeyisDown&&jumping)
{
yVelocity = -15;
jumping = false
Jason.gotoAndStop(4);
}
yVelocity += gravity
if(!Floor.hitTestPoint(Jason.x, Jason.y, true))
{
Jason.y+=yVelocity;
}
if(yVelocity > 20)
{
yVelocity = 20;
}
for(var i:int=0;i<10;i++)
{
if(Floor.hitTestPoint(Jason.x,Jason.y, true))
{
Jason.y --;
yVelocity = 0;
jumping = true
}
}