Package | spark.components |
Class | public class ButtonBar |
Inheritance | ButtonBar ButtonBarBase ListBase SkinnableDataContainer SkinnableContainerBase SkinnableComponent UIComponent FlexSprite flash.display.Sprite |
Implements | IFocusManagerComponent |
Subclasses | AlignTool |
Language Version : | ActionScript 3.0 |
Product Version : | Flex 4 |
Runtime Versions : | Flash Player 10, AIR 1.5 |
The typical use for a button bar is for grouping
a set of related buttons together, which gives them a common look
and navigation, and handling the logic for the change
event
in a single place.
The ButtonBar control creates Button controls based on the value of
its dataProvider
property.
Use methods such as addItem()
and removeItem()
to manipulate the dataProvider
property to add and remove data items.
The ButtonBar control automatically adds or removes the necessary children based on
changes to the dataProvider
property.
To use this component in a list-based component, such as a List or DataGrid, create an item renderer. For information about creating an item renderer, see Custom Spark item renderers.
For non-mobile projects, you can use the ButtonBar control to set the active child of a ViewStack container, as the following example shows:
Note: The Spark list-based controls (the Spark ListBase class and its subclasses
such as ButtonBar, ComboBox, DropDownList, List, and TabBar) do not support the BasicLayout class
as the value of the layout
property.
Do not use BasicLayout with the Spark list-based controls.
<s:ButtonBar dataProvider="{myViewStack}" requireSelection="true" /> <mx:ViewStack id="myViewStack" borderStyle="solid"> <s:NavigatorContent id="search" label="Search"> <s:Label text="Search Screen"/> </s:NavigatorContent> <s:NavigatorContent id="custInfo" label="Customer Info"> <s:Label text="Customer Info"/> </s:NavigatorContent> <s:NavigatorContent id="accountInfo" label="Account Info"> <s:Label text="Account Info"/> </s:NavigatorContent> </mx:ViewStack>
The ButtonBar control has the following default characteristics:
Characteristic | Description |
---|---|
Default size | Large enough to display all buttons |
Minimum size | 0 pixels |
Maximum size | No limit |
Default skin class | spark.skins.spark.ButtonBarSkin |
The <s:ButtonBar>
tag inherits all of the tag
attributes of its superclass and adds the following tag attributes:
<s:ButtonBar />
Default MXML PropertydataProvider
See also
Method | Defined By | ||
---|---|---|---|
Constructor. | ButtonBar | ||
addStyleClient(styleClient:IAdvancedStyleClient):void
Adds a non-visual style client to this component instance. | UIComponent | ||
callLater(method:Function, args:Array = null):void
Queues a function to be called later. | UIComponent | ||
clearStyle(styleProp:String):void
Deletes a style property from this component instance. | UIComponent | ||
contentToGlobal(point:Point):Point
Converts a Point object from content coordinates to global coordinates. | UIComponent | ||
contentToLocal(point:Point):Point
Converts a Point object from content to local coordinates. | UIComponent | ||
createAutomationIDPart(child:IAutomationObject):Object
Returns a set of properties that identify the child within
this container. | UIComponent | ||
createAutomationIDPartWithRequiredProperties(child:IAutomationObject, properties:Array):Object
Returns a set of properties as automation IDs that identify the child within
this container. | UIComponent | ||
createReferenceOnParentDocument(parentDocument:IFlexDisplayObject):void
Creates an id reference to this IUIComponent object
on its parent document object. | UIComponent | ||
deleteReferenceOnParentDocument(parentDocument:IFlexDisplayObject):void
Deletes the id reference to this IUIComponent object
on its parent document object. | UIComponent | ||
Returns a UITextFormat object corresponding to the text styles
for this UIComponent. | UIComponent | ||
dispatchEvent(event:Event):Boolean [override]
Dispatches an event into the event flow. | UIComponent | ||
drawFocus(isFocused:Boolean):void
Shows or hides the focus indicator around this component. | UIComponent | ||
drawRoundRect(x:Number, y:Number, w:Number, h:Number, r:Object = null, c:Object = null, alpha:Object = null, rot:Object = null, gradient:String = null, ratios:Array = null, hole:Object = null):void
Programmatically draws a rectangle into this skin's Graphics object. | UIComponent | ||
effectFinished(effectInst:IEffectInstance):void
Called by the effect instance when it stops playing on the component. | UIComponent | ||
effectStarted(effectInst:IEffectInstance):void
Called by the effect instance when it starts playing on the component. | UIComponent | ||
endEffectsStarted():void
Ends all currently playing effects on the component. | UIComponent | ||
executeBindings(recurse:Boolean = false):void
Executes all the bindings for which the UIComponent object is the destination. | UIComponent | ||
findRowIndex(field:String, value:String, startingIndex:int = 0, patternType:String):int
This will search through a dataprovider checking the given field and for the given value and return the index for the match. | ListBase | ||
findRowIndices(field:String, values:Array, patternType:String):Array
This will search through a dataprovider checking the given field and for the given values and return an array of indices that matched. | ListBase | ||
finishPrint(obj:Object, target:IFlexDisplayObject):void
Called after printing is complete. | UIComponent | ||
generateMXMLArray(document:Object, data:Array, recursive:Boolean = true):Array | UIComponent | ||
generateMXMLVector(document:Object, data:Array, recursive:Boolean = true):* | UIComponent | ||
getAutomationChildAt(index:int):IAutomationObject
Provides the automation object at the specified index. | UIComponent | ||
getAutomationChildren():Array
Provides the automation object list . | UIComponent | ||
getBoundsXAtSize(width:Number, height:Number, postLayoutTransform:Boolean = true):Number
Returns the x coordinate of the element's bounds at the specified element size. | UIComponent | ||
getBoundsYAtSize(width:Number, height:Number, postLayoutTransform:Boolean = true):Number
Returns the y coordinate of the element's bounds at the specified element size. | UIComponent | ||
getButtonIndices(labelValues:Array, fieldName:String):Array
Gets the index for several of a ButtonBar's Buttons, referencing them by the ButtonBarbutton's label. | ButtonBarBase | ||
getClassStyleDeclarations():Array
Finds the type selectors for this UIComponent instance. | UIComponent | ||
getConstraintValue(constraintName:String):*
Returns a layout constraint value, which is the same as
getting the constraint style for this component. | UIComponent | ||
getExplicitOrMeasuredHeight():Number
A convenience method for determining whether to use the
explicit or measured height
| UIComponent | ||
getExplicitOrMeasuredWidth():Number
A convenience method for determining whether to use the
explicit or measured width
| UIComponent | ||
getFocus():InteractiveObject
Gets the object that currently has focus. | UIComponent | ||
getLayoutBoundsHeight(postLayoutTransform:Boolean = true):Number
Returns the element's layout height. | UIComponent | ||
getLayoutBoundsWidth(postLayoutTransform:Boolean = true):Number
Returns the element's layout width. | UIComponent | ||
getLayoutBoundsX(postLayoutTransform:Boolean = true):Number
Returns the x coordinate that the element uses to draw on screen. | UIComponent | ||
getLayoutBoundsY(postLayoutTransform:Boolean = true):Number
Returns the y coordinate that the element uses to draw on screen. | UIComponent | ||
getLayoutMatrix():Matrix
Returns the transform matrix that is used to calculate the component's
layout relative to its siblings. | UIComponent | ||
getLayoutMatrix3D():Matrix3D
Returns the layout transform Matrix3D for this element. | UIComponent | ||
getMaxBoundsHeight(postLayoutTransform:Boolean = true):Number
Returns the element's maximum height. | UIComponent | ||
getMaxBoundsWidth(postLayoutTransform:Boolean = true):Number
Returns the element's maximum width. | UIComponent | ||
getMinBoundsHeight(postLayoutTransform:Boolean = true):Number
Returns the element's minimum height. | UIComponent | ||
getMinBoundsWidth(postLayoutTransform:Boolean = true):Number
Returns the element's minimum width. | UIComponent | ||
getPreferredBoundsHeight(postLayoutTransform:Boolean = true):Number
Returns the element's preferred height. | UIComponent | ||
getPreferredBoundsWidth(postLayoutTransform:Boolean = true):Number
Returns the element's preferred width. | UIComponent | ||
getRepeaterItem(whichRepeater:int = -1):Object
Returns the item in the dataProvider that was used
by the specified Repeater to produce this Repeater, or
null if this Repeater isn't repeated. | UIComponent | ||
getStyle(styleProp:String):*
Gets a style property that has been set anywhere in this
component's style lookup chain. | UIComponent | ||
getVisibleRect(targetParent:DisplayObject = null):Rectangle
Get the bounds of this object that are visible to the user
on the screen. | UIComponent | ||
globalToContent(point:Point):Point
Converts a Point object from global to content coordinates. | UIComponent | ||
hasCSSState():Boolean
Returns true if currentCSSState is not null. | UIComponent | ||
hasState(stateName:String):Boolean
Determines whether the specified state has been defined on this
UIComponent. | UIComponent | ||
horizontalGradientMatrix(x:Number, y:Number, width:Number, height:Number):Matrix
Returns a box Matrix which can be passed to the
drawRoundRect() method
as the rot parameter when drawing a horizontal gradient. | UIComponent | ||
initialize():void
Initializes the internal structure of this component. | UIComponent | ||
initializeRepeaterArrays(parent:IRepeaterClient):void
Initializes various properties which keep track of repeated instances
of this component. | UIComponent | ||
invalidateDisplayList():void
Marks a component so that its updateDisplayList()
method gets called during a later screen update. | UIComponent | ||
invalidateLayering():void
Called by a component's items to indicate that their depth
property has changed. | UIComponent | ||
invalidateLayoutDirection():void
An element must call this method when its layoutDirection changes or
when its parent's layoutDirection changes. | UIComponent | ||
invalidateProperties():void
Marks a component so that its commitProperties()
method gets called during a later screen update. | UIComponent | ||
invalidateSize():void
Marks a component so that its measure()
method gets called during a later screen update. | UIComponent | ||
invalidateSkinState():void
Marks the component so that the new state of the skin is set
during a later screen update. | SkinnableComponent | ||
itemToLabel(item:Object):String [override]
Given a data item, return the correct text a renderer
should display while taking the labelField
and labelFunction properties into account. | ListBase | ||
localToContent(point:Point):Point
Converts a Point object from local to content coordinates. | UIComponent | ||
matchesCSSState(cssState:String):Boolean
Returns true if cssState matches currentCSSState. | UIComponent | ||
matchesCSSType(cssType:String):Boolean
Determines whether this instance is the same as, or is a subclass of,
the given type. | UIComponent | ||
measureHTMLText(htmlText:String):TextLineMetrics
Measures the specified HTML text, which can contain HTML tags such
as <font> and <b>,
assuming that it is displayed
in a single-line UITextField using a UITextFormat
determined by the styles of this UIComponent. | UIComponent | ||
measureText(text:String):TextLineMetrics
Measures the specified text, assuming that it is displayed
in a single-line UITextField (or UIFTETextField) using a UITextFormat
determined by the styles of this UIComponent. | UIComponent | ||
move(x:Number, y:Number):void
Moves the component to a specified position within its parent. | UIComponent | ||
moveIndexFindRow(field:String, value:String, startingIndex:int = 0, patternType:String):Boolean
This will search through a dataprovider checking the given field and will set the selectedIndex to a matching value. | ListBase | ||
moveIndexFirstRow():void
Changes the selectedIndex to the first row of the dataProvider. | ListBase | ||
moveIndexLastRow():void
Changes the selectedIndex to the last row of the dataProvider. | ListBase | ||
moveIndexNextRow():void
Changes the selectedIndex to the next row of the dataProvider. | ListBase | ||
moveIndexPreviousRow():void
Changes the selectedIndex to the previous row of the dataProvider. | ListBase | ||
notifyStyleChangeInChildren(styleProp:String, recursive:Boolean):void
Propagates style changes to the children. | UIComponent | ||
owns(child:DisplayObject):Boolean
Returns true if the chain of owner properties
points from child to this UIComponent. | UIComponent | ||
parentChanged(p:DisplayObjectContainer):void
Called by Flex when a UIComponent object is added to or removed from a parent. | UIComponent | ||
prepareToPrint(target:IFlexDisplayObject):Object
Prepares an IFlexDisplayObject for printing. | UIComponent | ||
regenerateStyleCache(recursive:Boolean):void
Builds or rebuilds the CSS style cache for this component
and, if the recursive parameter is true,
for all descendants of this component as well. | UIComponent | ||
registerEffects(effects:Array):void
For each effect event, registers the EffectManager
as one of the event listeners. | UIComponent | ||
removeStyleClient(styleClient:IAdvancedStyleClient):void
Removes a non-visual style client from this component instance. | UIComponent | ||
replayAutomatableEvent(event:Event):Boolean
Replays the specified event. | UIComponent | ||
resolveAutomationIDPart(criteria:Object):Array
Resolves a child by using the id provided. | UIComponent | ||
resumeBackgroundProcessing():void [static]
Resumes the background processing of methods
queued by callLater(), after a call to
suspendBackgroundProcessing(). | UIComponent | ||
setActualSize(w:Number, h:Number):void
Sizes the object. | UIComponent | ||
setButtonEnabled(labelValue:String, enabledValue:Boolean, fieldName:String):void
Allows changing the enabled property of a the child ButtonBarbutton's. | ButtonBarBase | ||
setButtonsEnabled(labelValues:Array, enabledValue:Boolean, fieldName:String):void
Allows changing the enabled property of several child ButtonBarbutton's. | ButtonBarBase | ||
setConstraintValue(constraintName:String, value:*):void
Sets a layout constraint value, which is the same as
setting the constraint style for this component. | UIComponent | ||
setCurrentState(stateName:String, playTransition:Boolean = true):void
Set the current state. | UIComponent | ||
setFocus():void
Sets the focus to this component. | UIComponent | ||
setLayoutBoundsPosition(x:Number, y:Number, postLayoutTransform:Boolean = true):void
Sets the coordinates that the element uses to draw on screen. | UIComponent | ||
setLayoutBoundsSize(width:Number, height:Number, postLayoutTransform:Boolean = true):void
Sets the layout size of the element. | UIComponent | ||
setLayoutMatrix(value:Matrix, invalidateLayout:Boolean):void
Sets the transform Matrix that is used to calculate the component's layout
size and position relative to its siblings. | UIComponent | ||
setLayoutMatrix3D(value:Matrix3D, invalidateLayout:Boolean):void
Sets the transform Matrix3D that is used to calculate the component's layout
size and position relative to its siblings. | UIComponent | ||
setMXMLDescriptor(value:Array):void | UIComponent | ||
setMXMLProperties(value:Array):void | UIComponent | ||
setSelectedIndex(rowIndex:int, dispatchChangeEvent:Boolean = false, changeCaret:Boolean = true):void
The rowIndex is the index in the data provider
of the item containing the selected cell.
| ListBase | ||
setStyle(styleProp:String, newValue:*):void
Sets a style property on this component instance. | UIComponent | ||
setVisible(value:Boolean, noEvent:Boolean = false):void
Called when the visible property changes. | UIComponent | ||
styleChanged(styleProp:String):void
Detects changes to style properties. | UIComponent | ||
stylesInitialized():void
Flex calls the stylesInitialized() method when
the styles for a component are first initialized. | UIComponent | ||
suspendBackgroundProcessing():void [static]
Blocks the background processing of methods
queued by callLater(),
until resumeBackgroundProcessing() is called. | UIComponent | ||
toString():String [override]
Returns a string indicating the location of this object
within the hierarchy of DisplayObjects in the Application. | FlexSprite | ||
transformAround(transformCenter:Vector3D, scale:Vector3D = null, rotation:Vector3D = null, translation:Vector3D = null, postLayoutScale:Vector3D = null, postLayoutRotation:Vector3D = null, postLayoutTranslation:Vector3D = null, invalidateLayout:Boolean = true):void
A utility method to update the rotation, scale, and translation of the
transform while keeping a particular point, specified in the component's
own coordinate space, fixed in the parent's coordinate space. | UIComponent | ||
transformPointToParent(localPosition:Vector3D, position:Vector3D, postLayoutPosition:Vector3D):void
A utility method to transform a point specified in the local
coordinates of this object to its location in the object's parent's
coordinates. | UIComponent | ||
updateRenderer(renderer:IVisualElement, itemIndex:int, data:Object):void
Updates an item renderer for use or reuse. | SkinnableDataContainer | ||
validateDisplayList():void
Validates the position and size of children and draws other
visuals. | UIComponent | ||
validateNow():void
Validate and update the properties and layout of this object
and redraw it, if necessary. | UIComponent | ||
validateProperties():void
Used by layout logic to validate the properties of a component
by calling the commitProperties() method. | UIComponent | ||
validateSize(recursive:Boolean = false):void
Validates the measured size of the component
If the LayoutManager.invalidateSize() method is called with
this ILayoutManagerClient, then the validateSize() method
is called when it's time to do measurements. | UIComponent | ||
validationResultHandler(event:ValidationResultEvent):void
Handles both the valid and invalid events from a
validator assigned to this component. | UIComponent | ||
verticalGradientMatrix(x:Number, y:Number, width:Number, height:Number):Matrix
Returns a box Matrix which can be passed to drawRoundRect()
as the rot parameter when drawing a vertical gradient. | UIComponent |
This component uses skins made up of skin parts. Do not set the skin parts directly. The component's skin sets the skin parts.
Skin Part | Description | Defined By | ||
---|---|---|---|---|
Required: false Part Type: Static An optional skin part that defines the DataGroup in the skin class where data items get pushed into, rendered, and laid out. | SkinnableDataContainer | |||
firstButton:IFactory | Required: false Part Type: Dynamic A skin part that defines the first button. The IFactory must return an object of type IVisualElement | ButtonBar | ||
lastButton:IFactory | Required: false Part Type: Dynamic A skin part that defines the last button. The IFactory must return an object of type IVisualElement | ButtonBar | ||
middleButton:IFactory | Required: true Part Type: Dynamic A skin part that defines the middle button(s). The IFactory must return an object of type IVisualElement | ButtonBar |
To skin the component, implement a skin that defines the following states. Although you must implement all skin states, a skin state can be empty. An empty skin state specifies no changes to the default skin state.
ButtonBar | () | Constructor |
public function ButtonBar()
Language Version : | ActionScript 3.0 |
Product Version : | Flex 4 |
Runtime Versions : | Flash Player 10, AIR 1.5 |
Constructor.
<?xml version="1.0"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- Simple example to demonstrate the Spark ButtonBar --> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"> <fx:Style> @namespace "library://ns.adobe.com/flex/spark"; ButtonBar ToggleButton:upAndSelected, ButtonBar ToggleButton:overAndSelected, ButtonBar ToggleButton:downAndSelected, ButtonBar ToggleButton:disabledAndSelected { chromeColor: #663366; color: #9999CC; } ButtonBar { chromeColor: #9999CC; color: #663366; } </fx:Style> <fx:Script> <![CDATA[ import spark.events.IndexChangeEvent; private function changeSelection(event:IndexChangeEvent): void { selectionText.text = "Selected Item: " + ButtonBar(event.target).selectedItem; } ]]> </fx:Script> <s:Panel title="Spark ButtonBar Example" width="75%" height="75%" horizontalCenter="0" verticalCenter="0"> <s:Label text="Select an item below:" x="10" y="15" /> <s:ButtonBar id="viewMenu" requireSelection="true" x="10" y="40" width="320" change="changeSelection(event)"> <s:dataProvider> <s:ArrayCollection source="['Home', 'Rooms', 'Dining']" /> </s:dataProvider> </s:ButtonBar> <s:Label x="10" y="75" id="selectionText" /> </s:Panel> </s:Application>