套件 | spark.components |
類別 | public class ToggleButton |
繼承 | ToggleButton ToggleButtonBase ButtonBase SkinnableComponent UIComponent FlexSprite Sprite DisplayObjectContainer InteractiveObject DisplayObject EventDispatcher Object |
子類別 | AXMToggleButton, ButtonBarButton |
語言版本: | ActionScript 3.0 |
產品版本: | Flex 4 |
執行階段版本: | Flash Player 10, AIR 1.5 |
Because this component does not define a skin for the mobile theme, Adobe recommends that you not use it in a mobile application. Alternatively, you can define your own mobile skin for the component. For more information, see Basics of mobile skinning. |
The ToggleButton component defines a toggle button. Clicking the button toggles it between the up and an down states. If you click the button while it is in the up state, it toggles to the down state. You must click the button again to toggle it back to the up state.
You can get or set this state programmatically
by using the selected
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.
The ToggleButton control has the following default characteristics:
Characteristic | Description |
---|---|
Default size | Wide enough to display the text label of the control |
Minimum size | 21 pixels wide and 21 pixels high |
Maximum size | 10000 pixels wide and 10000 pixels high |
Default skin class | spark.skins.spark.ToggleButtonSkin |
The <s:ToggleButton>
tag inherits all of the tag
attributes of its superclass and adds no tag attributes:
<s:ToggleButton/>
預設 MXML 屬性label
更多範例
相關 API 元素
公用方法
方法 | 定義自 | ||
---|---|---|---|
Constructor. | ToggleButton | ||
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
會在 EventDispatcher 物件註冊事件偵聽程式,以便讓偵聽程式收到事件的通知。 | EventDispatcher | ||
Adds a non-visual style client to this component instance. | UIComponent | ||
指出安全性限制是否會造成傳回的清單 (可用指定的 point 點呼叫 DisplayObjectContainer.getObjectsUnderPoint() 方法來取得) 省略任何顯示物件。 | DisplayObjectContainer | ||
Queues a function to be called later. | UIComponent | ||
Deletes a style property from this component instance. | UIComponent | ||
判斷指定的顯示物件是否為 DisplayObjectContainer 實體的子系,或為實體本身。 | DisplayObjectContainer | ||
Converts a Point object from content coordinates to global coordinates. | UIComponent | ||
Converts a Point object from content to local coordinates. | UIComponent | ||
Returns a set of properties that identify the child within
this container. | UIComponent | ||
Returns a set of properties that identify the child within
this container. | UIComponent | ||
Creates an id reference to this IUIComponent object
on its parent document object. | UIComponent | ||
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 | ||
[覆寫]
Dispatches an event into the event flow. | UIComponent | ||
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 | ||
Called by the effect instance when it stops playing on the component. | UIComponent | ||
Called by the effect instance when it starts playing on the component. | UIComponent | ||
Ends all currently playing effects on the component. | UIComponent | ||
Executes all the bindings for which the UIComponent object is the destination. | UIComponent | ||
Called after printing is complete. | UIComponent | ||
Provides the automation object at the specified index. | UIComponent | ||
Provides the automation object list . | UIComponent | ||
傳回可定義顯示物件區域 (相對於 targetCoordinateSpace 物件的座標系統) 的矩形。 | DisplayObject | ||
Returns the x coordinate of the element's bounds at the specified element size. | UIComponent | ||
Returns the y coordinate of the element's bounds at the specified element size. | UIComponent | ||
傳回具有指定名稱的子顯示物件。 | DisplayObjectContainer | ||
Finds the type selectors for this UIComponent instance. | UIComponent | ||
Returns a layout constraint value, which is the same as
getting the constraint style for this component. | UIComponent | ||
A convenience method for determining whether to use the
explicit or measured height
| UIComponent | ||
A convenience method for determining whether to use the
explicit or measured width
| UIComponent | ||
Gets the object that currently has focus. | UIComponent | ||
Returns the element's layout height. | UIComponent | ||
Returns the element's layout width. | UIComponent | ||
Returns the x coordinate that the element uses to draw on screen. | UIComponent | ||
Returns the y coordinate that the element uses to draw on screen. | UIComponent | ||
Returns the transform matrix that is used to calculate the component's
layout relative to its siblings. | UIComponent | ||
Returns the layout transform Matrix3D for this element. | UIComponent | ||
Returns the element's maximum height. | UIComponent | ||
Returns the element's maximum width. | UIComponent | ||
Returns the element's minimum height. | UIComponent | ||
Returns the element's minimum width. | UIComponent | ||
傳回位於指定點底下,且屬於此 DisplayObjectContainer 實體之子系 (或孫系,以下類推) 的物件陣列。 | DisplayObjectContainer | ||
Returns the element's preferred height. | UIComponent | ||
Returns the element's preferred width. | UIComponent | ||
根據 targetCoordinateSpace 參數所定義的座標系統,並排除形狀上的任何筆畫,傳回可定義顯示物件邊界的矩形。 | DisplayObject | ||
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 | ||
Gets a style property that has been set anywhere in this
component's style lookup chain. | UIComponent | ||
Converts a Point object from global to content coordinates. | UIComponent | ||
將 point 物件從「舞台」(全域) 座標轉換成顯示物件的 (區域) 座標。 | DisplayObject | ||
將二維點從「舞台」(全域) 座標轉換為三維顯示物件的 (區域) 座標。 | DisplayObject | ||
Returns true if currentCSSState is not null. | UIComponent | ||
會檢查 EventDispatcher 物件是否有對特定的事件類型註冊偵聽程式。 | EventDispatcher | ||
指出物件是否有已定義的指定屬性。 | Object | ||
Determines whether the specified state has been defined on this
UIComponent. | UIComponent | ||
評估顯示物件的範圍框,看它是否與 obj 顯示物件的範圍框重疊或相交。 | DisplayObject | ||
評估顯示物件,看它是否與 x 和 y 參數所指定的點重疊或相交。 | DisplayObject | ||
Returns a box Matrix which can be passed to the
drawRoundRect() method
as the rot parameter when drawing a horizontal gradient. | UIComponent | ||
Initializes the internal structure of this component. | UIComponent | ||
Initializes various properties which keep track of repeated instances
of this component. | UIComponent | ||
Marks a component so that its updateDisplayList()
method gets called during a later screen update. | UIComponent | ||
Called by a component's items to indicate that their depth
property has changed. | UIComponent | ||
An element must call this method when its layoutDirection changes or
when its parent's layoutDirection changes. | UIComponent | ||
Marks a component so that its commitProperties()
method gets called during a later screen update. | UIComponent | ||
Marks a component so that its measure()
method gets called during a later screen update. | UIComponent | ||
Marks the component so that the new state of the skin is set
during a later screen update. | SkinnableComponent | ||
指出 Object 類別的實體是否位於指定為參數的物件原型鏈中。 | Object | ||
將三維顯示物件的 (區域) 座標的三維點轉換為「舞台」(全域) 座標中的二維點。 | DisplayObject | ||
Converts a Point object from local to content coordinates. | UIComponent | ||
將 point 物件從顯示物件的 (區域) 座標轉換成「舞台」(全域) 座標。 | DisplayObject | ||
Returns true if cssState matches currentCSSState. | UIComponent | ||
Determines whether this instance is the same as, or is a subclass of,
the given type. | UIComponent | ||
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 | ||
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 | ||
Moves the component to a specified position within its parent. | UIComponent | ||
Propagates style changes to the children. | UIComponent | ||
Returns true if the chain of owner properties
points from child to this UIComponent. | UIComponent | ||
Called by Flex when a UIComponent object is added to or removed from a parent. | UIComponent | ||
Prepares an IFlexDisplayObject for printing. | UIComponent | ||
指出指定的屬性是否存在,以及是否可列舉。 | Object | ||
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 | ||
For each effect event, registers the EffectManager
as one of the event listeners. | UIComponent | ||
將所有 child DisplayObject 實體從 DisplayObjectContainer 實體的子清單中移除。 | DisplayObjectContainer | ||
會從 EventDispatcher 物件移除偵聽程式。 | EventDispatcher | ||
Removes a non-visual style client from this component instance. | UIComponent | ||
Replays the specified event. | UIComponent | ||
升起顯示虛擬鍵盤。 | InteractiveObject | ||
Resolves a child by using the id provided. | UIComponent | ||
[靜態]
Resumes the background processing of methods
queued by callLater(), after a call to
suspendBackgroundProcessing(). | UIComponent | ||
Sizes the object. | UIComponent | ||
Sets a layout constraint value, which is the same as
setting the constraint style for this component. | UIComponent | ||
Set the current state. | UIComponent | ||
Sets the focus to this component. | UIComponent | ||
Sets the coordinates that the element uses to draw on screen. | UIComponent | ||
Sets the layout size of the element. | UIComponent | ||
Sets the transform Matrix that is used to calculate the component's layout
size and position relative to its siblings. | UIComponent | ||
Sets the transform Matrix3D that is used to calculate the component's layout
size and position relative to its siblings. | UIComponent | ||
為迴圈作業設定動態屬性的可用性。 | Object | ||
Sets a style property on this component instance. | UIComponent | ||
Called when the visible property changes. | UIComponent | ||
讓使用者拖曳指定的 sprite。 | Sprite | ||
讓使用者將指定的 Sprite 拖曳至觸控裝置上。 | Sprite | ||
遞迴停止執行所有 MovieClips 的時間軸根源於此物件。 | DisplayObjectContainer | ||
結束 startDrag() 方法。 | Sprite | ||
結束觸控裝置使用的 startTouchDrag() 方法。 | Sprite | ||
Detects changes to style properties. | UIComponent | ||
Flex calls the stylesInitialized() method when
the styles for a component are first initialized. | UIComponent | ||
[靜態]
Blocks the background processing of methods
queued by callLater(),
until resumeBackgroundProcessing() is called. | UIComponent | ||
傳回代表此物件的字串,根據地區特定慣例進行格式化。 | Object | ||
[覆寫]
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 | ||
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 | ||
Validates the position and size of children and draws other
visuals. | UIComponent | ||
Validate and update the properties and layout of this object
and redraw it, if necessary. | UIComponent | ||
Used by layout logic to validate the properties of a component
by calling the commitProperties() method. | UIComponent | ||
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 | ||
Handles both the valid and invalid events from a
validator assigned to this component. | UIComponent | ||
會傳回指定之物件的基本值。 | Object | ||
Returns a box Matrix which can be passed to drawRoundRect()
as the rot parameter when drawing a vertical gradient. | UIComponent | ||
檢查此 EventDispatcher 物件是否已註冊事件偵聽程式,或者此物件的任何祖系已為特定事件類型註冊事件偵聽程式。 | EventDispatcher |
樣式
樣式可分為一般樣式及與特定主題關聯的樣式兩種。如果是一般樣式,可以與任何主題搭配使用。如果是與特定主題關聯的樣式,只有在您的應用程式使用特定主題時才能使用該樣式。
一般樣式
Spark 主題樣式
Mobile 主題樣式
外觀狀態
若要設定組件的外觀,請實作一個定義以下狀態的外觀。雖然您必須實作所有外觀狀態,不過外觀狀態可以空白。空白的外觀狀態會指定不對預設外觀狀態做任何變更。
建構函式詳細資料
ToggleButton | () | 建構函式 |
public function ToggleButton()
語言版本: | ActionScript 3.0 |
產品版本: | Flex 4 |
執行階段版本: | Flash Player 10, AIR 1.5 |
Constructor.
範例 如何使用本範例
ToggleButtonExample.mxml
<?xml version="1.0"?> <!-- Simple example to demonstrate the Spark ToggleButton control --> <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:Script> <![CDATA[ // Event handler function to print a message // describing the Spark ToggleButton selected state. // Toggle the fontWeight of the Label between bold and normal private function printMessage(evt:Event):void { if (evt.target.selected){ message.text += "fontWeight: bold" + "\n"; lbl.setStyle("fontWeight", "bold"); togBtn.label = "Bold"; } else{ message.text += "fontWeight: normal" + "\n"; lbl.setStyle("fontWeight", "normal"); togBtn.label = "Normal"; } } ]]> </fx:Script> <s:Panel title="Spark ToggleButton Control Example" width="75%" height="75%" horizontalCenter="0" verticalCenter="0"> <s:VGroup left="10" right="10" top="10" bottom="10"> <s:ToggleButton id="togBtn" label="Normal" click="printMessage(event);" /> <s:Label id="lbl" text="Label" /> <s:TextArea id="message" height="100%" width="100%" color="#0000FF" /> </s:VGroup> </s:Panel> </s:Application>
Tue Jun 12 2018, 03:47 PM Z