// Copyright 2007. Adobe Systems Incorporated. All Rights Reserved. package fl.controls { import fl.controls.Labelstudent_ar_fl_controls_Button; import fl.core.InvalidationType; import fl.core.UIComponent; import fl.managers.IFocusManagerComponent; import flash.display.DisplayObject; import flash.display.Sprite; //-------------------------------------- // Styles //-------------------------------------- /** * The skin to be used when a button has emphasis. * * @default student_ar_fl_controls_Button_emphasizedSkin * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ [Style(name="emphasizedSkin", type="Class")] /** * The padding to be applied around the student_ar_fl_controls_Buttons in an * emphasized skin, in pixels. * * @default 2 * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ [Style(name="emphasizedPadding", type="Number", format="Length")] //-------------------------------------- // Class description //-------------------------------------- /** * The student_ar_fl_controls_Button component represents a commonly used rectangular button. * student_ar_fl_controls_Button components display a text label, an icon, or both. * *
A student_ar_fl_controls_Button component is typically associated with an event handler
* method that listens for a click
event and performs the
* specified task after the click
event is dispatched. When
* the user clicks an enabled button, the button dispatches the click
* and buttonDown
events. Even if it is not enabled, a button
* dispatches other events including mouseMove
, mouseOver
, mouseOut
,
* rollOver
, rollOut
, mouseDown
,
* and mouseUp
.
You can change the appearance of the button by associating a different * skin with each button state. A student_ar_fl_controls_Button component can also be set to * function as a push button or a toggle button.
* * @langversion 3.0 * @playerversion Flash 9.0.28.0 * @includeExample examples/student_ar_fl_controls_ButtonExample.as */ public class student_ar_fl_controls_Button extends Labelstudent_ar_fl_controls_Button implements IFocusManagerComponent { /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var _emphasized:Boolean = false; /** * @private (protected) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ protected var emphasizedBorder:DisplayObject; /** * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ private static var defaultStyles:Object = { emphasizedSkin:"student_ar_fl_controls_Button_emphasizedSkin", emphasizedPadding:2 }; /** * @copy fl.core.UIComponent#getStyleDefinition() * * @includeExample ../core/examples/UIComponent.getStyleDefinition.1.as -noswf * * @see fl.core.UIComponent#getStyle() UIComponent.getStyle() * @see fl.core.UIComponent#setStyle() UIComponent.setStyle() * @see fl.managers.StyleManager StyleManager * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ public static function getStyleDefinition():Object { return UIComponent.mergeStyles(Labelstudent_ar_fl_controls_Button.getStyleDefinition(), defaultStyles); } /** * @private * * Method for creating the Accessibility class. * This method is called from UIComponent. * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ public static var createAccessibilityImplementation:Function; /** * Creates a new student_ar_fl_controls_Button component instance. * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ public function student_ar_fl_controls_Button() { super(); } [Inspectable(defaultValue=false)] /** * Gets or sets a Boolean value that indicates whether a border is drawn * around the student_ar_fl_controls_Button component when the button is in its up state. A value * oftrue
indicates that the button is surrounded by a border
* when it is in its up state; a value of false
indicates that
* it is not.
*
* @default false
*
* @includeExample examples/student_ar_fl_controls_Button.emphasized.1.as -noswf
*
* @see #style:emphasizedPadding
* @see #style:emphasizedSkin
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function get emphasized():Boolean {
return _emphasized;
}
/**
* @private (setter)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function set emphasized(value:Boolean):void {
_emphasized = value;
invalidate(InvalidationType.STYLES)
}
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override protected function draw():void {
if (isInvalid(InvalidationType.STYLES) || isInvalid(InvalidationType.SIZE)) {
drawEmphasized();
}
super.draw();
if (emphasizedBorder != null) {
setChildIndex(emphasizedBorder, numChildren-1);
}
}
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
protected function drawEmphasized():void {
if (emphasizedBorder != null) { removeChild(emphasizedBorder); }
emphasizedBorder = null;
if (!_emphasized) { return; }
var emphasizedStyle:Object = getStyleValue("emphasizedSkin");
if (emphasizedStyle != null) {
emphasizedBorder = getDisplayObjectInstance(emphasizedStyle);
}
if (emphasizedBorder != null) {
addChildAt(emphasizedBorder, 0);
var padding:Number = Number(getStyleValue("emphasizedPadding"));
emphasizedBorder.x = emphasizedBorder.y = -padding;
emphasizedBorder.width = width + padding*2;
emphasizedBorder.height = height + padding*2;
}
}
/**
* @private
*
* @copy fl.core.UIComponent#drawFocus()
* @internal Added logic to resize focusRect if button has emphasis
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override public function drawFocus(focused:Boolean):void {
super.drawFocus(focused);
//Add focusRect to stage, and resize
if (focused) {
// Add the emphasis padding to the focus padding if appropriate
var emphasizedPadding:Number = Number(getStyleValue("emphasizedPadding"));
if (emphasizedPadding < 0 || !_emphasized) { emphasizedPadding = 0; }
var focusPadding = getStyleValue("focusRectPadding");
focusPadding = (focusPadding == null) ? 2 : focusPadding;
focusPadding += emphasizedPadding;
uiFocusRect.x = -focusPadding;
uiFocusRect.y = -focusPadding;
uiFocusRect.width = width + (focusPadding*2);
uiFocusRect.height = height + (focusPadding*2);
}
}
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override protected function initializeAccessibility():void {
if (student_ar_fl_controls_Button.createAccessibilityImplementation != null) {
student_ar_fl_controls_Button.createAccessibilityImplementation(this);
}
}
}
}