A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Changing a AS objects diameter of rotation dependant on position of mouse

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

    Changing a AS objects diameter of rotation dependant on position of mouse

    Hi guys,

    This is for a personal art project, however I have hit a potential (Actionscript) brick wall!

    I want the diameter of the 'balls' orbit to change dependant on the position of the mouse but keep the point of rotation exactly the middle of the stage at all times.

    I.e. if the mouse is hovering over the exact center (both X+Y) of the stage then the 'ball' should have a tiny diameter of rotation (but contstantly follows the orbit in clockwise direction) whilst if you move the mouse towards the edge of the stage then the diameter of the orbit of the ball will increase.

    Here is the AS which controls a blank movieclip;


    var sp:Sprite = new Sprite();
    orb1.addChild(sp)
    var g: Graphics =sp.graphics
    orb1.x = (stage.mouseX);
    orb1.y = (stage.mouseY);

    g.moveTo(stage.mouseX, stage.mouseY);
    //stage.stageWidth/2,stage.stageHeight/2)
    g.lineStyle(1.5,0x000000,10);
    g.beginFill(0x000000,0.2)
    g.drawCircle(stage.mouseX,stage.mouseY,10)
    g.endFill();


    stage.addEventListener(Event.ENTER_FRAME,test)
    stop();


    function test(Evt:Event):void{
    orb1.rotation +=5;

    orb1.x = (stage.mouseX);
    orb1.y = (stage.mouseY);

    }


    If it help's, here is the .swf, .fla AND an image with an explanation:

    http://www.taylormadeclubbing.co.uk/flash/test.swf
    http://www.taylormadeclubbing.co.uk/flash/test.png
    http://www.taylormadeclubbing.co.uk/flash/test.fla

    Hope this helps!

  2. #2
    Senior Member
    Join Date
    May 2004
    Posts
    226
    There are lots of ways to do this, one easy way would be to put your orb inside another container sprite, then rotate the container and offset the location of the orb:
    PHP Code:
    var orb:Sprite = new Sprite();
    orb.graphics.lineStyle1.5,0x00000010 );
    orb.graphics.beginFill0x000000,0.2 );
    orb.graphics.drawCircle0010 );
    orb.graphics.endFill();

    var 
    orbContainer:Sprite = new Sprite();
    orbContainer.addChildorb );
    orbContainer.stage.stageWidth 2;
    orbContainer.stage.stageHeight 2;
    addChildorbContainer );

    function 
    updateOrbe:Event ):void {
        
    orbContainer.rotation += 5;
        
    //a squared plus b squared equals c squared
        
    orb.Math.sqrtMath.powstage.mouseX orbContainer.x) + Math.powstage.mouseY orbContainer.y) );
    }
    addEventListenerEvent.ENTER_FRAMEupdateOrb ); 
    Also, when posting code it really should be indented and wrapped it in a code tag.

Tags for this Thread

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