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

Hour 15. ActionScripting Applications fo... > Task: Make a Simple Draggable Object

Task: Make a Simple Draggable Object

In this task you'll create a simple draggable object. Here are the steps to follow:

In a new file, draw a square, select it, and convert it to a symbol. Call the symbol “Button” and make sure its behavior is Button.

Select the button instance and use the Properties panel to give it the instance name box. Next we'll attach an Action to the button that effectively says “drag me.” Select the button instance and open the Actions panel. Click the plus button, Actions, Movie Clip Control, startDrag.

Modify the startDrag Action's parameters by typing box into the target field. Go ahead and test the movie to see what works and what doesn't. If you click and drag, the button doesn't move. However, if you click and let go on the button, you'll start dragging—but that's after you let go!

To fix this, go back to the button instance and change the mouse event from the default “Release” to “Press,” as shown in Figure 15.1. (Because you can have more than one mouse event, you'll have to deselect Release and then check Press.) If you do a Test Movie now, you'll see that it works fine, except you can't let go of the button after you start dragging.

Figure 15.1. Selecting the first line in the script lets you change the specific mouse event to which you're going to respond.

You need the button to respond to two events. For the Press event, it needs to start dragging (which it does), and for the Release event, it needs to stop dragging. Therefore, drag the stopDrag Action (from Actions, Movie Clip Control), as shown in Figure 15.2.

Figure 15.2. Dragging the stopDrag Action below the end of the Press mouse event causes a new mouse event to be created (Actions attached to buttons must be inside a mouse event).

The second mouse event (wrapping the stopDrag Action) uses the Release event by default. This is good, but you should also click Release Outside, which will work if the user releases outside this button. Basically, this is a failsafe way to make sure the user can let go of the clip. The result should look like what's shown in Figure 15.3. Take a good look at the result, which should now make sense to you as it currently reads. It should also work when you test it.

Figure 15.3. The finished version of a simple draggable button script.



Not a subscriber?

Start A Free Trial

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