• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 7. Controlling the Movie Clip > Detecting Dropped Movie Clips

Detecting Dropped Movie Clips

Now that you can make a movie clip that can be dragged around the Stage, you’ll want to know where the user drops it. If the movie clips are puzzle pieces, for example, you need to know whether or not those pieces are dragged and dropped on the correct spots. One of the simplest ways to detect the dropped movie clip’s location is to use the movie-clip property _droptarget. This property retrieves the absolute target path of another movie clip where the draggable movie clip was dropped. The second movie clip essentially is the destination for the draggable movie clip. Use a conditional statement to compare whether the _droptarget of the draggable movie clip is the same as the target path of the destination movie clip. Perform any actions based on whether the condition is true or false.

A common practice with drag-and-drop movie clips is to create snap-to and bounce-back behaviors. When the user drops a movie clip very near a correct location, you can detect that situation with _droptarget and then adjust, or snap, the movie clip to a more exact position by using the setProperty action, which sets its X and Y Positions. When the user drops a movie clip in an inappropriate location, you can detect that situation with _droptarget and then send, or bounce, it back to its original position by using the setProperty action.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint