For the garbage to be able to drop into the trash can, the garbage needs to know where the trash can is located. Right now, the trash can is a miscellaneous movie clip on the Stage; it needs an instance name so that you can talk to it. After you've assigned an instance name to the trash can movie clip, you can use the _droptarget property of the garbage movie clip you're dragging to control what happens next . The _dropTarget property returns the full path to the instance of the object on which you drop. Unfortunately, the path returned is in the deprecated slash syntax. You can get around that by using the eval() statement to convert the slash syntax to dot syntax. After you've done that, you can easily compare the instance name of the trash can movie clip (_root.trashcan) to the name of whatever you drop on. If it turns out that you have dropped on top of the trash can movie clip, you just need to make the current piece of trash invisible. Now that you know what to do, give it a try. Exercise 17.2 Using _dropTarget You already know that you need to assign the trash can an instance name before you do anything else, so start there.
Tip Any time you've entered some code, you can do a quick syntax check by pressing the Options arrow in the top-right corner of the Actions panel and selecting Check Syntax. This can help you catch any errors before you test your movie. What else could you do with this movie? You could make the different pieces of garbage do something on a mouseover or hit. You could add sound. You could make the trash can open and close. You also could set it up so that you could drop the garbage only on the ground or in the trash canno leaving the garbage hanging in the sky. You're limited only by your imagination . Next you combine the drag-and-drop interaction you already know with creating a custom cursor. |