In Flash 5 and earlier versions, only button instances were able to have mouse events attached to them. With Flash MX, however, movie clip instances can also have attached mouse events (as shown in the above exercise). To make the most of this powerful new capability, you need to be aware of a few things especially if you're familiar with Flash's earlier implementation of button instances and mouse events:

  • To cause a movie clip to be treated as a button, simply attach a mouse event to it. Under most circumstances, you cannot attach both mouse events and clip events to a single instance; however, you can use event handler methods (discussed later in this lesson) to set a movie clip instance to react to both mouse and clip events.

  • When a movie clip instance is assigned mouse events so that Flash recognizes it as a button, it retains all of its movie clip functionality.

  • When a movie clip instance is assigned mouse events so that Flash recognizes it as a button, a hand cursor will appear when the user places his or her mouse over it. If you want a movie clip instance to act like a button but don't want the hand cursor to appear, set the useHandCursor property of the instance to false with a rollOver event, as follows:

     on(rollOver){    this.useHandCursor = false;  } 

    The useHandCursor property can be set for button instances as well (see below).

  • Although you can place mouse events on movie clip instances, you cannot place clip events on button instances (as we'll discuss later in this lesson).

  • Button instances can now be assigned instance names, and they have properties similar to movie clip instances (for example, _alpha , _rotation , _y , and so on). Thus, if you give a button an instance name of myButton, you can change its transparency using myButton._alpha = 50 .

  • Although you can assign instance names to buttons (and they're treated similarly to movie clip instances, now employing properties and methods) buttons aren't independent timelines (as movie clips are) an important thing to remember when using the term this as a target path. For example, if you were to place the following script on a movie clip instance, the instance itself would rotate:

     on(press){    this._rotation = 30;  } 

    However, if you were to place the same script on a button, the button's parent will rotate. Think of it this way: Movie clip instances are timelines, even when attaching mouse events so that Flash recognizes them as buttons. Even though buttons can now be given instance names as well as have properties and methods, they are still part of a timeline, not timelines themselves.

    You may now be asking, Since movie clips can now be treated as buttons while still maintaining all of their powerful movie clip instance capabilities, why use standard buttons at all anymore? Well, primarily because a button's up, over, and down states are still much easier to re-create and implement using an actual button. So, for quick and easy button functionality, use button instances. For highly sophisticated button functionality, use movie clip instances with mouse events attached to them.

  • If you use a movie clip instance as a button, you can place three special frame labels (_up, _over, _down) on a movie clip's timeline to easily facilitate the movie clip button's appearance when the mouse interacts with it (though you aren't required to do this in order to use a movie clip instance as a button).


  • By default, the hit area of a movie clip button will be the shape and area of any graphical content it contains, but you can change the hit area at any time by defining its hitArea property. For example, the following will set a movie clip instance as the hitArea of a movie clip button.

     myClipButton.hitArea = "_root.myHitClip"; 

This property is only available to movie clip buttons, not standard buttons.

Macromedia Flash MX ActionScripting Advanced. Training from the Source
Macromedia Flash MX ActionScripting: Advanced Training from the Source
ISBN: 0201770229
EAN: 2147483647
Year: 2002
Pages: 161 © 2008-2017.
If you may any questions please contact us: