PDA

View Full Version : constrain dragging to a circular path?



d.ellington
October 4th, 2004, 02:38 PM
I am designing an interface where a person will drag a circular measurement tool (called a goniometer) over part of an image, and then rotate two different arms on the tool to measure an angle.

The entire tool itself needs to be draggable by its center. So far I have the arms rotating by means of pressing the arrow keys on the keyboard, but it would be more realistic to have the user drag the arms to rotate them. I can't think of how to accomplish that, though.

Please see this example to get an idea of what I am doing:

http://interactive.elon.edu/goniometer.html

My other question is, why is it that you have to click the mouse somewhere on the screen before the key arrows will work?

TIA!

d.ellington
October 6th, 2004, 09:11 AM
I found a solution to my problem and thought I would share it with y'all. First I had to put an invisible button on each arm with the following code:



// start rotation
on (press) {
doRotateArm1 = true;
}
// stop rotation
on (release, releaseOutside) {
doRotateArm1 = false;
}


Next each arm movie clip has the following code:



onClipEvent (load) {
doRotateArm1 = false;
}
onClipEvent (enterFrame) {
if (doRotateArm1) {
this._rotation += (Math.floor(180*Math.atan2(_ymouse, _xmouse)/Math.PI)+180);
}
}


I just changed doRotateArm1 to doRotateArm2 in order to control the second arm.

I found the code I needed on this website: http://www.sonify.org/home/feature/remixology/010_knobs/

Here is the scale in action:

http://interactive.elon.edu/goniometer.html

Jerryscript
October 7th, 2004, 11:16 AM
My other question is, why is it that you have to click the mouse somewhere on the screen before the key arrows will work?
The SWF movie needs to be selected (clicked on) before it can receive input from the user, much as a form's textfield needs to be selected before you can type in it. When the window displaying a SWF movie is opened, it often does not only contain the SWF file. Most often, it is an HTML page with the SWF movie and other objects, many of which have the ability to gain the mouse/keyboard focus (forms, images, etc). Without scripting to tell the window which item to focus on, the user must choose by clicking on an object with the mouse, or by using the tab key to move the focus from object to object.