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
Rotary knob
Page 1 of 15 Replies - 4884 Views - Last Post: 30 May 2012 - 05:14 AM
Replies To: Rotary knob
#2
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
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.
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
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);
};
};
#5
Re: Rotary knob
Posted 23 April 2010 - 04:49 AM
Yes. Thank you very much lost child.
#6
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);
};
};
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|