[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do you apply droptarget feature to a rotating object?

Posted on 2010-01-06
4
Medium Priority
?
266 Views
Last Modified: 2013-11-11
I have a Flash document which is already employing drag and drop targets successfully.  However, I am having trouble getting it to work on a rotating object.
In the attached stripped-down flash document, I have a knob that rotates 360 degrees continuously by grabbing the red dot.  You will notice I have a slightly larger red dot located approx. 45 degrees to the left... that's my drop target - but I can't get it to work the same as a traditional drag type drop.
The script for the knob is located in a layer named "action script for knob" and the target is in the "drop targets" folder on a layer named "target dial".  Instance names are already in place.
The end result I'm trying achieve is: when the knob is rotated to the target, I want to pop up a movie clip that simply says "Correct".  I'll take care of the movie clip.
Any help would be greatly appreciated.

rotatingKnob.fla
0
Comment
Question by:smdevivoydocs
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:NiklasMoller
ID: 26192381
Hello!
I had a look at your file.
well correct me if I am getting this wrong... but I have a solution that might be simpler than using dropTarget.
here it goes:

- you want to say "correct" when the dial is turned to a certain angle... right?
so you can just check the rotation property of the dial Sprite/Movieclip ?

pseudo-code:
onDragRelease
    check rotation of dial
    if rotation is within acceptable range
         say "correct!"
         snap the dial to a correct exact rotaion angle.

You could store the acceptable rotation-range as two variables: min   and   max for example and check against those!

should work right?
and then you dont need to care about droptarget at all!
you with me?
0
 

Author Comment

by:smdevivoydocs
ID: 26193753
Hey... I'm easy!
If that gets the job done fine.
Now, if you could show me how to set up the Action Script, I'll be in business. I pretty much borrow/use canned scripts written by others and modify as needed, so I wouldn't know where to begin with turning your pseudo code into real live action script.
Would I still be able to fire a movie clip as well when the range of angle was reached?
Thanks for your help and this new alternative to a solution.
0
 
LVL 5

Accepted Solution

by:
NiklasMoller earned 2000 total points
ID: 26195356
ok just change the code in the "action script for knob" frame to this code below.
I have commented it alot so that you should be able to understand what is happening in there...
hope that helps!
cheers
handle.grip.onPress = function(){
	//this code happens when user presses mouse button on grip
	handle.onMouseMove = function(){
		//this code happens everytime the mouse is down, and is moved:
		//calculate angle in radians:
		var angleInRadians = Math.atan2(this._parent._ymouse-this._y,this._parent._xmouse-this._x);
		//convert that to degrees instead:
		var angleInDegrees = angleInRadians*180/Math.PI;
		//just output the angle for debugging:
		trace("angleInDegrees: "+angleInDegrees);
		//set the rotation of the handle:
		this._rotation = angleInDegrees;
				
		//the numbers below are the min-max angle values (-145 to -155)
		//you can change them if you want to
		//check if the rotation is within the specified range:
		if(angleInDegrees < -145 && angleInDegrees > -155){
			//this code will run if condition above is true.
			//the user has rotated the handle to correct place
			trace("correct"); //just for debugging. user wont see it.
			//snap the handle to the exact correct degree:
			//I am just presuming you want it to be -150, you can change that if you want to:
			this._rotation = -150;
			
			//here is where you put the code to reveal a certain movie-clip or something like that
			//to say "correct"
			
			//for example:
			//here you have already created a mc on stage that has ._visible = false;
			//then you make it visible:
			
			//correct_mc._visible = true;
			
		}
		
	}
}
handle.onMouseUp = function(){
	if (this.onMouseMove) delete this.onMouseMove;
}

Open in new window

0
 

Author Closing Comment

by:smdevivoydocs
ID: 31673537
Beautiful....
Exactly what I was looking for!  You were a great help and I can now make a successful presentation on Friday.
Truly appreciate being able to tap into your expertise.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
Suggested Courses
Course of the Month19 days, 13 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question