;

PDA

Click to See Complete Forum and Search --> : [RESOLVED] Dynamic Rotation


pixelmauler
05-20-2008, 03:50 PM
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);
}
}
}
}

cancerinform
05-21-2008, 06:59 AM
http://board.flashkit.com/board/showthread.php?t=736502&highlight=center+point

pixelmauler
05-21-2008, 09:11 AM
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.

pixelmauler
05-21-2008, 04:41 PM
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;