Skip navigation
Currently Being Moderated

Knob Min & Max

Sep 12, 2012 11:18 AM

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;

}

 

knob.fw.png

 
Replies
  • kglad
    62,165 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 12, 2012 11:21 AM   in reply to TheScarecrow

    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;

    }

     
    |
    Mark as:
  • kglad
    62,165 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 12, 2012 11:31 AM   in reply to TheScarecrow

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

     

    what's the following show:

     

    trace(knob_mc.rotation)

     
    |
    Mark as:
  • kglad
    62,165 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 12, 2012 12:25 PM   in reply to TheScarecrow

    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;

    }

     

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points