AS3 - CS5 - iOS Game - Main character won't jump when (b_button) is pressed

Hello all,

Thank you for taking the time to read and try to help me out with this small issue. I’m not a programmer, I’m more of a designer with aspirations of continue learning “logics”. Well, enough of that.

My problem is as follow: When I deploy to the iPhone 5 for testing, app installs all good, runs all good, and all buttons work (SEPARATE) all good. In this platformed game I’m developing, when the user touches the (l_button or r_button) left and right, the character moves just fine. But if the user is holding the left button and ttys to use the B button for jumping, nothing happens. It doesn’t register at all. no trace, no actions, no nothing. Its like the device can only handle on “press” at the time. I’m sure the problem lies somewhere in my novice code. So please if anyone could help me with this, I would greatly appreciate it.

Thank you!

Here is my current source;:megaman_classic:



// BG variables
    var scrollX:Number = 0;
    var scrollY:Number = 0;
    var xSpeed:Number = 0;
    var ySpeed:Number = 0;
    var centermap:Number = 0;
    
// Gravity STuff
    var gravityConstant:Number = 4;
    var jumpConstant:Number = -90;
    var maxSpeedConstant:Number = 25;
    var minSpeedConstant:Number = 0;
    var frictionConstant:Number = 0.8;
    var speedConstant:int = 6;
    
// Collision Detection
    var leftBumping:Boolean = false;
    var rightBumping:Boolean = false;
    var upBumping:Boolean = false;
    var downBumping:Boolean = false;
    
    // Creating Collision Points inside the Hero
        var leftBumpPoint:Point = new Point(-63, -3);
        var rightBumpPoint:Point = new Point(40, -3);
        var upBumpPoint:Point = new Point(-17, -62);
        var downBumpPoint:Point = new Point(-17, 70);
    
    

// character movement
    var lPressed:Boolean = false;
    var rPressed:Boolean = false;
    var aPressed:Boolean = false;
    var bPressed:Boolean = false;
     
    
    l_button.addEventListener(MouseEvent.MOUSE_DOWN,l_down);
    r_button.addEventListener(MouseEvent.MOUSE_DOWN,r_down);
    a_button.addEventListener(MouseEvent.MOUSE_DOWN,a_down);
    b_button.addEventListener(MouseEvent.MOUSE_DOWN,b_down);
    
    function l_down(e:Event):void{
        this.key = "l";
        HeroFacing = "left";
        keyDownHandler(e);
        }
        
    function r_down(e:Event):void{
        this.key = "r";
        HeroFacing = "right";
        keyDownHandler(e);
        }
        
    function a_down(e:Event):void{
        this.key = "a";
        keyDownHandler(e);
        }
        
    function b_down(e:Event):void{
        this.key = "b";
        heroJump(e);
        keyDownHandler(e);
        }
    
    
    function keyDownHandler(e:Event):void{
        if(this.key == "l"){
            lPressed = true;
            trace("L Pressed");
     
        } else if(this.key == "r"){
            rPressed = true;
            trace("R Pressed");
     
        } else if(this.key == "a"){
            aPressed = true;
            trace("A Pressed");
     
        } else if(this.key == "b"){
            bPressed = true;
            trace("B Pressed");
        }
    }
    
    
    
    

    l_button.addEventListener(MouseEvent.MOUSE_UP,l_UP);
    r_button.addEventListener(MouseEvent.MOUSE_UP,r_UP);
    a_button.addEventListener(MouseEvent.MOUSE_UP,a_UP);
    b_button.addEventListener(MouseEvent.MOUSE_UP,b_UP);
    
    function l_UP(e:Event):void{
        this.key = "l";
        heroIddle(e);
        keyUpHandler(e);
        }
        
    function r_UP(e:Event):void{
        this.key = "r";
        heroIddle(e);
        keyUpHandler(e);
        }
        
    function a_UP(e:Event):void{
        this.key = "a";
        keyUpHandler(e);
        }
        
    function b_UP(e:Event):void{
        this.key = "b";
        keyUpHandler(e);
        }
    
    function keyUpHandler(e:Event):void{
        if(this.key == "l"){
            lPressed = false;
     
        } else if(this.key == "r"){
            rPressed = false;
     
        } else if(this.key == "a"){
            aPressed = false;
     
        } else if(this.key == "b"){
            bPressed = false;
        }
    }
    
    
    
    

    l_button.addEventListener(MouseEvent.ROLL_OUT,l_ROLLOUT);
    r_button.addEventListener(MouseEvent.ROLL_OUT,r_ROLLOUT);
    a_button.addEventListener(MouseEvent.ROLL_OUT,a_ROLLOUT);
    b_button.addEventListener(MouseEvent.ROLL_OUT,b_ROLLOUT);
    
    function l_ROLLOUT(e:Event):void{
        this.key = "l";
        heroIddle(e);
        keyRollOutHandler(e);
        }
        
    function r_ROLLOUT(e:Event):void{
        this.key = "r";
        heroIddle(e);
        keyRollOutHandler(e);
        }
        
    function a_ROLLOUT(e:Event):void{
        this.key = "a";
        keyRollOutHandler(e);
        }
        
    function b_ROLLOUT(e:Event):void{
        this.key = "b";
        keyRollOutHandler(e);
        }
    
    function keyRollOutHandler(e:Event):void{
        if(this.key == "l"){
            lPressed = false;
        } else if(this.key == "r"){
            rPressed = false;
     
        } else if(this.key == "a"){
            aPressed = false;
     
        } else if(this.key == "b"){
            bPressed = false;
        }
    }


// Hero facing movements Set Hero back to
// iddle if nothings press
    function heroIddle(e:Event):void{
        if(HeroFacing=="left"){
             hero.gotoAndStop("iddleLeft");
        }
        
        if(HeroFacing=="right"){
             hero.gotoAndStop("iddleRight");
        }
    }




