# Rotation by 45 degrees each time

**URL:** <https://forum.kirupa.com/t/rotation-by-45-degrees-each-time/65198>\
**Category:** flash\
**Created:** [September 23, 2004, 9:59pm UTC](https://forum.kirupa.com/t/rotation-by-45-degrees-each-time/65198 "2004-09-23T21:59:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gt\_X\_lt](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@gt\_X\_lt](https://forum.kirupa.com/u/gt_X_lt)\
**Post date:** [September 23, 2004, 9:59pm UTC](https://forum.kirupa.com/t/rotation-by-45-degrees-each-time/65198/1 "2004-09-23T21:59:20Z")

</div>

I would like to be able to rotate a movieclip by 45 degrees each time i press left or right.

I have got this

```auto

on (keyPress "<Right>") {
 _rotation=+45
}
on (keyPress "<Left>") {
 _rotation=-45
}

```

However, this moves the movie clip to the point of 45 degrees or minus 45 degrees depending on the key pressed.

I would like to add +45 to the rotation when i press the right key and -45 when i press the left key.

What have i done wrong. Please can you help me?

---

<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:** [September 24, 2004, 1:46am UTC](https://forum.kirupa.com/t/rotation-by-45-degrees-each-time/65198/2 "2004-09-24T01:46:50Z")

</div>

+=  
-=

---

<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:** [September 24, 2004, 3:42am UTC](https://forum.kirupa.com/t/rotation-by-45-degrees-each-time/65198/3 "2004-09-24T03:42:12Z")

</div>

```auto
on (keyPress "<Right>") {
 _rotation +=45
}
on (keyPress "<Left>") {
 _rotation-=45
}

```

note tha you have placed + & = in the wrong way

---

<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:** [September 24, 2004, 8:25am UTC](https://forum.kirupa.com/t/rotation-by-45-degrees-each-time/65198/4 "2004-09-24T08:25:11Z")

</div>

Just so i fully understand.

= 45 means rotate to 45 degrees.

+= 45 Means add 45 degrees to the current rotation.  
-= 45 means minus 45 degrees to the current rotation.

---

<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:** [September 24, 2004, 11:45am UTC](https://forum.kirupa.com/t/rotation-by-45-degrees-each-time/65198/5 "2004-09-24T11:45:25Z")

</div>

Yes, ‘=’ will set a value, ‘+=’ will increase by value and ‘-=’ will decrease by value.

---

<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:** [September 24, 2004, 11:53am UTC](https://forum.kirupa.com/t/rotation-by-45-degrees-each-time/65198/6 "2004-09-24T11:53:24Z")

</div>

Just as another option (less efficient) you could also have used  
rotation = rotation+45;  
that’s the long hand for the += operator.

There are two more shorthand operators like this, the decrementation operator and incrementation operator  
variable–; //subtracts one from the variable  
vairable++; //adds one to the variable
