ButtonBackground
| Kind of class: | class |
|---|---|
| Inherits from: | MovieClip |
| Version: | 4 Feb 2006 |
| Author: | Arthur Clemens |
| Classpath: | playground.classes.ui.buttons.ButtonBackground |
| File last modified: | Thursday, 13 July 2006, 09:34:01 |
Button background class with 3 part clips: center, left and right.
By setting the width of the center clip, the side clips positions are automatically adjusted.The 3 ButtonBackground movieclips are:
center_mc, left_mc and right_mc.Usage:
In a (custom, centered) button class:
private var label_tf:TextField; private var background_mc:ButtonBackground; private var BUTTON_WIDTH_OFFSET:Number = 5; // ... public function setLabel (inText:String) : Void { // put the label text in the text field label_tf.text = inText; // calculate the new width of the text field, and add an amount to account for Flash cutting off chars at the end var width:Number = label_tf.textWidth * 1.15; // set the text frame width to its contents label_tf._width = width; // set the width of the background background_mc.setWidth(width, BUTTON_WIDTH_OFFSET); // center the label label_tf._x = -width/2; // center the background background_mc._x = -background_mc._width/2; }For a left-aligned button:
public function setLabel (inText:String) : Void { // put the label text in the text field label_tf.text = inText; // calculate the new width of the text field, and add an amount to account for Flash cutting off chars at the end var width:Number = label_tf.textWidth * 1.15; // set the text frame width to its contents label_tf._width = width; // set the width of the background background_mc.setWidth(width, BUTTON_WIDTH_OFFSET); // left-align the label label_tf._x = background_mc.getCenterClipPosition() + BUTTON_WIDTH_OFFSET; // left-align the background background_mc._x = 0; }
Summary
Instance methods
Instance methods
getCenterClipPosition
function getCenterClipPosition (
) : Number
The position of the center clip.
setWidth
function setWidth (
inWidth:Number,
inOffset:Number) : Void
Sets the width of the center clip, plus (optionally) a side offset. This offset will be added to the two sides of the center clip.
Parameters:
inWidth :
the width of the center clip
inOffset:
the width of the side offset