First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: estudioworks | Website: http://www.ebasics.net

3. Swap Objects depth:

Now we need to tell our movieclip that we are dragging to ( when pressed ) put itself on a level higher than
the other objects on the stage. All objects by default are on Level 0.

In the actions panel click right after startDrag(this); press ENTER and type in this:

this.swapDepths(100); This ActionScript tells the movieclip that you are dragging to put itself on level 100, which is above level 0. And when ever you drag this movieclip, it will be above all other items on the stage. We could have placed our movieclip on level 1 which is still above level 0, but I chose 100, just in case I wanted to add things to my movie at a later time.

4. Set up a drop target:
5. Make your object return to it's original location when it misses it's target:
6. Make your object lock into place, when it hits it's target:

Return to the main stage, from the library drag two more movie clip instances onto the stage ( draggableMC1 & draggableMC2 )
Align them on the right side of the stage, ( equal to drag1 & drag 2 ).

Give these movieclips a unique instance name ( I named mine target1 & target 2 ).

Note: I also lowered the Alpha on these instances to 50%

Select draggableMC1 ( drag1 ) and open the actions panel ( F2). Click right after stopDrag(this); press ENTER and type this:

if (this._droptarget=="/target1") {
setProperty(this, _x, 444.8);
setProperty(this, _y, 133);
} else {
setProperty(this, _x, 76);
setProperty(this, _y, 128.3);
}
This ActionScript tells your movieclip that it's looking for a target with instance name of ("target1").

The if statement is saying: That if your droptarget is target1 than I want you to place the draggable movieclip on the exact position of target1. If the registration point of your draggable movieclip comes in contact with the target movieclip, than your draggable movieclip is placed in the exact x & y position as your target movieclip.

The else statement is saying: that if your droptarget is not equal to target1 than I want you to go back to your original position. So if you release your draggable movieclip anywhere on the stage, besides on the droptarget, the movieclip goes back to it's original position

Do the same thing to drag2, substituting target 1 with target2, you'll also need to change the x & y positions to match drag 2 and target2.

Here is the complete script for drag1:

on (press) {
startDrag(this);
this.swapDepths(100);
}
on (release) {
stopDrag();
if (this._droptarget=="/target1") {
setProperty(this, _x, 444.8);
setProperty(this, _y, 133);
} else {
setProperty(this, _x, 76);
setProperty(this, _y, 128.3);
}
}

Here is the complete script for drag2:

on (press) {
startDrag(this);
this.swapDepths(100);

}
on (release) {
stopDrag();
if (this._droptarget=="/target2") {
setProperty(this, _x, 444.8);
setProperty(this, _y, 249.5);
} else {
setProperty(this, _x, 78);
setProperty(this, _y, 250);
}
}

» Level Basic

Added: 2002-11-01
Rating: 8 Votes: 89
(10 being the highest)
» Author
Flashkit Moderator
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.