Skip to main content
Known Participant
September 12, 2012
Question

Knob Min & Max

  • September 12, 2012
  • 2 replies
  • 1013 views

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;

}

This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
September 12, 2012

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;

}

kglad
Community Expert
Community Expert
September 12, 2012

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;

}

Known Participant
September 12, 2012

It would start at 0.  How do I get that starting  position?  I am thinking I would do an if statement to check the rotation to make sure its not over or under that max and min.  right?

kglad
Community Expert
Community Expert
September 12, 2012

it's possible but i doubt that's 0.

what's the following show:

trace(knob_mc.rotation)