A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Simple rotation

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Posts
    11

    Simple rotation

    So I've been trying to find the answer to this but I either find something too complicated or something too simple.

    I have a flash file with a circle in the middle and a button on the side.
    The circle is called "faces". On the button I currently have this:

    on (press) {
    faces._rotation += 90;
    }

    When I press the button it turns the circle 90 degrees and that works fine. But now what I want to do is have it turn smoothly. Right now when I press the button it jumps to the next position. I'd rather have it move in increments of 5 until it turns 90 degrees. (And if you press it again I want it to go to 180, then 270, etc etc.)

    It seems like it should be very simple but as I said, I keep either finding what I already know how to do or find something extremely complicated.

  2. #2
    Junior Member
    Join Date
    Nov 2009
    Posts
    28
    I dont know alot about the as2 syntax or definition dictonary but i know as3 has a tween class so i would assume you could use that and tween the movement. Thats for you to find out if its valid in as2.

    Not to worry though, this isnt a waistfull post. Ill show you how to do it another way though.

    Put this on your button

    on (press) {
    rotateFace = true
    }

    on the main timeline you will need this

    rotateFace:boolean = false
    nextValue:int = 90

    onEnterframe {
    if (rotateFace = true) {
    rotateFunction ()
    }
    }

    function rotateFunction {
    if(faces._rotation != nextValue) {
    faces._rotation = faces._rotation + 5
    } else {
    rotateFace = false
    nextValue = nextValue + 90
    if ( nextValue = 360){
    nextValue = 0
    }
    }
    }



    Its pretty simple to understand, if you cant break it down your self let me know and ill document it. I just wrote that up quickly so you better make sure the syntax is corrent and i havent miss spelt any of it.

  3. #3
    Junior Member
    Join Date
    Apr 2009
    Posts
    11
    Thanks I got a bit busy there for awhile.

    Anyway, I tried the code and it gave me a few errors on the timeline part, so I was fixing it up. Now I have this:

    rotateFace:boolean = false;
    nextValue:int = 90;

    onEnterframe {
    if (rotateFace = true) {
    rotateFunction ()
    }
    }

    function rotateFunction () {
    if (faces._rotation != nextValue) {
    faces._rotation = faces._rotation + 5
    } else {
    rotateFace = false
    nextValue = nextValue + 90
    if ( nextValue = 360){
    nextValue = 0
    }
    }
    }


    But it keeps giving me this error:
    Scene=Scene 1, Layer=BUTTON, Frame=1: Line 4: ';' expected
    onEnterframe {

  4. #4
    Member
    Join Date
    Jun 2004
    Posts
    83
    AS1 syntax is:

    onClipEvent(enterFrame){
    }

  5. #5
    Junior Member
    Join Date
    Apr 2009
    Posts
    11
    Ok, now I have

    rotateFace:boolean = false;
    nextValue:int = 90;

    onClipEvent (enterFrame) {
    if (rotateFace=true) {
    rotateFunction();
    }

    }


    function rotateFunction () {
    if (faces._rotation != nextValue) {
    faces._rotation = faces._rotation+5;
    } else {
    rotateFace = false;
    nextValue = nextValue+90;
    if (nextValue=360) {
    nextValue = 0;
    }
    }
    }


    It's giving me error: Scene=Scene 1, Layer=BUTTON, Frame=1: Line 4: Clip events are permitted only for movie clip instances
    onClipEvent (enterFrame) {



    I tried a few different things but none of them worked so I changed it back to what I have above. So close yet so far.

  6. #6
    Member
    Join Date
    Jun 2004
    Posts
    83
    This error message is telling you that for AS1, the portion of your code containing the onClipEvent event code (in bold) is put on the movie clip instance, not the timelime where the rest should be put. This can be subtle for a newbie, but in other words- first select the individual movie clip instance, then in the action window, enter the code in bold. Similarly, any buttons which require on(){} event code to be put on the button instances not the timeline. All other code (besides onClipEvent(){} code- you should select a frame in the timeline window, to place it on the timeline i.e. the frame).

    onClipEvent (enterFrame) {
    if (rotateFace=true) {
    rotateFunction();
    }

  7. #7
    Junior Member
    Join Date
    Apr 2009
    Posts
    11
    One of the things I tried was moving the code to the movie clip.

    So on the button I have:
    on (press) {
    rotateFace = true;
    }


    On the timeline I have:
    rotateFace:boolean = false;
    nextValue:int = 90;
    function rotateFunction () {
    if (faces._rotation != nextValue) {
    faces._rotation = faces._rotation+5;
    } else {
    rotateFace = false;
    nextValue = nextValue+90;
    if (nextValue=360) {
    nextValue = 0;
    }
    }
    }


    And on the movie I have:
    onClipEvent (enterFrame) {
    if (rotateFace=true) {
    rotateFunction();
    }
    }


    It doesn't give me any errors that way, but when I test the scene it doesn't do anything.

  8. #8
    Junior Member
    Join Date
    Nov 2009
    Posts
    28
    Im sorry mate, i never learned as2. I only just started using flash and actionscript my self and i decided to jump straight into as3 and so i had no idea how different the syntax was, and lets just say its very different. But never the less, i have fixed it and done it all in as2. And let me just say, never again.

    Alright, here is what you need to do.
    Start a new file.
    Create a new button and you can call it what ever you want.
    Place it on stage
    Change its instance name to "faces"
    Open the actions for this button and add
    Code:
    on (press) {
    	// It turns our switch on
    _root.rotateFace = 1
    }
    }
    Now go to the first frame on the timeline and open the actions
    Add this code
    Code:
    // I use this like a light switch, 0 = off, 1 = on
    rotateFace = 0;
    // Pretty simple, this is used in out code to check to see
    // what the next point we want to rotate it.
    nextPoint = 90;
    //This is the function that does it all.
    function rotateFunction() {
    	//If the rotation is not equal to the next point
    	if (faces._rotation != nextPoint) {
    		// Rotate the face. It checks its current rotation and adds 5
    		faces._rotation = faces._rotation+5;
    	} else {
    		// Elses work if the first argument is not true
    		// This resets our switch so the face stops rotating
    		rotateFace = 0;
    		// This updates the next point so next time we know
    		nextPoint = nextPoint+90;
    		// Flash is stupid and works 0 to 180 and then it jumps over to
    		// -180 and works back to 0. I dont know why but this fixes that issue
    		// Once we get to 180 and the next point is updated it +90
    		// And so it would equal 270, we just change it -90 scince thats what we want
    		if (nextPoint == 270) {
    			nextPoint = -90;
    		}
    	}
    }
    
    onEnterFrame = function () {
    	// If the switch is on "1" run the function
    	if (rotateFace == 1) {
    		rotateFunction();
    	}
    };
    And that is it, it works on my pc so it should work on yours., Let me know if this is what you were after.

  9. #9
    Junior Member
    Join Date
    Apr 2009
    Posts
    11
    I can't believe it still won't work.

    I thought maybe I had some little error somewhere in that file, so I made a whole new file and started over to see if I could get it to work. Same instance name and all. I can't see any reason why it won't work, it just doesn't.

    I uploaded my file because maybe someone can see some dumb mistake I've made.

    http://www.yousendit.com/download/MV...NEhBNkYzZUE9PQ

    (The movie clip is just the smiley faces. I know supposedly they'll turn unevenly but I'm not too worried about that right now. They aren't what I plan on actually using.)

  10. #10
    Junior Member
    Join Date
    Nov 2009
    Posts
    28
    Ok well here is the problem, i was unaware that flash 5 did not use as2, im not sure if as even understands half the code i gave you. Sorry mate im only new to this as well, i wouldnt have known. So i cant help you unless you upgrade.
    You will need flash version of 6 or higher to use the code. And it does work, i tested your file in as2 format and it all good.

    You are going to need someone with as1 experiance.

  11. #11
    Junior Member
    Join Date
    Apr 2009
    Posts
    11
    Ok, because I was having problems with Flash 5 I finally gave up and found a copy of Flash 8. I'm not sure if Flash 8 works with AS2 though? I've only been using it a couple of minutes and that code didn't work.

    I'll probably fiddle with it some more.

  12. #12
    Junior Member
    Join Date
    Nov 2009
    Posts
    28
    Yes flash 8 works with as2. And yes the code works. Do you know of any free, not requiring a sign up site that allows you to upload files to be downloaded? If so ill give you my copy and you can compair.

  13. #13
    Junior Member
    Join Date
    Apr 2009
    Posts
    11
    Megaupload or Yousendit would both probably work fine. Flash 8 looks different in a few ways so I'm not very used to the layout yet. I need to set it up how I like it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center