# Advice needed on cleaning up some script

**URL:** <https://forum.kirupa.com/t/advice-needed-on-cleaning-up-some-script/281986>\
**Category:** programming\
**Created:** [February 16, 2009, 1:47pm UTC](https://forum.kirupa.com/t/advice-needed-on-cleaning-up-some-script/281986 "2009-02-16T13:47:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sapster](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sapster](https://forum.kirupa.com/u/Sapster)\
**Post date:** [February 16, 2009, 1:47pm UTC](https://forum.kirupa.com/t/advice-needed-on-cleaning-up-some-script/281986/1 "2009-02-16T13:47:02Z")

</div>

Hi, I’m a complete beginner who ventured into the world of Flash and programming only a couple of days ago and need some advice on how to clean up some as2 script I’ve put together because I haven’t been able to find tutorials on everything.

The script below does exactly what I need it to do at this stage for a one time project i.e.

1. Start an object moving in a certain direction on loading
2. Turn an object to face a certain direction and have the object move in that direction.
3. Make the movement perpetual (i.e. not reliant on continuous keystrokes or holding down a key) at a constant speed.

Apologies in advance if the following is offensive to anyone.

onClipEvent (load) {  
upmove = 0.5

}  
onClipEvent (enterFrame) {

if (Key.isDown(Key.RIGHT)) {  
this.gotoAndStop(2);  
rightmove = 0.5  
leftmove = 0  
upmove = 0  
downmove = 0

}  
else if (Key.isDown(Key.LEFT)) {  
this.gotoAndStop(4);  
leftmove = 0.5  
rightmove = 0  
upmove = 0  
downmove = 0

}  
if (Key.isDown(Key.UP)) {  
this.gotoAndStop(1);  
upmove = 0.5  
downmove = 0  
leftmove = 0  
rightmove = 0

}  
if (Key.isDown(Key.DOWN)) {  
this.gotoAndStop(3);  
downmove = 0.5  
upmove = 0  
leftmove = 0  
rightmove = 0

}  
speed = 0.5  
\_x += rightmove  
\_x -= leftmove  
\_y += downmove  
\_y -= upmove  
}

My concern is that I arrived at point 3 above by banging my head relentlessly on the keyboard and employing an army of monkeys to sit and type random monkey-babble all day long, and no doubt there is a much prettier and more efficient way of achieving the same thing. Any advice on how I might do that would be much appreciated.

Cheers.

[http://www.ezy-english.com](http://www.ezy-english.com)
