Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drag a drop help please

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hi i work for a company and were trying to make a form to where synthesizer modules can be dragged into a case type thing and they snap into place, then you click on a button and it shows you the price. i already have it so that you can drag modules but im needing help on knowing how to snap them into...oh say XY coordinates. please help, thanx.
 
You could use invisible movie clips for the area that you will allow the module to be dropped onto. Then use a hitTest method to either snap it into place, or snap it back to where it was picked up from:

Code:
on (press) {
    _root.x_module01 = _root.module01._x
    _root.y_module01 = _root.module01._y
    startDrag ("");
}
on (release) {
    stopDrag ();
    if (_root.module01.hitTest(_root.droparea_module01)) {
        _root.module01._x = 350;
        _root.module01._y = 250;
    } else {
        _root.module01._x = _root.x_module01;
        _root.module01._y = _root.y_module01;
    }
}
 
I should have thrown a couple of comments in there:

Code:
on (press) {
    // get the module's current location
    _root.x_module01 = _root.module01._x
    _root.y_module01 = _root.module01._y
    startDrag ("");
}
on (release) {
    stopDrag ();
    // snap module into place if in drop area
    if (_root.module01.hitTest(_root.droparea_module01)) {
        _root.module01._x = 350;
        _root.module01._y = 250;
    // snap module back into its starting position
    } else {
        _root.module01._x = _root.x_module01;
        _root.module01._y = _root.y_module01;
    }
}
 
can you tell me how to put all this code into the action? i really dont know how other than to the thru the action menu. i dont know how to put in
"_root.x_module01 = _root.module01._x
_root.y_module01 = _root.module01._y"

what would i pick on the action menu?
 
I think Frozenpeas' code envolves two movie clips (the case and the item), and at least one invisible button in the item clip. The code goes on that invisible button and the way to copy and paste it from his post, is to be in the Object actions window (and not the Frame actions window!), to select Expert Mode in the top-right arrow menu of that window, and to paste what you have copied from here.

Regards,
new.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top