Knob

Code Actionscript 2.0

Instance action

on (press) {
mousepressed = 1;
}
on (release, releaseOutside) {
mousepressed = 0;
}
onClipEvent (enterFrame) {
dx = _root._xmouse - this._x;
dy = _root._ymouse - this._y;
angle = Math.atan2(dy , dx) * 180 / Math.PI;
if (mousepressed == 1) {
this._rotation = angle;
_root.target._y = 110 + angle;
}
}

Code Actionscript 3.0

addEventListener(Event.ENTER_FRAME, enterFrame); addEventListener(MouseEvent.MOUSE_UP, releaseOutside); square.addEventListener(MouseEvent.MOUSE_DOWN, press); square.addEventListener(MouseEvent.MOUSE_UP, release); var mousepressed = 0; function press(e:MouseEvent) { mousepressed = 1; } function release(e:MouseEvent){ mousepressed = 0; } function releaseOutside(e:MouseEvent) { mousepressed = 0; } function enterFrame(event:Event) { var dx = mouseX - square.x; var dy = mouseY - square.y; var angle = Math.atan2(dy, dx) * 180 / Math.PI ; if (mousepressed == 1) { square.rotation = angle; this.target.y = 200+angle ; } }

Description

When the knob is pressed, its degree of rotation is dependent on the angle of the mouse. The angle is calculated with the function arctangent (atan2) from the x and y-coordinates relative to the knob. This angle is also used to modify the vertical positioning of the square.

related to: Mouse rotation

Download

Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File


Share