# Rotating forth/back with AS

**URL:** https://forum.kirupa.com/t/rotating-forth-back-with-as/29715
**Category:** flash
**Created:** [August 29, 2003, 5:23pm UTC](https://forum.kirupa.com/t/rotating-forth-back-with-as/29715 "2003-08-29T17:23:19Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Bacizone](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Bacizone](https://forum.kirupa.com/u/Bacizone)
#### Post date: [August 29, 2003, 5:23pm UTC](https://forum.kirupa.com/t/rotating-forth-back-with-as/29715/1 "2003-08-29T17:23:19Z")

</div>

Hi,

I am still quite new to AS. I’d like to rotate a circle (compass\_mc) around its centerpoint slowly forth/back with +/- 45 degree…or better with random degree.

As file size is important, I can not solve it with MotionTween.

Up to this time I applied this code to the MC, which endlessly rotates it:

iranytu\_mc.onEnterFrame = function(){  
this.\_rotation+=1;  
}

Do you have any idea how to apply that sort of random slow forth/back rotation to the circle with AS?

Many thanks,

Bacizone

---

<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: [August 29, 2003, 6:12pm UTC](https://forum.kirupa.com/t/rotating-forth-back-with-as/29715/2 "2003-08-29T18:12:45Z")

</div>

as a start

clip.onEnterFrame = function(){  
if(this.\_rotation\<45)  
this.\_rotation+=1;  
}

with variations on this you could have any rotation you wanted but i think the use of setInterval is better than onenterframe.

---

<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: [August 29, 2003, 6:52pm UTC](https://forum.kirupa.com/t/rotating-forth-back-with-as/29715/3 "2003-08-29T18:52:35Z")

</div>

to finish the code:

```auto

onClipEvent (load) {
	a = 3;
}
onClipEvent (enterFrame) {
	if (this._rotation<=45 && this._rotation>=-45) {
		this._rotation += a;
	} else {
		a *= -1;
		this._rotation += a;
	}
}

```

works fine - you could add a bit of easing too…

---

<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: [August 29, 2003, 7:03pm UTC](https://forum.kirupa.com/t/rotating-forth-back-with-as/29715/4 "2003-08-29T19:03:28Z")

</div>

This is also and option:

```auto

onClipEvent (enterFrame) {
	d += 0.1;
	_rotation = Math.cos(d)*20;
}

```
