Table of Contents

Button.onRelease( ) Event Handler Flash 6; on (release) supported since Flash 2

occurs when the mouse is pressed and then released while the pointer is over a Flash button
theButton.onRelease()   

on (release) {  
  statements
}

Description

The onRelease( ) event handler is executed when the following sequence is detected:

  1. The mouse pointer is in the hit area of theButton.

  2. The primary mouse button is pressed while the mouse pointer is still in the hit area of theButton (at which point an onPress( ) event occurs).

  3. The primary mouse button is released while the mouse pointer is still in the hit area of theButton (at which point an onRelease( ) event occurs).

By using the release event instead of the press event, you give users a chance to move the pointer off of a button even after the mouse has been pressed, thus allowing them to retract their action. The onRelease( ) handler is the most common button handler in Flash. It is used to respond to the classic button click. Note that the trackAsMenu property can alter the behavior of onRelease( ), as described under Button.trackAsMenu.

Example

The following code shows two onRelease( ) handlers. When ok_btn is clicked, the playhead of the button's parent movie clip is sent to the frame labeled begin. When cancel_btn is clicked, the playhead is sent to the frame labeled quit.

ok_btn.onRelease = function () {
  this._parent.gotoAndStop("begin");
}
   
cancel_btn.onRelease = function () {
  this._parent.gotoAndStop("quit");
}

See Also

Button.onPress( ), Button.trackAsMenu, MovieClip.onRelease( ); Chapter 10


Table of Contents