Skip to main content
Participant
August 8, 2013
Answered

How can I make him fall if the up key isn't being held? AS2?

  • August 8, 2013
  • 1 reply
  • 435 views

Here is the code of my guy that will jump and (even if you let go of the key) will fall down after a certain period of air time.

if(Key.isDown(Key.UP))
{
jumping_var = true
}
if (jumping_var == true)
{
this._y +=jumpSpeed_var;
jumpSpeed_var +=1;
if (this._y >=300)
{
jumping_var = false;
jumpSpeed_var = -20;
}

How can I increment it so that when you let go of the key he starts too fall?
I tried by using if(!Key.isDown(Key.UP)) but that didn't work.. Please help

Also I am having a moving movieClip in the back and want it to keep rolling through, how can i get it to keep attaching (I tried resetting i to 0 but wasnt working for me, id rather no have (i=o;i<1000000;i++)

for(i=0;i<2;i++){

          _root.attachMovie("ground","mc_ground" + i, _root.getNextHighestDepth())

          _root["mc_ground"+i]._y = 400

          _root["mc_ground"+i]._x = i*1132

          _root["mc_ground"+i].onEnterFrame = function(){

                    this._x -= groundSpeed_var;

                    if(this._x < -1*1000){

                              removeMovieClip(this)

  ****(TRIED i=0)

                    }

  ****(TRIED if(i >=1)  i=0)

          }

}

let me know if im not clear, usually the case

This topic has been closed for replies.
Correct answer kglad

you need a loop (enterframe or setinterval) to start executing when Key.UP is up

var lo:Object={};

lo.onKeyUp = function() {

if(Key.getCode()==Key.UP){

// start your loop

}

};

Key.addListener(lo);

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 8, 2013

you need a loop (enterframe or setinterval) to start executing when Key.UP is up

var lo:Object={};

lo.onKeyUp = function() {

if(Key.getCode()==Key.UP){

// start your loop

}

};

Key.addListener(lo);