A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: I just want to rotate it

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    4

    Unhappy I just want to rotate it

    I just want to have a mc rotate when the mouse goes over and stop when it goes out. Right now I'm just working on it going over and it goes to the right and to the right and it's not repeating. What am I doing wrong. PLEEEAASSEEEE HELPPP.

    stop();

    var angle:Number = 0;
    var radius:Number = 150;
    var angleChange:Number = 10;
    rotateButton_mc.x = 393.9;
    rotateButton_mc.y = 218.6;

    home_btn.addEventListener(MouseEvent.ROLL_OVER, over);

    function over(evt:Event):void
    {
    var radian:Number = deg2rad(angle);
    rotateButton_mc.x = rotateButton_mc.x + radius * Math.cos(radian);
    rotateButton_mc.y = rotateButton_mc.y + radius * Math.sin(radian)
    angle += angleChange;
    angle %= 360;

    }
    function deg2rad(deg:Number):Number
    {
    return deg * (Math.PI/180)
    }

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    You need to have the loop continually play until the mouseout event occurs. You could try either a stage eventListener onEnterFrame or home_btn eventListener onEnterFrame. Make sure to remove the listener on the mouseout otherwise it will continue regardless.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Member
    Join Date
    May 2009
    Posts
    30
    Jst Use The Transform Tool!

  4. #4
    Junior Member
    Join Date
    May 2009
    Posts
    4

    I kind of fixed it!

    I got it to do what I want, but if you roll over the button enough times it bugs out and spins when it should just snap back and stop. Is there something wrong with my math somewhere.. please help. I almost got it. Is there a way to add elastic when it returns or no?

    stop();

    var over:Boolean = false;
    var angle:Number = 0;
    var angleChange:Number = 10;

    home_btn.addEventListener(MouseEvent.ROLL_OVER, onOver, false, 0, true);
    home_btn.addEventListener(MouseEvent.ROLL_OUT, onOut, false, 0, true);
    addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);


    function onLoop(evt:Event):void
    {
    if (over)
    {
    angle += angleChange;
    angle %= 360;
    rotateButton_mc.rotation = angle;
    }
    }


    function onOver(evt:MouseEvent):void {
    over = true;
    }

    function onOut(evt:MouseEvent):void {
    over = false;
    addEventListener(Event.ENTER_FRAME, outLoop, false, 0, true);
    function outLoop(evt:Event):void
    {
    angle -= angleChange;
    angle %= 360;
    rotateButton_mc.rotation = angle;
    if (angle == 0)
    {
    removeEventListener(Event.ENTER_FRAME, outLoop);
    }
    }
    }

  5. #5
    Member
    Join Date
    May 2009
    Posts
    30

    Red face Send Me The .fla File

    Cn U Jst Snd Me The Fla File And Then I Can Have A Look

  6. #6
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Try this, I've updated your code a little. You were on the right track, just needed to group two actions. Good work.
    Code:
    var over:Boolean = false;
    var angle:Number = 0;
    var angleChange:Number = 10;
    
    home_btn.addEventListener(MouseEvent.ROLL_OVER, onOver, false, 0, true);
    home_btn.addEventListener(MouseEvent.ROLL_OUT, onOut, false, 0, true);
    addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
    
    
    function onLoop(evt:Event):void
    {
    	if (over)
    	{
    		angle += angleChange;
    		angle %= 360;
    		rotateButton_mc.rotation = angle;
    	}
    	else
    	{
    		if(angle != 0)
    		{
    			angle -= angleChange;
    			angle %= 360;
    			rotateButton_mc.rotation = angle;
    		}
    		
    	}
    }
    
    
    function onOver(evt:MouseEvent):void 
    {
    	over = true;
    }
    
    function onOut(evt:MouseEvent):void 
    {
    	over = false;
    }
    I used what you had, but just moved it around. It was the second onEnterFrame listener that was causing you your problem.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  7. #7
    Junior Member
    Join Date
    May 2009
    Posts
    4

    THank You

    That worked great, thanks so much. unfortunately, that wasn't the end to what I wanted to do. I am trying to make it slightly trail and blur.... This is what I have so far and it says I'm missing some bracket, but I don't see it.
    If you guys can help I'd appreciate it, this is my first flash project, but I don't want to cheese out, I want to learn it full force....thanks guys. Fred.

    stop();

    var over:Boolean = false;
    var angle:int = 0;
    var angleChange:int = 10;
    var imageRequest:URLRequest = new URLRequest("recentWork.swf");
    var imageLoader:Loader = new Loader();
    var timer:Timer = new Timer(100,400000);



    home_btn.addEventListener(MouseEvent.ROLL_OVER, onOver, false, 0, true);
    home_btn.addEventListener(MouseEvent.ROLL_OUT, onOut, false, 0, true);
    addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
    timer.addEventListener (TimerEvent.TIMER, createButtonTrail);


    function onLoop(evt:Event):void
    {
    if (over)
    {
    timer.start ();
    angle += angleChange;
    angle %= 360;
    rotateButton_mc.rotation = angle;
    function createTrailButton (evt:Event):void
    {

    var trailButton:rotateButtons = new rotateButtons();
    trailButton.x = rotateButton_mc.x;
    trailButton.y = rotateButton_mc.y;

    trailButton.addEventListener (Event.ENTER_FRAME,animateTrailButton);

    addChildAt (trailButton,0);
    }

    function animateTrailButton (evt:Event):void;
    {
    evt.target.alpha -= 0.04;


    if (evt.target.alpha < 0)
    {
    evt.target.removeEventListener (Event.ENTER_FRAME,animateTrailButton);
    removeChild ((MovieClip)(evt.target));
    }
    }
    else
    {
    if(angle != 0)
    {
    angle -= angleChange;
    angle %= 360;
    rotateButton_mc.rotation = angle;
    }

    }
    }

    function onOver(evt:MouseEvent):void
    {
    over = true;
    }

    function onOut(evt:MouseEvent):void
    {
    over = false;
    }

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