# Rotary knob

Page 1 of 1

## 5 Replies - 6979 Views - Last Post: 30 May 2012 - 05:14 AM

### #1 booleanops

Reputation: 2
• Posts: 24
• Joined: 18-June 09

# Rotary knob

Posted 22 April 2010 - 12:23 PM

Does anyone have code, point in the right direction, or know where I can find a tutorial on making (faking) a rotary knob in AS3?

~boo
Is This A Good Question/Topic? 0

## Replies To: Rotary knob

### #2 W3bDev

• D.I.C Regular

Reputation: 42
• Posts: 379
• Joined: 15-March 09

## Re: Rotary knob

Posted 22 April 2010 - 12:42 PM

Not hard to do... create a movieclip of the knob you want to use, then you can rotate it based on whatever interactivity you desire. Maybe you have little dots at different points, or lines, representing a stove... you can target the movieclip to rotate to that point via the rotate property. Show some effort with writing some code.

### #3 booleanops

Reputation: 2
• Posts: 24
• Joined: 18-June 09

## Re: Rotary knob

Posted 22 April 2010 - 03:57 PM

W3bDev, thanks for the input.

I tired this once before about a year ago and got frustrated. So I am trying to start anew with a fresh head. No problem showing code when I get something functional.

Your approach sounds less complex than my previous attempt.

### #4 lost child

Reputation: 2
• Posts: 18
• Joined: 01-March 08

## Re: Rotary knob

Posted 22 April 2010 - 10:16 PM

Would the following be along the lines?
```[SWF(width = "640", height = "360", frameRate = "180", backgroundColor = "#FFFFFF")]
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Stage;
import flash.events.MouseEvent;
var knob:Shape = new Shape();
with(knob)
{
with (graphics)
{
beginFill(0, 1);
drawCircle(0, 0, 20);
drawCircle( -8, -8, 4);//so we ca see the rotation

};
x = y = 200;
};
function rotateStart(me:MouseEvent):void
{
with (stage)
{
removeEventListener(MouseEvent.MOUSE_DOWN, rotateStart, false);
};
};
function rotate(me:MouseEvent):void
{
knob.rotation = stage.mouseY * 2;
};
function rotateStop(me:MouseEvent):void
{
with(stage)
{
removeEventListener(MouseEvent.MOUSE_MOVE, rotate, false);
};
};
```

### #5 booleanops

Reputation: 2
• Posts: 24
• Joined: 18-June 09

## Re: Rotary knob

Posted 23 April 2010 - 04:49 AM

Yes. Thank you very much lost child.

### #6 mrtea

Reputation: 0
• Posts: 1
• Joined: 30-May 12

## Re: Rotary knob

Posted 30 May 2012 - 05:14 AM

@ lost child, thank you for your code. I made some small improvement to make the knob more natural.

```[SWF(width = "640", height = "360", frameRate = "180", backgroundColor = "#FFFFFF")]
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Stage;
import flash.events.MouseEvent;
var knob:Shape = new Shape();
with(knob)
{
with (graphics)
{
beginFill(0, 1);
drawCircle(0, 0, 20);
drawCircle( -10, 0, 4);//so we ca see the rotation

};
x = y = 200;
};
function rotateStart(me:MouseEvent):void
{
with (stage)
{
removeEventListener(MouseEvent.MOUSE_DOWN, rotateStart, false);
};
};
function rotate(me:MouseEvent):void
{
knob.rotation = -((Math.floor(180*Math.atan2(stage.mouseX-knob.x,stage.mouseY-knob.y)/Math.PI)+90));
};
function rotateStop(me:MouseEvent):void
{
with(stage)
{
removeEventListener(MouseEvent.MOUSE_MOVE, rotate, false);