|
Building
A Draggable Menu
If youd like follow along, open m0001.fla and edit the Symbol clip.menu. Now we need to make this menu clip draggable. To so, the user must press and hold the mouse button over the menu bar. With the mouse button pressed, the user can drag the menu around. When the user releases the mouse button, the menu is dropped or placed at the new location. For interactivity with the mouse we need to use a button. Lets drop an Instance of button.empty over the elements assembled in clip.menu thus far. It will cover the entire height of the menu bar, but will stop in width just short of the arrow. Why? Because well need to place a different button over the arrow to control the expansion and collapse of the menu items.
Select the Instance of the button on the Stage, not the Timeline. Open the Actions Panel and make sure its called Object Actions (which indicates that you applying script to an Instance rather than a key frame.) Well start with making the menu draggable when the user presses and holds the mouse button. Input the following script: on
(press) { Lets examine this code (well ignore the curly braces, just keep in mind that the curly braces contain code that is executed with particular events, such as the on (press) event): on
(press) this.startDrag(); If youre following along, test the movie or run m0002.swf. Drag the menu around. Youll notice that the menu is draggable, but once pressed, you cannot drop it! We need to add the script to stop the menu from dragging when the user releases the mouse button. Return to the Flash movie and select the button Instance (in the button.drag Layer of clip.menu.) Below the on (press) Event we need to add the following script: on
(release, releaseOutside)
{ Our Event Handler
is release and releaseOutside, meaning that when the user releases the
mouse button, either over top or outside of the buttons hit area
the following action will be executed. The action being executed is stopDrag().
Again, this a a method of the Movie Clip Object that will stop the Instance
currently being dragged. Note: Only one Instance at a time can be dragged. If youre following
along, test the movie or run m0003.swf.
Now you can drag and drop the menu around the screen, just as you can
drag Panels around in the Flash Environment. |