Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9272439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:52:43+00:00 2026-06-18T15:52:43+00:00

I am making a platformer game. But I am having issue because whenever I

  • 0

I am making a platformer game. But I am having issue because whenever I pressed the spacebar to jump, the character will stuck in the mid-air. However, I can resolved the problem by holding spacebar and the character will land.

The issue is at mainJump() located inside Boy class.

I seen many people solved the problem by using action timeline, but my main problem is, are there anyway I can solve the problem by using an external class?

Main class

package 
{
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.utils.Timer;
import flash.text.*;

public class experimentingMain extends MovieClip 
{
    var count:Number = 0;
    var myTimer:Timer = new Timer(10,count);

    var classBoy:Boy;

    //var activateGravity:gravity = new gravity();

    var leftKey, rightKey, spaceKey, stopAnimation:Boolean;

    public function experimentingMain() 
    {
        myTimer.addEventListener(TimerEvent.TIMER, scoreUp);
        myTimer.start();

        classBoy = new Boy();
        addChild(classBoy);


        stage.addEventListener(KeyboardEvent.KEY_DOWN, pressTheDamnKey);
        stage.addEventListener(KeyboardEvent.KEY_UP, liftTheDamnKey);
    }

    public function pressTheDamnKey(event:KeyboardEvent):void
    {
        if (event.keyCode == 37)
        {
            leftKey = true;
            stopAnimation = false;
        }

        if (event.keyCode == 39)
        {
            rightKey = true;
            stopAnimation = false;
        }

        if (event.keyCode == 32)
        {
            spaceKey = true;
            stopAnimation = true;
        }
    }

    public function liftTheDamnKey(event:KeyboardEvent):void
    {
        if (event.keyCode == 37)
        {
            leftKey = false;
            stopAnimation = true;
        }

        if (event.keyCode == 39)
        {
            rightKey = false;
            stopAnimation = true;
        }

        if (event.keyCode == 32)
        {
            spaceKey = false;
            stopAnimation = true;
        }
    }

    public function scoreUp(event:TimerEvent):void 
    {
        scoreSystem.text = String("Score : "+myTimer.currentCount);
    }

}
    }

Boy class

package 
{
import flash.display.*;
import flash.events.*;

public class Boy extends MovieClip
{
    var leftKeyDown:Boolean = false;
    var upKeyDown:Boolean = false;
    var rightKeyDown:Boolean = false;
    var downKeyDown:Boolean = false;
    //the main character's speed
    var mainSpeed:Number = 5;
    //whether or not the main guy is jumping
    var mainJumping:Boolean = false;
    //how quickly should the jump start off
    var jumpSpeedLimit:int = 40;
    //the current speed of the jump;
    var jumpSpeed:Number = 0;

    var theCharacter:MovieClip;

    var currentX,currentY:int;

    public function Boy()
    {
        this.x = 600;
        this.y = 540;

        addEventListener(Event.ENTER_FRAME, boyMove);
    }

    public function boyMove(event:Event):void
    {
        currentX = this.x;
        currentY = this.y;

        if (MovieClip(parent).leftKey)
        {
            currentX +=  mainSpeed;
            MovieClip(this).scaleX = 1;
        }

        if (MovieClip(parent).rightKey)
        {
            currentX -=  mainSpeed;
            MovieClip(this).scaleX = -1;
        }

        if (MovieClip(parent).spaceKey)
        {
            mainJump();
        }

        this.x = currentX;
        this.y = currentY;
    }

    public function mainJump():void
    {
        currentY = this.y;


        if (! mainJumping)
        {

            mainJumping = true;
            jumpSpeed = jumpSpeedLimit * -1;
            currentY +=  jumpSpeed;
        }
        else
        {
            if (jumpSpeed < 0)
            {
                jumpSpeed *=  1 - jumpSpeedLimit / 250;
                if (jumpSpeed > -jumpSpeedLimit/12)
                {
                    jumpSpeed *=  -2;
                }
            }
        }
        if (jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit)
        {
            jumpSpeed *=  1 + jumpSpeedLimit / 120;
        }
        currentY +=  jumpSpeed;

        if (currentY >= stage.stageHeight - MovieClip(this).height)
        {
            mainJumping = false;
            currentY = stage.stageHeight - MovieClip(this).height;
        }
    }
    }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:52:44+00:00Added an answer on June 18, 2026 at 3:52 pm

    You’ve got a mainJumping variable that is only true while the jump is running. Why not just use that?

    if (MovieClip(parent).spaceKey || mainJumping)
    {
        mainJump();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im making a platform type of game. I made my main character a rectangle
hi i am making a game in flash as3 ios devices, but I have
I am making a platform game, but i have a problem with my collision
I'm making a game that will allow content development and I'd like it to
I'm making a 2D platformer game and to represent a level I'm using 2D
I am making a 2D game for the Android platform. The character is supposed
Let me explain my situation... I'm making a 2D platformer game, where you can
Im currently working on making a flash platformer engine...but my collision detect needs some
Well, I'm making a relatively simple platformer game with java and I have a
I am making a top-down platformer game using sprites. I would like to add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.