// Hero facing movements Set Hero Jump to
// when the jump key is pressed
    function heroJump(e:Event):void{
        if(HeroFacing=="left"){
             hero.gotoAndStop("jumpLeft");
        }
        
        if(HeroFacing=="right"){
             hero.gotoAndStop("jumpRight");
        }
    }








// --------------------------- [ MAIN LOOP ]


    stage.addEventListener(Event.ENTER_FRAME, MainLoop);
    function MainLoop(e:Event):void{


        // Placing Collision Points inside the Hero
        // Comment this block to hide them.
            this.point_L.x = hero.x + leftBumpPoint.x;
            this.point_L.y = hero.y + leftBumpPoint.y;
            
            this.point_R.x = hero.x + rightBumpPoint.x;
            this.point_R.y = hero.y + rightBumpPoint.y;
            
            this.point_U.x = hero.x + upBumpPoint.x;
            this.point_U.y = hero.y + upBumpPoint.y;
            
            this.point_D.x = hero.x + downBumpPoint.x;
            this.point_D.y = hero.y + downBumpPoint.y;
                

       
        // check for collision
             if(bg.levelCollision.hitTestPoint(hero.x + leftBumpPoint.x, hero.y + leftBumpPoint.y, true)){
                //trace("leftBumping");
                leftBumping = true;
            } else {
                leftBumping = false;
            }
             
            if(bg.levelCollision.hitTestPoint(hero.x + rightBumpPoint.x, hero.y + rightBumpPoint.y, true)){
                //trace("rightBumping");
                rightBumping = true;
            } else {
                rightBumping = false;
            }
             
            if(bg.levelCollision.hitTestPoint(hero.x + upBumpPoint.x, hero.y + upBumpPoint.y, true)){
                //trace("upBumping");
                upBumping = true;
            } else {
                upBumping = false;
            }
             
            if(bg.levelCollision.hitTestPoint(hero.x + downBumpPoint.x, hero.y + downBumpPoint.y, true)){
                //trace("downBumping");
                downBumping = true;
            } else {
                downBumping = false;
            }
            
            


     
        // character movement
            if(lPressed){
                xSpeed -= speedConstant;
                
                if(downBumping){
                     this.hero.gotoAndStop("left");
                }
                         
            } else if(rPressed){
                xSpeed += speedConstant;
                
                if(downBumping){
                     this.hero.gotoAndStop("right");
                }
            }
            
         
            if(aPressed){
                // bg.y += yScrollSpeed;
         
            } else if(bPressed){
                // bg.y -= yScrollSpeed;
            }
            
            
            
            
            
            
            // If the Hero hits a wall or platform,
            // make him bounce of it till halt.
                if(leftBumping){
                    if(xSpeed < 0){
                        xSpeed *= -0.5;
                    }
                }
         
                if(rightBumping){
                    if(xSpeed > 0){
                        xSpeed *= -0.5;
                    }
                }
                 
                if(upBumping){
                    if(ySpeed < 0){
                        ySpeed *= -0.5;
                    }
                }
                 
                if(downBumping){
                    //if we are touching the floor
                        if(ySpeed > 0){
                            ySpeed *= -0;
                            
                            // Go back to iddle mode
                            // after jumping
                                if(this.HeroFacing=="left"){
                                     this.hero.gotoAndStop("iddleLeft");
                                }
                                if(this.HeroFacing=="right"){
                                     this.hero.gotoAndStop("iddleRight");
                                }
                        }
                    
                    //and if the jump key is pressed
                        if(bPressed){
                            //set the y speed to the jump constant
                                  ySpeed = jumpConstant; 
                         }
                } else {
                    // If we are not touching the floor
                    // accelerate downwards
                         ySpeed += gravityConstant;
                        
                        // Go to jumping animation
                        // when the hero is not touching the ground.
                            if(this.HeroFacing=="left"){
                                 this.hero.gotoAndStop("jumpLeft");
                            }
                            if(this.HeroFacing=="right"){
                                 this.hero.gotoAndStop("jumpRight");
                            }
                } 
            
            
            
            // Equation to mantain a maximun speed limit
                if(xSpeed > maxSpeedConstant){ //moving right
                     xSpeed = maxSpeedConstant;
                } else if(xSpeed < (maxSpeedConstant * -1)){ //moving left
                     xSpeed = (maxSpeedConstant * -1);
                }


            // Equation to move the Hero/BG smooth
            // and stop him with friction as it goes.
                xSpeed *= frictionConstant;
                ySpeed *= frictionConstant;
                
            // Minimun Speed when it goes below 0.5
                if(Math.abs(xSpeed) < 0.5){
                    xSpeed = minSpeedConstant;
                }
            
            // Execute the moving BG/Player 
                scrollX -= xSpeed;
                scrollY -= ySpeed;
                    
                bg.x = scrollX + 0;
                bg.y = scrollY - 420;    


    }


/*
// random number generator
    function GenerateRandomNumber(limit:Number):Number {
        var randomNumber:Number = Math.floor(Math.random()*(limit+1));
        return randomNumber;
    }


    var rndnumber:Number = this.GenerateRandomNumber(6);
    trace(rndnumber);


    if (rndnumber==0){this.gotoAndPlay("a");}
    if (rndnumber==1){this.gotoAndPlay("b");}
    if (rndnumber==2){this.gotoAndPlay("c");}
    if (rndnumber==3){this.gotoAndPlay("d");}
    if (rndnumber==4){this.gotoAndPlay("e");}
    if (rndnumber==5){this.gotoAndPlay("f");}
    if (rndnumber==6){this.gotoAndPlay("g");}    
*/



stop();