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

#1 booleanops  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • 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  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 42
  • View blog
  • 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.
Was This Post Helpful? 1
  • +
  • -

#3 booleanops  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#4 lost child  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • 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;	
};
addChild(knob);
stage.addEventListener(MouseEvent.MOUSE_DOWN, rotateStart, false, 0, false);
function rotateStart(me:MouseEvent):void
{
	with (stage)	
	{
		removeEventListener(MouseEvent.MOUSE_DOWN, rotateStart, false);		
		addEventListener(MouseEvent.MOUSE_UP, rotateStop, false, 0, false);		
		addEventListener(MouseEvent.MOUSE_MOVE, rotate, false, 0, false);		
	};
};
function rotate(me:MouseEvent):void
{
	knob.rotation = stage.mouseY * 2;	
};
function rotateStop(me:MouseEvent):void
{
	with(stage)
	{
		removeEventListener(MouseEvent.MOUSE_MOVE, rotate, false);		
		addEventListener(MouseEvent.MOUSE_DOWN, rotateStart, false, 0, false);		
	};
};

Was This Post Helpful? 2
  • +
  • -

#5 booleanops  Icon User is offline

  • New D.I.C Head
  • member icon

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

Re: Rotary knob

Posted 23 April 2010 - 04:49 AM

Yes. Thank you very much lost child. :clap:
Was This Post Helpful? 0
  • +
  • -

#6 mrtea  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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;   
	};
	addChild(knob);
	stage.addEventListener(MouseEvent.MOUSE_DOWN, rotateStart, false, 0, false);
	function rotateStart(me:MouseEvent):void
	{
	    with (stage)   
	    {
	        removeEventListener(MouseEvent.MOUSE_DOWN, rotateStart, false);    
	        addEventListener(MouseEvent.MOUSE_UP, rotateStop, false, 0, false);    
	        addEventListener(MouseEvent.MOUSE_MOVE, rotate, false, 0, 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);     
	        addEventListener(MouseEvent.MOUSE_DOWN, rotateStart, false, 0, false);     
	    };
	};


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1