要做一个圆形按钮,在flex4里最直接的方法就是为button写一个皮肤。先看下样子:
下面是皮肤的代码:
<?xml version="1.0" encoding="utf-8"?>
<!--
round button
-->
<s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
minWidth="21" minHeight="21"
alpha.disabled="0.5">
<fx:Metadata>
<![CDATA[
[HostComponent("spark.components.Button")]
]]>
</fx:Metadata>
<fx:Script>
<![CDATA[
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
bg.width = bg.height = Math.max(unscaledWidth, unscaledHeight) - 2;
var cc:Number = Number(getStyle("chromeColor"));
if(isNaN(cc))
{
cc = 0xff0000;
}
bgFill.color = borderStroke.color = cc;
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
]]>
</fx:Script>
<!-- states -->
<s:states>
<s:State name="up" />
<s:State name="over" />
<s:State name="down" />
<s:State name="disabled" />
</s:states>
<!--背景-->
<s:Ellipse id="bg" width="100%" height="100%" left="1" right="1" top="1" bottom="1">
<s:fill>
<s:SolidColor id="bgFill" color="0xffffff" alpha=".6" alpha.over=".8" alpha.down="1"/>
</s:fill>
</s:Ellipse>
<!--边框-->
<s:Ellipse id="border" left="0" right="0" top="0" bottom="0">
<s:stroke>
<s:SolidColorStroke id="borderStroke" color="0" />
</s:stroke>
</s:Ellipse>
<!--文本-->
<s:Label id="labelDisplay"
textAlign="center"
maxDisplayedLines="1"
horizontalCenter="0" verticalCenter="1" verticalAlign="middle"
left="5" right="5" top="2" bottom="2">
</s:Label>
</s:SparkButtonSkin>
使用方式:
<?xml version="1.0" encoding="utf-8"?>
<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:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:VGroup>
<s:TextInput id="ti"/>
<mx:ColorPicker id="cp"/>
<s:Button skinClass="skins.RoundButtonSkin" label="{ti.text}" chromeColor="{cp.selectedColor}"/>
</s:VGroup>
</s:Application>
s:SparkButtonSkin是sdk4.5+才有的,之前的请改成s:SparkSkin

- 大小: 2.1 KB
- src.zip (1.9 KB)
- 描述: source code
- 下载次数: 43
分享到:
相关推荐
### FLEX4 皮肤制作教程知识点详解 #### 一、SparkSkin介绍 1. **基本概念**: - SparkSkin是Adobe Flex 4 (Gumbo)框架中的一个关键类,用于自定义用户界面(UI)组件的外观。它提供了一种机制,允许开发者通过...
在Flex框架中,我们可以使用各种组件和样式来创建美观的UI元素。渐变色和圆角效果的按钮是现代UI设计中常用的...掌握了这些知识点,开发者就可以在自己的Flex项目中实现个性化的按钮皮肤设计,从而提升应用的用户体验。
- Flex项目通常包括可视组件(如按钮、文本框等)和非可视组件(如数据源、数据绑定等)。 #### 三、Flex基础语法及Hello World - **基础语法:** Flex的基础语法主要涉及MXML和ActionScript的使用。MXML用于定义...
- **Button皮肤示例**: 展示按钮的不同状态(正常、禁用等)。 - **SkinnableDataContainer**: 支持皮肤的应用程序容器。 **知识点19:使用Adobe Flash Catalyst设置Flex应用程序外观** - **工具介绍**: Adobe ...