A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: AS2-Help with rotating circular menu

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    4

    Unhappy AS2-Help with rotating circular menu

    Hi there, with help from a few tutorials, I've made a menu with 5 buttons that rotate around a central Clip. So far so good.

    Except I need to add an arrow that will point toward the center whenever a button is activated. Kind of like a tooltip with a compass in it... Much like picture below:



    Everything is AS2 with no animation on the timeline. I've been stuck on this for days Firstly, I'm having a hard time to get this arrow mc to rotate on a SMALLER trajectory than my five buttons. Secondly, I cannot get the arrow mc to rotate on itself 360° while it goes around it's trajectory. And finally, I'm not sure if I need 5 arrow mc (one for each button), of if a single mc could be triggered to appear next to whichever button is being called for.

    So I would really appreciate any suggestions as to how I might fix my code (AS2) and get the lightning to position itself where it must be. Thanks!

    Actionscript Code:
    var rotX:Number = 290;
    var rotY:Number = 140;
    var Centre:Number = Stage.height/2;
    var vitesse:Number = 0.1;
    var sceneW:Number =Stage.width;
    var sceneH:Number = Stage.height;
    var nbI:Number=5;
    var angle:Number=1;
    var i:Number;

    var lightning:MovieClip = this.attachMovie("arrow", "arrow", 1000);
    arrow._alpha = 0;

    var videostopped:Boolean = false;

    for(i=0;i<nbI;i++)
    {
       //_____________________
       var button:MovieClip = this.attachMovie('Icone'+i,'Ic'+i,i);

       //_____________________
       button.onRelease= onRelease;
       button.onRollOut = onRollOut;
       button.onRollOver = onRollOver;
    }

    function onRollOver():Void {   
       lightning._alpha = 100;
       videostopped = true;
    }

    function onRollOut():Void {
       lightning._alpha = 0;
       videostopped = false;
    }

    onEnterFrame=function(){
       
        if (!videostopped) {
             //_____
         if (angle > (2*Math.PI))
         {
             angle = 0;
         }else{          
            for(i=0; i<nbI; i++){

                //_____________________angle on x axis
                this['Ic'+i]._x=rotX*Math.cos(angle+2*Math.PI*i/nbI)+sceneW/2;
               
                //_____________________angle on y axis
                this['Ic'+i]._y=rotY*Math.sin(angle+2*Math.PI*i/nbI)+sceneH/2;
               
                //_____________________Speed
                    angle=angle+(sceneW/180)/sceneH*vitesse;
                        }
                        }
    }
    }

  2. #2
    Bacon-wrapped closures Nialsh's Avatar
    Join Date
    Dec 2003
    Location
    Houston!
    Posts
    338
    Yeah, you can get away with just one arrow. Here's some code off the top of my head.

    Code:
    function onRollOver():Void {   
       lightning._alpha = 100;
       videostopped = true;
    
       var theta:Number = Math.atan2(this._x-sceneH/2, this._y-sceneW/2);
       lightning._x = rotX/2 * Math.cos(theta);
       lightning._y = rotY/2 * Math.sin(theta);
    
       // maybe add or subtract 90 degrees to make it look right
       lightning._rotation = theta*180/Math.PI;
    }
    I use arctangent to get the angle between the button and the center of the screen.

  3. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    4
    thanks, I'll try that later today and let you know how it goes!

  4. #4
    Junior Member
    Join Date
    Apr 2010
    Posts
    4

    Unhappy

    Somehow the lightning still appears in the top left corner of my scene. I can't say that I understand what Math.atan2 does very well, but at the moment, it doesn't seem to affect my movie clip. I"ll try to change things a bit.

    Here's a link to the fla in case one of you can spot any mistakes.
    http://idisk.mac.com/animationap//Pu...nce_06.fla.zip

    Thanks!

  5. #5
    Bacon-wrapped closures Nialsh's Avatar
    Join Date
    Dec 2003
    Location
    Houston!
    Posts
    338
    Here you go. I fixed that other code but decided it was the wrong approach, so here's another take.
    Code:
    function onRollOver():Void {
    	lightning._alpha = 100;	
    	videostopped = true;
    	var xOffset = this._x - sceneW/2;
    	var yOffset = this._y - sceneH/2;
    	var q:Number = .3;
    	lightning._x = q*xOffset + sceneW/2;
    	lightning._y = q*yOffset + sceneH/2;
    	lightning._rotation = Math.atan2(yOffset, xOffset)*180/Math.PI;
    }
    The lightning still lands wrong in some places... it wouldn't be a problem if your signs were elliptical. But it will look better if you at least center up the green sign.

    -Neal

  6. #6
    Junior Member
    Join Date
    Apr 2010
    Posts
    4
    Wow! Thanks a lot! You just saved my weekend. I was about to post to let you know that I had fixed the position horizontally, but that it didn't work vertically.

    But your code works in all direction!

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