# Rotation

**URL:** https://forum.kirupa.com/t/rotation/2900
**Category:** flash
**Created:** [February 26, 2002, 2:03am UTC](https://forum.kirupa.com/t/rotation/2900 "2002-02-26T02:03:11Z")
**Posts on this page:** 20
**Page:** 1

<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: [February 26, 2002, 2:03am UTC](https://forum.kirupa.com/t/rotation/2900/1 "2002-02-26T02:03:11Z")

</div>

can i rotate a MC like a motion tween, but without the motion tween? i want to press a button and the MC will rotate 360 degrees…

---

<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: [February 26, 2002, 7:15am UTC](https://forum.kirupa.com/t/rotation/2900/2 "2002-02-26T07:15:07Z")

</div>

Course you can !! That’s called Actionscript, baby. You can write that code in the Actions of your movie clip :

```auto
 onClipEvent (load) {\r\r rotate = 0 ;\r\r amount = 5 ;//this will make the clip move by 5 degrees on each frame\r\r}\r\ronClipEvent (enterFrame) {\r\r this._rotation = rotate*amount ;\r\r rotate++ ;\r\r}

```

Get it ? I’m sure you do.\rpom 0]

---

<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: [February 26, 2002, 7:30am UTC](https://forum.kirupa.com/t/rotation/2900/3 "2002-02-26T07:30:04Z")

</div>

Crap… I know how to do this, but I can’t seem to figure it out at the moment… I WAS looking for a past post where Supra and I hammered this out, but I can’t seem to find it. I’m looking through my notes.

---

<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: [February 26, 2002, 7:31am UTC](https://forum.kirupa.com/t/rotation/2900/4 "2002-02-26T07:31:50Z")

</div>

Thanks POM… I’m slapping myself in the head. I thought that the question was, how do I rotate it ONLY 360 degrees and then stop… I had all this wacky code writen out… I’m a fool sometimes, I didn’t need half of what I had. 🙂

---

<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: [February 26, 2002, 12:17pm UTC](https://forum.kirupa.com/t/rotation/2900/5 "2002-02-26T12:17:02Z")

</div>

thanks guys.

---

<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: [February 26, 2002, 2:30pm UTC](https://forum.kirupa.com/t/rotation/2900/6 "2002-02-26T14:30:50Z")

</div>

that worked good, but how can i get a button to initiate that action, and then have it stop? could i just use if statements?\r\rI GOT IT TO START! NOW HOW DO I MAKE IT STOP??? lol…ok say i only want it to rotate for 360 degrees, and then stop? can i just use an if statement for that?

---

<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: [February 26, 2002, 3:56pm UTC](https://forum.kirupa.com/t/rotation/2900/7 "2002-02-26T15:56:38Z")

</div>

name the movie clip something in the instance panel.\r\ronClipEvent (enterFrame) {\r if (flag==true){\r rotate++;\r }\r}\r\rCreate a button with the following a/s\r\ron(release){\r if (\_root.myMovieClipName.flag==false){\r \_root.myMovieClipName.flag=true;\r }else{\r \_root.myMovieClipName.flag=false;\r}

---

<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: [February 26, 2002, 4:03pm UTC](https://forum.kirupa.com/t/rotation/2900/8 "2002-02-26T16:03:06Z")

</div>

hmmm that’s not working right… hold on

---

<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: [February 26, 2002, 4:09pm UTC](https://forum.kirupa.com/t/rotation/2900/9 "2002-02-26T16:09:23Z")

</div>

ok got it\r\rbutton has this a/s\r\ron (release) {\r&nbsp &nbsp &nbsp &nbsp if (flag==false) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp \_root.rotator.rot=5;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp flag=true;\r&nbsp &nbsp &nbsp &nbsp }else{\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp \_root.rotator.rot=0;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp flag=false;\r&nbsp &nbsp &nbsp &nbsp }\r}\r\r\rMovie clip has this a/s and an instance name of “rotator”\r\ronClipEvent (load){\r&nbsp &nbsp &nbsp &nbsp rot=5;\r}\ronClipEvent (enterFrame) {\r&nbsp &nbsp &nbsp &nbsp \_rotation+=rot;\r}

---

<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: [February 26, 2002, 4:57pm UTC](https://forum.kirupa.com/t/rotation/2900/10 "2002-02-26T16:57:09Z")

</div>

I didn’t look at Upu’s code but if you use mine, you’ll just have to add a few lines:

```auto
  onClipEvent (load) {\r\r rotate = 0 ;\r\r amount = 5 ;//this will make the clip move by 5 degrees on each frame\r\r}\r\ronClipEvent (enterFrame) {\r\rif (rotate < 360/amount) {\r\r this._rotation = rotate*amount ;\r\r rotate++ ;\r\r }\r\r}

```

pom 0] \rPS:no button involved in that script.

---

<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: [February 26, 2002, 5:47pm UTC](https://forum.kirupa.com/t/rotation/2900/11 "2002-02-26T17:47:39Z")

</div>

ok, had to put in my two cents…\r\rmake a button:

```auto
 \r\ron(release){\r\r&nbsp &nbsp &nbsp &nbsp mpress = !mpress;\r\r}

```

\r\rmake that button a movie:

```auto
 \r\ronClipEvent (enterFrame) {\r\r&nbsp &nbsp &nbsp &nbsp if(mpress){\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _rotation += 5;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp if(_rotation == 0) mpress = 0;\r\r&nbsp &nbsp &nbsp &nbsp }\r\r}

```

\r\rwhatever your +=ing by must be a factor of 360, otherwise it won’t equal 0 when it gets around.

---

<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: [February 26, 2002, 10:36pm UTC](https://forum.kirupa.com/t/rotation/2900/12 "2002-02-26T22:36:07Z")

</div>

You said

```auto
 on(release){\r\r mpress = !mpress;\r\r}

```

and then

```auto
 onClipEvent (enterFrame) {\r\r if(mpress){...

```

How does Flash handle that ? I mean, mpress is never initialized. Unless variables are automatically set to 0 by default. But I don’t think so, since I’ve had troubles with undefined values in the past…\rpom 0]

---

<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: [February 26, 2002, 11:57pm UTC](https://forum.kirupa.com/t/rotation/2900/13 "2002-02-26T23:57:23Z")

</div>

an undefined variables will evaluate as false in actionscript (which is not quite the same as 0).\r\rother languages will balk at undefined variables, but flash is quite forgiving.

---

<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: [February 27, 2002, 4:08pm UTC](https://forum.kirupa.com/t/rotation/2900/14 "2002-02-27T16:08:21Z")

</div>

cool, okay I was would like to get it to rotate only 135 degrees how can you do that? thanks suprabeener, because I do not see anything that looks like degrees.\r\rPom, I tried your method as well but it seems to stop 355 deg not 360. did I miss something?\r\rAlso I tried to get your codes to play counter clockwise instead of clockwise. supra’s I got to work fine (don’t understand it 😉 ), Pom’s I got it to go work but could not get it to stop.\r\rAny pointers would be great, thanks,\rMatt

---

<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: [February 27, 2002, 4:37pm UTC](https://forum.kirupa.com/t/rotation/2900/15 "2002-02-27T16:37:49Z")

</div>

```auto
 \r\ronClipEvent (enterFrame) {\r\r if(mpress){\r\r // this is the speed and the direction,\r\r //subtract (-=) to go the other way\r\r _rotation += 5;\r\r // to stop at 135, make this read if(_rotation == 135)\r\r if(_rotation == 0) mpress = 0;\r\r }\r\r}\r\r

```

---

<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: [February 27, 2002, 8:42pm UTC](https://forum.kirupa.com/t/rotation/2900/16 "2002-02-27T20:42:30Z")

</div>

Yeah, OK, Supra’s code is better than mine… _snif_ But still it works. That 355 degrees thing is only a matter of if test. Just replace \* rotate \<\* by \* rotate \<=\*. And to go counter clockwise, I believe that this should work :

```auto
onClipEvent (load) {\r rotate = 0 ;\r amount = 5 ;\r}\ronClipEvent (enterFrame) {\rif (rotate <= 360/amount) {\r this._rotation = - rotate*amount ;//substracting instead of adding\r rotate++ ;\r }\r}

```

\rBut Supra’s script is better, I must admit. Wait a minute, I’ll find the ultimate simplest script.\r\rpom 0]

---

<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: [February 27, 2002, 9:31pm UTC](https://forum.kirupa.com/t/rotation/2900/17 "2002-02-27T21:31:11Z")

</div>

Okay, it works when I stop at 135 with this code\r\rif (\_rotation == 135) mpress = 0;\r\rbut when I change it to this it does not work, it keeps playing.\r\rif (\_rotation == 235) mpress = 0;\r\rI have tried to get it to rotate 360+45 degress and that does not work\rif (\_rotation == 360+45) mpress = 0;\rbut this does.\rif (\_rotation == 45+35) mpress = 0;\r\rI am just playing around trying to get a better understanding.\r\rWhat would be cool if I could get it to rotate 135, then rotate -90, then 135, then -90 until I get to 360 total kinda of three steps forward then two steps back type of thing.\r\rThanks for the great code Suprabeener and If I am not being too anoying could you help me out? you too Pom. 😉 \r\rMatt

---

<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: [February 27, 2002, 10:08pm UTC](https://forum.kirupa.com/t/rotation/2900/18 "2002-02-27T22:08:30Z")

</div>

All you ever wanted to know about \_rotation but were afraid to ask : just change the code to :

```auto
 onClipEvent (enterFrame) {\r\r&nbsp &nbsp &nbsp &nbsp if (mpress) {\r\r&nbsp &nbsp &nbsp &nbsp trace (_rotation) ;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _rotation += 5;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp // to stop at 135, make this read if(_rotation == 135)\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp if (_rotation == 135) {\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp mpress = 0;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }\r\r&nbsp &nbsp &nbsp &nbsp }\r\r}\r\r

```

The trace (\_rotation) command will show you how Flash handles rotation : 0 to 180, then -175 to 0. That’s why \_rotation == 235 never happens. That would be \_rotation == -125.\rAbout that back and forth effect, you can get it easily with a series of flags. Give me 2 minutes.\r\rpom 0]

---

<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: [March 14, 2002, 6:52pm UTC](https://forum.kirupa.com/t/rotation/2900/19 "2002-03-14T18:52:01Z")

</div>

Hello, it has been a while since I have been on. Pom anything more on the rotation thing.\r\rNice to be back for a little bit.\r\rMatt

---

<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: [March 14, 2002, 9:47pm UTC](https://forum.kirupa.com/t/rotation/2900/20 "2002-03-14T21:47:57Z")

</div>

I don’t have the courage… Anybody ??\rpom 0]
