Button._name Property

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Button._name Property Flash 6

the instance name of the Button object read/write
theButton._name

Description

The string _name property indicates theButton's instance name, which is specified via the Property inspector at authoring time. Though rarely (if ever) necessary, setting _name reassigns the instance name for theButton; thereafter, references to the old instance name yield undefined.

More commonly, the _name property is read, not written. For example, it can be used to identify a specific button when one of many is clicked. The following function performs different actions based on the calling button:

function doAction () {   if (this._name =  = "ok_btn") {     doConfirm();   } else if (this._name =  = "cancel_btn") {     doCancel();   } }     // Assign button handlers ok_btn.onRelease = doAction; cancel_btn.onRelease = doAction;

Or, if we're looking for a single button in a group of unknown buttons, we can use a for-in loop to hunt for the button's instance name:

// Access all properties of someClip for (var p in someClip) {   // If it's a Button object...   if (someClip[p] instanceof Button) {     // ...show its name:     trace("Found " + someClip[p]._name);         // Look for edit_btn     if (someClip[p]._name =  = "edit_btn") {       // Disable the edit button.       someClip[p].enabled = false;     }   } }

See Also

Button.onRelease( ), "The for-in Loop," in Chapter 8



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net