Hey All.. (thanks to kglad for the code about this button) I have developed my dial and the code seems to be working but I have once small problem. I have a min and max for the dial. I dont want it to go all the way around and I dont know how to prevent it from doing that. (see image below)
The Code I am using is also below. Thanks for any help.
CODE:
//Knob Testing Code
knob_mc.addEventListener(MouseEvent.MOUSE_DOWN, startTurn);
stage.addEventListener(MouseEvent.MOUSE_UP, stopTurn);
var minTemp:Number = 0;
var maxTemp:Number = 180;
paramF(knob_mc,-180,minTemp,180,maxTemp);
function startTurn(e:MouseEvent):void
{
addEventListener(Event.ENTER_FRAME, turn, false, 0, true);
}
function stopTurn(e:MouseEvent):void
{
removeEventListener(Event.ENTER_FRAME, turn);
}
function turn(e:Event):void
{
knob_mc.rotation = Math.atan2(mouseY - knob_mc.y, mouseX - knob_mc.x) / (Math.PI / 180);
knob.textInput.tempvalue.text = String(knob_mc.m * knob_mc.rotation + knob_mc.b1);
}
function paramF(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number):void
{
knob_mc.m = (y1 - y2) / (x1 - x2);
knob_mc.b1 = y1 - knob_mc.m * x1;
}
the limits depend on the orientation of your knob_mc. what's the rotation when it starts in that position?
and you messed up the code in paramF. that should be:
function paramF(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number):void
{
mc.m = (y1 - y2) / (x1 - x2);
mc.b1 = y1 - mc.m * x1;
}
you still don't understand paramF.
but you can use:
//Knob Testing Code
knob_mc.addEventListener(MouseEvent.MOUSE_DOWN, startTurn);
stage.addEventListener(MouseEvent.MOUSE_UP, stopTurn);
var angle:Number;
var minTemp:Number = 0;
var maxTemp:Number = 180;
paramF(knob_mc,-180,minTemp,180,maxTemp);
function startTurn(e:MouseEvent):void
{
addEventListener(Event.ENTER_FRAME, turn, false, 0, true);
}
function stopTurn(e:MouseEvent):void
{
removeEventListener(Event.ENTER_FRAME, turn);
}
function turn(e:Event):void
{
angle = Math.atan2(mouseY - knob_mc.y, mouseX - knob_mc.x) / (Math.PI / 180);
if(angle>=0 || angle<=-90){
knob_mc.rotation = Math.atan2(mouseY - knob_mc.y, mouseX - knob_mc.x) / (Math.PI / 180);
knob.textInput.tempvalue.text = String(knob_mc.m * knob_mc.rotation + knob_mc.b1);
}
}
function paramF(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number):void
{
mc.m = (y1 - y2) / (x1 - x2);
mc.b1 = y1 - mc.m * x1;
}
North America
Europe, Middle East and Africa
Asia Pacific