Button._name Property | Flash 6 |
the instance name of the Button object | read/write |
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; } } }
Button.onRelease( ), "The for-in Loop," in Chapter 8