Rotation

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…

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

 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]

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.

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. :slight_smile:

thanks guys.

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?

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}

hmmm that’s not working right… hold on

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}

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

  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.

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

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

\r\rmake that button a movie:

 \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.

You said

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

and then

 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]

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.

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 :wink: ), Pom’s I got it to go work but could not get it to stop.\r\rAny pointers would be great, thanks,\rMatt

 \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

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 :

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]

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. :wink: \r\rMatt

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

 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]

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

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