Flex中通过扩展LinkButtonSkin和添加自己的selectedUpSkin,selectedOverSkin,selectedDownSkin,selectedDisabledSkin设置LinkButton控件是否保持鼠标按下状态的例子
By Minidxer | September 7, 2008
一般按钮鼠标点下离开后,按下的状态 接下来的例子演示了Flex中如何通过扩展LinkButtonSkin和添加自己的selectedUpSkin,selectedOverSkin,selectedDownSkin,selectedDisabledSkin,设置LinkButton控件是否保持鼠标按下状态。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application name="LinkButton_toggle_test"
- xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
- <mx:ApplicationControlBar dock="true">
- <mx:Form styleName="plain">
- <mx:FormItem label="toggle:">
- <mx:CheckBox id="toggleCheckBox" />
- </mx:FormItem>
- <mx:FormItem label="selected:">
- <mx:CheckBox id="selectedCheckBox"
- selected="{linkButton.selected}" />
- </mx:FormItem>
- </mx:Form>
- </mx:ApplicationControlBar>
- <mx:LinkButton id="linkButton"
- label="LinkButton"
- toggle="{toggleCheckBox.selected}"
- selected="{selectedCheckBox.selected}"
- skin="skins.ToggleLinkButtonSkin" />
- </mx:Application>
下面是ToggleLinkButtonSkin.as的代码:
Download: main.mxml
- package {
- import mx.skins.halo.LinkButtonSkin;
- public class ToggleLinkButtonSkin extends LinkButtonSkin {
- public function ToggleLinkButtonSkin() {
- super();
- }
- override protected function updateDisplayList(w:Number, h:Number):void {
- super.updateDisplayList(w, h);
- var cornerRadius:Number = getStyle("cornerRadius");
- var rollOverColor:uint = getStyle("rollOverColor");
- var selectionColor:uint = getStyle("selectionColor");
- graphics.clear();
- switch (name) {
- case "upSkin":
- // Draw invisible shape so we have a hit area.
- drawRoundRect(
- 0, 0, w, h, cornerRadius,
- 0, 0);
- break;
- case "selectedUpSkin":
- case "selectedOverSkin":
- case "overSkin":
- drawRoundRect(
- 0, 0, w, h, cornerRadius,
- rollOverColor, 1);
- break;
- case "selectedDownSkin":
- case "downSkin":
- drawRoundRect(
- 0, 0, w, h, cornerRadius,
- selectionColor, 1);
- break;
- case "selectedDisabledSkin":
- case "disabledSkin":
- // Draw invisible shape so we have a hit area.
- drawRoundRect(
- 0, 0, w, h, cornerRadius,
- 0, 0);
- break;
- }
- }
- }
- }
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
Flex |
No Comments » |
Tags: LinkButton, LinkButtonSkin, selectedDisabledSkin, selectedDownSkin, selectedOverSkin, selectedUpSkin