Moving an object with the arrow keys in Actionscript 2 is a piece of cake compared to other languages like Java. In fact, the descriptive nature of AS2 code pretty much speaks for itself.
var speed = 5;
this.onEnterFrame = function(){
if(Key.isDown(Key.UP)){
spider_mc.play();
spider_mc._y -= speed;
}
if(Key.isDown(Key.DOWN)){
spider_mc.play();
spider_mc._y += speed;
}
if(Key.isDown(Key.LEFT)){
spider_mc.play();
spider_mc._x -= speed;
}
if(Key.isDown(Key.RIGHT)){
spider_mc.play();
spider_mc._x += speed;
}
}
In the example above we have a movie clip called spider_mc. Every time the example enters a new frame (30 times per second) we check to see if one of the arrow keys is being pressed. If, for example, the UP key is being pressed we subtract 5 (indicated by the variable speed) from the spiders y position. We also tell the spider_mc movie clip to play it's walking animation. It is necessary to put a stop() action on the spider_mc movie clip so that the walking animation does not play when the spider is still.





