Flash MX - Drag and Drop to Shapes
This tutorial is an adjunct to the basic Drag and drop tutorial situated here.
In response to Clara, who asks :
"How can I drag (in Flash 5) a button or movie clip (symbol2) to a similar object (silhouette or outline)
in another place of the scene. If this object (silueta) has the same shape that the button (symbol2) then
stop drag and if this button has a different shape return to the original place."
Flash Tutorials in Video Format -
Watch them now at LearnFlash.com
So Clara, let's start.
-
Create your image to be dragged on layer 1 and name that layer "dragger"
-
Create a silhouette or outline of this image on layer 2 and name that layer "dragto".
Hit the "F8" key and make it a MovieClip and call it "siluto".
In the instance field of the properties box, name it "silute".
-
Select your original image on layer 1 , hit the "F8" key (Convert to Symbol), make it a MovieClip, call it
"camel". In its instance field, call it "camel_mc".
-
Open your library window (F11), double click the camel movieClip.
-
Create another layer inside the camel mc, call it "button", Cover the camel with a filled rectangle or circle,
hit F8 and make the rectangle a button, call it Invisible .
-
Double click on that button or select it from the library and hit F6 to create Key frames for the Over, Down, and Hit frames.
Delete the first 3 frames only leaving the rectangle on the hit frame. It thus becomes an invisible button.
-
Go back to the camel movieclip and select the button and put this code in the ActionScipt window(F9):
// when mc is pressed , drag it
on(press) {
startDrag(this);
}
// when mc is released stop dragging
on(release) {
stopDrag();
// if the right shape , leave it there
if (this._droptarget == "/silute") {
this._x = _root.silute._x;
this._y = _root.silute._y
}
// if wrong shape,
else{
// take it back to original position
this._x = 350;
this._y = 300;
}
}
Hopefully that should do the trick.
Download the fla here.
If you have any questions , drop into the forum and ask away.
Flash 8 update for drag and drop
|