Drag and Drop
Dropping into target
One of important features of drag and drop is a possibility to find – where draggable clip was dropped. Of course we may find coordinated of place when releasing button as we done in the slider example. But it's easier to do it by using _droptargetproperty of the MovieCilp object.- Create a new file and add several draggable instances. Remember that to make it draggable you need to use a combination of the Button inside the Movie symbol. In our example we have a buttons btLetter and three movie symbols mvA, mvB and mvC In each symbol the button is encapsulated and letter A , B or C added.
- Edit movie instances and highlight buttons inside them. Enter the code for each button, similarly to how we done it for previous exercises
on(press){ startDrag(this,false); } on(release) { stopDrag(); } - Create a movie symbol and call it thetarget
- Higlight each movie symbol – mvA, mvB, mvC enter the following script. Make sure it must be script for Movie Symbol – not for the Frame!
onClipEvent(mouseUp) { if (eval(this._droptarget) == _root.thetarget ){ this._visible = false; } }The first line of code recognize an event mouseUp of this movie symbol.
If condition compare _droptarget property of the movie (simply to say on what this letter was dropped) to the target symbol. If it is droopped on thetarget then condition is satisfied and letter disappears. If target is missed – the letter stays. Here is an example of using eval function. It help to compare different things. Actually _droptarget is a property of MovieClip instance, but _root.thetarget is an instance of MovieClip itself and without eval they cannot be compared.
- Test the movie. If you drop letter to the target – letter must disappear. Think about improving this movie – it's an enormous potential for games in this simple technique!