Moving a movie clip via key press event question.


i have project i'm trying move movie clip: "wally", , down 3 levels of stage.

 

however, default position have him move 145 pixels, , down 120 pixels.

 

i want limit action 1 use, meaning if wally goes once default position must come down, , vice versa, if goes down must come up(or stay on level). also, if goes 145 pixels, needs come down 145 pixels, likewise if goes down 120 pixels, needs come 120 pixels. might over-thinking this, had strip starting code other day, , @ loss once more. if this'd easier performed moving keyboard arrows , case statments, let me know, i'm stumped.

 

 

starting code:

 

stage.addeventlistener(keyboardevent.key_down, keypresshandler1);

 

 

function keypresshandler1(event:keyboardevent):void

{

          if(event.keycode==38)

          {

                    wally.y -= 145;

          }

                    else if(event.keycode==40)

          {

                    wally.y += 120;

          }

}

use:

 

 

 

wally.starty = wally.y;

 

stage.addeventlistener(keyboardevent.key_down, keypresshandler1);

 

 

function keypresshandler1(event:keyboardevent):void

{

          if(event.keycode==38)

          {

if(wally.y==wally.starty){

                    wally.y -= 145;

} else if(wally.y>wally.starty){

wally.y=wally.starty

}

          }

                    else if(event.keycode==40)

          {

if(wally.y==wally.starty){

                    wally.y += 120;

} else if(wally.y<wally.starty){

wally.y=wally.starty;

}

          }

}

 

p.s. please mark helpful/correct responses.



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

Joomla 3.3 Installation Error message - Joomla! Forum - community, help and support

Multilanguage infinite redirect loop error. - Joomla! Forum - community, help and support

trim media limit reached