How do you apply droptarget feature to a rotating object?

Posted on 2010-01-06
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.

Question by:smdevivoydocs
    LVL 5

    Expert Comment

    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 ?

        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?

    Author Comment

    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.
    LVL 5

    Accepted Solution

    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!
    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


    Author Closing Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    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…
    Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
    In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
    The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now