DelayButton

Kind of class:class
Inherits from:EventButton < EventMovieClip < MovieClip
Known subclasses:
Author:Arthur Clemens
Classpath:org.asapframework.ui.buttons.DelayButton
File last modified:Thursday, 12 October 2006, 11:19:40
DelayButton offers timing control over rollOver and rollOut. This can be useful for navigation menus where a menu item should "remember" its state for a brief moment even when the mouse has moved out of its click region (in UI design this effect is called hysteresis - see also time delay in hierarchical menus.

Other uses for DelayButton are (Flash specific) to avoid flickering with buttons that grow in size with roll over, and in intuitive interfaces that require precise time control.

DelayButton has 3 properties that can be set to control timings before and after roll over and roll out:
  • indelay : the number of seconds between the mouse having rolled over and the clip performing onRollOver
  • outdelay : the number of seconds between the mouse having rolled out and the clip performing onRollOut
  • afterdelay : the number of seconds a movieclip is momentarily inactive after roll out
Usage:
  • A hierarchical menu that folds out a submenu will leave the submenu visible for a short time after the mouse has left it. The submenu will have an outdelay of about 0.5 seconds.

    If the menu has multiple submenus, each submenu will only pop up after a short delay, to prevent a wild and annoying popping-up effect. The submenu will have a short indelay (of about 0.1 seconds).

    A movieclip that expands with roll over will get its hit area wrong - an annoying Flash 'bug'. If you move the mouse on the right spot, a wild firing of onRollOver and onRollOut will occur, resulting in the flickering of the movieclip as if it is not sure in which state it is in. To prevent this, give the button a afterdelay of about 0.5 seconds.
Example:
  • You may need to create a rollover state variable to prevent onRollOut getting called when the button's doRollOver has not yet been called. For example in a DelayButton subclass:
    private static var UP_STATE:Number = 0;
    private static var ROLLOVER_STATE:Number = 1;
    private var mState:Number = UP_STATE;
    //...
    public function doRollOver () : Void {
        mState = ROLLOVER_STATE;
        super.doRollOver(); // DelayButton sends an onRollOver to its superclass
    }
    
    public function doRollOut () : Void {
        if (mState != ROLLOVER_STATE) {
            return;
        }
        super.doRollOut(); // DelayButton sends an onRollOut to its superclass
        mState = UP_STATE;
    }

Summary


Constructor
Instance properties
  • mRollOverState : Boolean
    • Indicates if the button has a rollover, defined by the delay variables.
  • indelay : Number
    • Delay before doRollOver action is performed, in seconds.
  • outdelay : Number
    • (Hysteresis) delay before doRollOut action is performed, in seconds.
  • afterdelay : Number
    • Delay after onRollOut until the button is activated (enabled) again, in seconds.
  • mReenabledTime : Number
    • Set the time from where the button will be active again (in milliseconds); value is calculated.
  • mInDelay_ival : Number
    • Id from setInterval used to call method performDoRollOver.
  • mOutDelay_ival : Number
    • Id from setInterval used to call method performDoRollOut.
  • mAfterDelay_ival : Number
    • Id from setInterval used to call method reenableAfterDelay.
Instance methods
Event handlers
  • onUnload : Void
    • At unload, clears the intervals set with setInterval.
  • onRollOver : Void
    • Implements MovieClip.onRollOver.
  • onRollOut : Void
    • Implements MovieClip.onRollOut.
  • onPress : Void
    • Implements MovieClip.onPress.
  • onRelease : Void
    • Implements MovieClip.onRelease.
  • onReleaseOutside : Void
    • Implements MovieClip.onReleaseOutside.

Constructor

DelayButton

function DelayButton (
)

Creates a new DelayButton.

Instance properties

afterdelay

afterdelay:Number = 0
(read)

Delay after onRollOut until the button is activated (enabled) again, in seconds.

indelay

indelay:Number = 0
(read)

Delay before doRollOver action is performed, in seconds.

mAfterDelay_ival

private mAfterDelay_ival:Number
(read)

Id from setInterval used to call method reenableAfterDelay.

mInDelay_ival

private mInDelay_ival:Number
(read)

Id from setInterval used to call method performDoRollOver.

mOutDelay_ival

private mOutDelay_ival:Number
(read)

Id from setInterval used to call method performDoRollOut.

mReenabledTime

private mReenabledTime:Number
(read)

Set the time from where the button will be active again (in milliseconds); value is calculated.

mRollOverState

private mRollOverState:Boolean
(read)

Indicates if the button has a rollover, defined by the delay variables.

outdelay

outdelay:Number = 0
(read)

(Hysteresis) delay before doRollOut action is performed, in seconds.

Instance methods

clearIntervals

private function clearIntervals (
) : Void

Clears all intervals created with setInterval.

doPress

function doPress (
) : Void

Called by onPress. Empty stub to be implemented by a DelayButton subclass. Calls super.onPress.

doRelease

function doRelease (
) : Void

Called by onRelease. Empty stub to be implemented by a DelayButton subclass. Calls super.onRelease.
Example:
  • In a DelayButton subclass:
    private function doRelease () : Void
        super.doRelease();
        if (!selected) {
            selected = true;
            gotoAndStop("selected");
        }
    }

doRollOut

function doRollOut (
) : Void

Called by onRollOut. Empty stub to be implemented by a DelayButton subclass. Calls super.onRollOut.

doRollOver

function doRollOver (
) : Void

Called by onRollOver. Empty stub to be implemented by a DelayButton subclass. Calls super.onRollOver.
Example:
  • In a DelayButton subclass:
    private function doRollOver () : Void
        super.doRollOver();
        if (!selected) {
            gotoAndStop("over");
        }
    }

performDoRollOut

private function performDoRollOut (
) : Void

Interval method called from onRollOut. Calls doRollOut.

performDoRollOver

private function performDoRollOver (
) : Void

Interval method called from onRollOver. Calls doRollOver.

reenableAfterDelay

private function reenableAfterDelay (
) : Void

Interval method called from onRollOut. Sets the button enabled to true.

toString

function toString (
) : String

Event handlers

onPress

function onPress (
) : Void

Implements MovieClip.onPress. Do not implement this method yourself; code that should be performed on onPress should go into doPress.

onRelease

function onRelease (
) : Void

Implements MovieClip.onRelease. Do not implement this method yourself; code that should be performed on onRelease should go into doRelease.

onReleaseOutside

function onReleaseOutside (
) : Void

Implements MovieClip.onReleaseOutside. Calls doRollOut by default.

onRollOut

function onRollOut (
) : Void

Implements MovieClip.onRollOut. Do not implement this method yourself; code that should be performed on onRelease should go into doRollOut.
If afterdelay is specified, the movieclip will be disabled until after delay time. This is useful for out-animations where the hitarea changes shape - the Flash can get trapped in a race condition if a onRollOver event is fired immediately after the onRollOut. Setting afterdelay enables the movieclip to finish the out-animation before being enabled/active again.
If outdelay is specified, calling of doRollOut is postponed until after delay time. This effect is also called hysteresis.

onRollOver

function onRollOver (
) : Void

Implements MovieClip.onRollOver. Do not implement this method yourself; code that should be performed on onRelease should go into doRollOver.
If indelay is specified, calling of doRollOver is postponed until after the delay period.

onUnload

function onUnload (
) : Void

At unload, clears the intervals set with setInterval.