# Acceleration

**URL:** <https://forum.kirupa.com/t/acceleration/11291>\
**Category:** programming\
**Created:** [January 15, 2003, 2:23am UTC](https://forum.kirupa.com/t/acceleration/11291 "2003-01-15T02:23:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NaliWarCow](https://avatars.discourse-cdn.com/v4/letter/n/57b2e6/32.png) [@NaliWarCow](https://forum.kirupa.com/u/NaliWarCow)\
**Post date:** [January 15, 2003, 2:23am UTC](https://forum.kirupa.com/t/acceleration/11291/1 "2003-01-15T02:23:27Z")

</div>

I was doing the actionscript tutorial with the beetle and using key’s to make it move in different directions. And I thought I’d try to add some acceleration to it. Well, the only way i knew how to do that was to make the movement exponential instead of just linear. I wrote this code myself, and well I’m a total n00b at actionscript, so sorry if its hideous. Here is what I wrote:

If (this.\_y \< -1)  
{  
on (keyPress “\<Up\>”) {  
currentY = this.\_y;  
this.\_y = currentY + .1 \* currentY;  
\_root.bug.\_rotation = 360;  
}  
on (keyPress “\<Down\>”) {  
currentY = this.\_y;  
this.\_y = currentY - .1 \* currentY;  
\_root.bug.\_rotation = 180;  
}  
}  
I thought I’d need to make it exponential only when the y was \>, \< 1, so that it wouldn’t exponentialy increase 0 (stay at 0). Yet, it gives me some hideous looking error.

Scene=Scene 1, Layer=beetle, Frame=1: Line 26: Statement must appear within on handler  
{

Scene=Scene 1, Layer=beetle, Frame=1: Line 39: ‘)’ or ‘,’ expected

Scene=Scene 1, Layer=beetle, Frame=1: Line 38: Statement must appear within on handler  
If (this.\_y

I know this method would work fairly wierd after the bug stopped moving at like x = 90, and then the key was pressed again and it starts off moving very fast. But, i couldn’t get the actual acceleration tutorial to work. Thanks for all your help guys.

Cheers,  
NaliWarCowz :trout:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 15, 2003, 2:28am UTC](https://forum.kirupa.com/t/acceleration/11291/2 "2003-01-15T02:28:33Z")

</div>

Well read your error message.

The error is happening because your if statment is confusing Flash.

You can’t have actionscript on a clip without it being inside a handler, and in this case, an on handler.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 15, 2003, 3:03am UTC](https://forum.kirupa.com/t/acceleration/11291/3 "2003-01-15T03:03:17Z")

</div>

OH, ok. Sorry, i’m a total flash n00b. So the if statements have to be inside the on(keypress) thing? Ok, i got it now. Sorry for the n00bishness.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 15, 2003, 3:11am UTC](https://forum.kirupa.com/t/acceleration/11291/4 "2003-01-15T03:11:35Z")

</div>

No problem man. I hope that solves your problem 🙂

But what I wanna know is… How are you a N00B!? You know Kirupa personally, didn’t his ability rub off on you? 😛
