A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] Dynamic Rotation

  1. #1
    Junior Member
    Join Date
    May 2008
    Posts
    5

    resolved [RESOLVED] Dynamic Rotation

    What I am have trouble with is rotating the the labels so that the 0 is where the 1000 (counter clockwise) is if you publish this file as is. The issue is the objects reg point is in the top left and when I rotate it it goes off the screen. The registration point needs to be in the center. I tried loading the labels in a empty movie clip from the libary with the registration point in the center but I could not get it to work. I know it needs to be centered and I can take it from there. Any help with this is greatly apperciated.

    The file name is MyGauge.as

    The Document Class name is MyGauge

    Here is the code:


    package {
    import flash.display.*;
    import flash.text.*;
    import flash.events.*;
    public class MyGauge extends Sprite {
    public function MyGauge(){

    drawOutterLabels();
    }
    public function drawOutterLabels():void {
    for (var i:Number=0; i <= 10; i++) {
    // Creates a new TextField showing the Psi number
    var outterLabel:TextField=new TextField;
    var textLabel:Number=0;
    textLabel=i*100;
    //innerLabel.text=i.toString();
    outterLabel.text=textLabel.toString();
    // Places PSI labels around the gauge face.
    // The sin() and cos() functions both operate on angles in radians.
    var angleInRadians:Number=i * 26 * Math.PI / 180;
    // Place the label using the sin() and cos() functions to get the x,y coordinates.
    // The multiplier value of 0.9 puts the labels inside the outline of the gauge face.
    // The integer value at the end of the equation adjusts the label position,
    // since the x,y coordinate is in the upper left corner.
    outterLabel.x=178 + 0.9 * 180 * Math.sin(angleInRadians) - 5;
    outterLabel.y=295 - 0.9 * 180 * Math.cos(angleInRadians) - 9;

    // Formats the label text.
    var tf:TextFormat=new TextFormat;
    tf.font="Arial";
    tf.bold="true";
    tf.size=12;
    outterLabel.setTextFormat(tf);
    // Adds the label to the gauge face display list.
    addChild(outterLabel);
    }
    }
    }
    }

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    May 2008
    Posts
    5
    When I followed your link I then did the code there and when I published it put all the labels on top of each other.

  4. #4
    Junior Member
    Join Date
    May 2008
    Posts
    5
    var degShift:Number=0;
    degShift=(i*28) -45;
    //var angleInRadians:Number=i * 26 * Math.PI / 180;
    var angleInRadians:Number=degShift * Math.PI / 180;

    outterLabel.x=175 + 0.9 * -180 * Math.cos(angleInRadians) - 5;
    outterLabel.y=295 - 0.9 * 180 * Math.sin(angleInRadians) - 9;

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