Copy link to clipboard
Copied
I am using Adobe Flash Professional CS6
i am facing a problem more then a month and not finding any solution and now i am pretty frustrated. As my last resort i am posting it here.
I am making a hero move with the keyboard. I have 4 animations.
It's working well so far, but the problem I'm facing in jumping the player is having to hold down the key to jump. I don't want the player to be required to hold the key to perform jumping. I want to play the full Movie Clip (lets say 10 frame with different image) with one key press, and honestly I don't know how to do it.
plz help
Here is the file Kim movement.zip - Google Drive
here is my code
import flash.display.Stage;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.display.MovieClip;
import flash.events.Event;
kim.gotoAndStop("kim Stand");
var grav:int = 0;
var floor = 450;
var dPressed:Boolean = false;
var aPressed:Boolean = false;
var jumping:Boolean = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN , keyDownHandaler);
stage.addEventListener(KeyboardEvent.KEY_UP , KeyUpHandaler);
stage.addEventListener(Event.ENTER_FRAME , gameLoop);
function keyDownHandaler(Devent:KeyboardEvent😞void
{
if (Devent.keyCode == Keyboard.D)
{
dPressed = true;
}
else if (Devent.keyCode == Keyboard.A)
{
aPressed = true;
}
else if (Devent.keyCode == Keyboard.W && !jumping)
{
jumping = true;
}
}
function KeyUpHandaler (Uevent:KeyboardEvent😞void
{
if (Uevent.keyCode == Keyboard.D)
{
dPressed = false;
kim.gotoAndStop("kim Stand");
}
else if(Uevent.keyCode == Keyboard.A)
{
aPressed = false;
kim.gotoAndStop("kim Stand");
}
else if(Uevent.keyCode == Keyboard.W)
{
jumping = false;
kim.gotoAndStop("kim Stand");
}
}
function gameLoop(Levent:Event😞void
{
if (dPressed)
{
kim.x += 5;
kim.gotoAndStop("kim Move Right");
}
else if(aPressed)
{
kim.x -= 5;
kim.gotoAndStop("kim Move Left");
}
else if(jumping)
{
kim.gotoAndStop("kim Jump");
kim.y -= 10;
}
gravity();
}
function gravity ():void
{
kim.y += grav;
if (kim.y+kim.height/2 <floor){
grav++;
}
else {
grav = 0;
kim.y = floor - kim.height/2 ;
}
}
Copy link to clipboard
Copied
Based on the code you show the jump initiates when the mousedown action occurs and it ends when the mouseup action occurs. If you want it to end at someother time then you need to have that end occur using some other means, such as using a Timer to initiate the end of the jump after an amount of time passes. You would have to initiate the Timer as part of the mousedown action.
Copy link to clipboard
Copied
its not the time i want , i want to play the whole movie clip i mean it will play to it's last frame once for 1 click and then it will go back to normal.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now