Drag and drop functions

im starting a project that may be a bit above my ability level so im asking for a bit of detailed help here, (finally working on my website) what i have going here is a series of five parts of a machine on the left hand side of the page, to the right of them is the actuall machine, each part is labeled with the proper page it will take you to, heres what i need to happen, when nothing is happening on the page everything should be still aside from subtle animations on the machine and so forth, when a person drags a part and drops it in the slot on the machine i want the machine to start up, run a animation and then trigger a mc to play that will deliver drop down menues or thumbnails etc, the dragable part will actually move through the machine and stop before the mc is qued and played. i have some ideas as to how to accomplish this but they are a bit vauge. detailed help would be appreciated. this may be more appropriate for the as forum, if so feel free to move it there. thanks… hopefully i wont see 600 websites like this, im sure there are some already but what the hell

i just moved it here anyhow, its definitly an AS topic

Hey asmodias,
Try this tutorial tha explains how to use drag and drop with targets to accomplish something very similar to the problem you are having: www.kirupa.com/developer/…agdrop.asp

ive got basic drop and drag down with root commands, i guees what im needing to know is how to go about queing a movie thats not on screen and making sure the link is intact at the end of the mc for now lets just say its an email link instead of a url, would i make the changes of this nature to the script for changing color on (press) {startDrag ("_root.email");
on (release) {stopDrag ();
&nbsp &nbsp &nbsp &nbsp if (_root.email._droptarget == “/machine”) {
&nbsp &nbsp &nbsp &nbsp _root.machine.gotoAndPlay(“mc”);
&nbsp &nbsp &nbsp &nbsp }

where email would be my draggable object
machine would take the place of the computer in the tut. and mc would be the movie clip i want to play when the email is dropped in the right location. also do i need to just have the mc in my library or do i need to put the code on frame 1 and place the mc in frame 5? perhaps change the gotoAndPlay(“mc”) to gotoAndPlay(“frame5”)?


this command is telling the movie “machine” to gotoAndPlay a frame named “mc”. is that what you want?

putting something in the library will ** not** put it in your swf. you must put it on the stage. what’s more, to target a movie it exist on the stage when you target it. that doesn’t mean it needs to be visible, you can make it’s _visible=0, make it’s _alpha=0, have it go to an empty frame, or simply move it off to the side, but it’s gotta be there.

keep the link intact … hmmm. i’m not sure what you mean, but it sounds like the kind of thing i would store in a variable. how about having:

link="mailto:[email protected]";

which would of course vary according to which movie is being dragged, and then later (after the animation i presume):


is that what you mean?

reading back on this i see i wasnt very clear, basically all i have is a mc of a machine on the right and to the left are draggable objects
all i need it to do is play the mc once the draggable objects are dropped in the right place. as far as the links are concerned, i can accomplish this easily enough by adding a get url action to the last frame of the mc, but i need that to vary, because if something other than email is chosen, ( such as portfolio) i want a mc containing thumbnails to either alpha or scroll onto the screen above the machine MC once it is finished playing. am i still not clear enough if so tell me

re: getting the mc to play.

is your if statement evaluating properly? use trace actions to find out. if it is, name the mc you want to play something, perhaps “machine”, and then:


if a drop is successful.

as to loading different urls with one load statement at the end, the variable technique in my previous post will work for that. store a variable in each movie clip corresponding to the link you want loaded, then pass that to “machine” in the event of a successful drop. “machine” will play, get to the end, and go “what am i meant to load? oh yeah, i load whatever ‘link’ equals” and that’s what gets set by each draggable clip.

hey, this is asmodias at the clonespecks house, ( since my service is shut off cuz im a broke bastard) thanks for replying, i pretty much have it down with one problem left heres the code i have so far
onpress startdrag(_root.drag)
on release StopdragO}

if_root.drag._droptarget == “/mc1”}
_root.mc1.gotoandplay “5”}
_root.mc2.gotoandstop “1”}
if_root.drag._droptarget == “/mc2”}
_root.mc2.gotoandplay “5”}
_root.mc1.gotoandstop “1”}
i need to add a action that will reset evferything to the beginnin if you click somewhere else on the screen or even better return the draggable object back to its original position once youve chosen a menu option
( frame 5 of mc1 and mc2 roll out a series of buttons for thumbnail galleries) i need the drag function to reset once a gallery is chosen but the gallery should remain as it is.
any ideas?

hey, likewise, sorry for the posting delay, it’s thanksgiving up here, i was ignoring computers.

how about putting the actions for returning the draggable movie clips into a function, and then calling that function from each button in addition to whatever else you want.

right in frame 1 level 1 write (something like):

function resetDrag(){
&nbsp &nbsp &nbsp &nbsp _root.mc1._x = //where ever it started
&nbsp &nbsp &nbsp &nbsp _root.mc1._y = //etc
&nbsp &nbsp &nbsp &nbsp // repeat for each movie, or you might consider
&nbsp &nbsp &nbsp &nbsp // using a for loop and arrays of x and y values.

then in the buttons:

&nbsp &nbsp &nbsp &nbsp _root.resetDrag();
&nbsp &nbsp &nbsp &nbsp // … the rest of what you want to happen


sounds good to me, now how do i find out the start coordinates of my drag? im not very familiar with different functions yet and have no clue what the // do

are the start coordinates going to be the same each time? if that’s the case just find where their x and y’s in the fla and punch in those numbers.

a function is kind of just a way to reference code so you don’t have to write it more than once. imagine putting identical code in all your seperate buttons and then needing to make a change. you have to change every button, very tedious. if it’s contained in a function you just change the function and voila! all the buttons do the new action.

it’s comparable to using many copies of the same movie, change one, and you’ve changed them all.