change background color of RadioButton in flex - apache-flex

I have a radio button in flex and wanna change background color of its text to some color
but I didn't find any solution for this problem.
EDIT :
NOTICE: I want some ( not all) of radio button with some conditions in a radio button group, have different color
Is there any solution for this?
EDIT :
code of my project
MyItemRenderer.mxml
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" dataChange="onDataChange()" >
<fx:Script><![CDATA[
import avmplus.constantXml;
import ir.fanap.bizint.ui.flex.event.MyAdvancedListEvent;
import ir.fanap.bizint.ui.flex.skin.MyRadioButtonSkin;
import mx.core.UIComponent;
private function onDataChange():void {
changeColorForMultiCube();
}
private function changeColorForMultiCube():void {
if (data['color'] != null ) {
box.setStyle("skinClass","MySkin");
}
else{
box.setStyle("SkinClass","RadioButtonSkin");//default skin for radio button
}
}
]]></fx:Script>
<s:states>
<s:State name="normal" />
<s:State name="hovered" />
<s:State name="selected" />
</s:states>
<s:RadioButton id="box" change="onDataChange()"/>
</s:ItemRenderer>
MySkin.mxml:
<?xml version="1.0" encoding="utf-8"?>
<fx:Metadata>
<![CDATA[
/**
* #copy spark.skins.spark.ApplicationSkin#hostComponent
*/
[HostComponent("spark.components.RadioButton")]
]]>
</fx:Metadata>
<fx:Script fb:purpose="styling">
/* Define the skin elements that should not be colorized.
For button, the graphics are colorized but the label is not. */
static private const exclusions:Array = ["labelDisplay", "dot"];
/**
* #private
*/
override public function get colorizeExclusions():Array {return exclusions;}
/* Define the symbol fill items that should be colored by the "symbolColor" style. */
static private const symbols:Array = ["dotFill"];
/**
* #private
*/
override public function get symbolItems():Array {return symbols};
/**
* #private
*/
override protected function initializationComplete():void
{
useChromeColor = true;
super.initializationComplete();
}
</fx:Script>
<fx:Script>
<![CDATA[
/**
* #private
*/
private static const focusExclusions:Array = ["labelDisplay"];
/**
* #private
*/
override public function get focusSkinExclusions():Array { return focusExclusions;};
]]>
</fx:Script>
<s:states>
<s:State name="up" />
<s:State name="over" stateGroups="overStates" />
<s:State name="down" stateGroups="downStates" />
<s:State name="disabled" stateGroups="disabledStates" />
<s:State name="upAndSelected" stateGroups="selectedStates" />
<s:State name="overAndSelected" stateGroups="overStates, selectedStates" />
<s:State name="downAndSelected" stateGroups="downStates, selectedStates" />
<s:State name="disabledAndSelected" stateGroups="disabledStates, selectedStates" />
</s:states>
<s:Rect width="{labelDisplay.width}" height="{labelDisplay.height}" left="18" right="0" top="3" bottom="3" verticalCenter="2">
<s:fill>
<s:SolidColor color="0xDAC1C3" />
</s:fill>
</s:Rect>
<s:Label id="labelDisplay"
textAlign="start"
verticalAlign="middle"
maxDisplayedLines="1"
left="18" right="0" top="3" bottom="3" verticalCenter="2" />
</s:SparkSkin>

I don't know about Flex 3 but in Flex 4, it can be done in the following way.
1) Create an MXML skin with HostComponent as spark.components.RadioButton.
2)Create a graphics Rect before labelDisplay of radio button, which is of same dimension & position as the labelDisplay is.
<s:Rect width="{labelDisplay.width}" height="{labelDisplay.height}" left="18" right="0" top="3" bottom="3" verticalCenter="2">
<s:fill>
<s:SolidColor color="0xDAC1C3" />
</s:fill>
</s:Rect>
<s:Label id="labelDisplay"
textAlign="start"
verticalAlign="middle"
maxDisplayedLines="1"
left="18" right="0" top="3" bottom="3" verticalCenter="2" />
3) Use this skin in the Spark RadioButton created in Application.
<s:RadioButton id="rdo" label="Programming in Actionscript" fontSize="20" x="100" y="100" skinClass="skinRdoBtn"/>

Here I am posting answer again for your ease. But I will request you to come out of your comfort level and search things. You will find many other important things in the process of finding your answer.
Below are the codes used.
Application.mxml
<?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" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
private var arrSource:Array = [{label:"Button1", color:0xDAC1C3},
{label:"Button2", color:0xDAC1C3},
{label:"Button3"}, {label:"Button4", color:0xDAC1C3}, {label:"Button5", color:0xDAC1C3},
{label:"Button6"}, {label:"Button7", color:0xDAC1C3}, {label:"Button8", color:0xDAC1C3},
{label:"Button9"},{label:"Button10", color:0xDAC1C3},{label:"Button11", color:0xDAC1C3}];
private var arrCol:ArrayCollection = new ArrayCollection(arrSource);
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:List id="lstBtns" dataProvider="{arrCol}" itemRenderer="MyItemRenderer">
</s:List>
</s:Application>
MyItemRenderer.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true" dataChange="onDataChange()">
<fx:Script><![CDATA[
import mx.core.UIComponent;
import spark.components.RadioButtonGroup;
import spark.skins.spark.RadioButtonSkin;
private static var rdoBtnGrp:RadioButtonGroup = new RadioButtonGroup();
private function onDataChange():void {
changeColorForMultiCube();
}
private function changeColorForMultiCube():void {
if (data['color'] != null ) {
box.setStyle("skinClass",MySkin2);
}
else{
box.setStyle("SkinClass",RadioButtonSkin);//default skin for radio button
}
}
]]></fx:Script>
<s:states>
<s:State name="normal" />
<s:State name="hovered" />
<s:State name="selected" />
</s:states>
<s:RadioButton id="box" change="onDataChange()" label="{data.label}" group="{rdoBtnGrp}"/>
</s:ItemRenderer>
MySkin2.mxml
Don't Delete anything which is pre-written when you are making skin unless you have specific reason to do so. I have added in this skin only Rect with id="bgColor" before the labelDisplay. The fill color is responsible for radio button's background color. If you want to set this color dynamic then you need to create a class extending RadioButton and define [SkinPart] there. Please see this and this
<!--
ADOBE SYSTEMS INCORPORATED
Copyright 2008 Adobe Systems Incorporated
All Rights Reserved.
NOTICE: Adobe permits you to use, modify, and distribute this file
in accordance with the terms of the license agreement accompanying it.
-->
<!--- The default skin class for a Spark RadioButton component.
#see spark.components.RadioButton
#see spark.components.RadioButtonGroup
#langversion 3.0
#playerversion Flash 10
#playerversion AIR 1.5
#productversion Flex 4
-->
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009" alpha.disabledStates="0.5">
<fx:Metadata>
<![CDATA[
/**
* #copy spark.skins.spark.ApplicationSkin#hostComponent
*/
[HostComponent("spark.components.RadioButton")]
]]>
</fx:Metadata>
<fx:Script fb:purpose="styling">
/* Define the skin elements that should not be colorized.
For button, the graphics are colorized but the label is not. */
static private const exclusions:Array = ["labelDisplay", "dot"];
/**
* #private
*/
override public function get colorizeExclusions():Array {return exclusions;}
/* Define the symbol fill items that should be colored by the "symbolColor" style. */
static private const symbols:Array = ["dotFill"];
/**
* #private
*/
override public function get symbolItems():Array {return symbols};
/**
* #private
*/
override protected function initializationComplete():void
{
useChromeColor = true;
super.initializationComplete();
}
</fx:Script>
<fx:Script>
<![CDATA[
/**
* #private
*/
private static const focusExclusions:Array = ["labelDisplay"];
/**
* #private
*/
override public function get focusSkinExclusions():Array { return focusExclusions;};
]]>
</fx:Script>
<s:states>
<s:State name="up" />
<s:State name="over" stateGroups="overStates" />
<s:State name="down" stateGroups="downStates" />
<s:State name="disabled" stateGroups="disabledStates" />
<s:State name="upAndSelected" stateGroups="selectedStates" />
<s:State name="overAndSelected" stateGroups="overStates, selectedStates" />
<s:State name="downAndSelected" stateGroups="downStates, selectedStates" />
<s:State name="disabledAndSelected" stateGroups="disabledStates, selectedStates" />
</s:states>
<s:Group verticalCenter="0" width="13" height="13">
<!-- drop shadow -->
<s:Ellipse left="-1" top="-1" right="-1" bottom="-1">
<s:stroke>
<s:LinearGradientStroke rotation="90" weight="1">
<s:GradientEntry color="0x000000"
color.downStates="0xFFFFFF"
alpha="0.011"
alpha.downStates="0" />
<s:GradientEntry color="0x000000"
color.downStates="0xFFFFFF"
alpha="0.121"
alpha.downStates="0.57" />
</s:LinearGradientStroke>
</s:stroke>
</s:Ellipse>
<!-- fill -->
<s:Ellipse left="1" top="1" right="1" bottom="1">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="0xFFFFFF"
color.overStates="0xBBBDBD"
color.downStates="0xAAAAAA"
alpha="0.85" />
<s:GradientEntry color="0xD8D8D8"
color.overStates="0x9FA0A1"
color.downStates="0x929496"
alpha="0.85" />
</s:LinearGradient>
</s:fill>
</s:Ellipse>
<!-- fill highlight -->
<s:Path data="M 1 6 Q 2 2 6 1 Q 11 2 12 6 h -9">
<s:fill>
<s:SolidColor color="0xFFFFFF" alpha="0.33" />
</s:fill>
</s:Path>
<!-- layer 6: highlight stroke (all states except down) -->
<s:Ellipse left="1" right="1" top="1" bottom="1">
<s:stroke>
<s:LinearGradientStroke rotation="90" weight="1">
<s:GradientEntry color="0xFFFFFF" color.downStates="0x939393" alpha.overStates="0.22" />
<s:GradientEntry color="0xD8D8D8" color.downStates="0xB1B1B1" alpha.overStates="0.22" />
</s:LinearGradientStroke>
</s:stroke>
</s:Ellipse>
<s:Rect left="5" top="1" right="5" height="1">
<s:fill>
<s:SolidColor color="0xFFFFFF"
color.downStates="0x939393"
alpha.overStates="0.22" />
</s:fill>
</s:Rect>
<!-- border - put on top of the fill so it doesn't disappear when scale is less than 1 -->
<s:Ellipse left="0" top="0" right="0" bottom="0">
<s:stroke>
<s:LinearGradientStroke rotation="90" weight="1">
<s:GradientEntry color="0x000000" alpha="0.70" />
<s:GradientEntry color="0x000000" alpha="0.80" />
</s:LinearGradientStroke>
</s:stroke>
</s:Ellipse>
<!-- dot -->
<!--- Defines the appearance of the RadioButton's dot. To customize the appearance of the dot, create a custom RadioButtonSkin class. -->
<s:Path left="4" top="4" includeIn="selectedStates" id="dot" itemCreationPolicy="immediate"
data="M 2.5 0 Q 4.5 0.5 5 2.5 Q 4.5 4.5 2.5 5 Q 0.5 4.5 0 2.5 Q 0.5 0.5 2.5 0">
<s:fill>
<!--- #private
Defines the appearance of the dot's fill. The default color is 0x000000. The default alpha is .9. -->
<s:SolidColor id="dotFill" color="0" alpha="0.9" />
</s:fill>
</s:Path>
<s:Path left="4" top="7" includeIn="selectedStates"
data="M 0 0 Q 0.5 2 2.5 2.0 Q 3.5 2.0 4 0">
<s:stroke>
<s:LinearGradientStroke>
<s:GradientEntry color="0xFFFFFF" alpha="0.3" />
<s:GradientEntry color="0xFFFFFF" alpha="0.7" />
<s:GradientEntry color="0xFFFFFF" alpha="0.3" />
</s:LinearGradientStroke>
</s:stroke>
</s:Path>
</s:Group>
<!-- Label -->
<!--- #copy spark.components.supportClasses.ButtonBase#labelDisplay -->
<s:Rect id="bgColor" left="18" right="0" top="3" bottom="3" verticalCenter="2"
>
<s:fill>
<s:SolidColor color="0xDAC1C3" />
</s:fill>
</s:Rect>
<s:Label id="labelDisplay"
textAlign="start"
verticalAlign="middle"
maxDisplayedLines="1"
left="18" right="0" top="3" bottom="3" verticalCenter="2" />
</s:SparkSkin>

Try like this
myRadBtnId.setStyle("backgroundColor","0x00FF00");
(or)
myRadBtnId.setStyle("backgroundColor", #E8E8E8);

Related

Set Application backgroundImage in flex 4.6

I am trying to set BackgroundImage of application in flex 4.6 By Creating Skin of Application.
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<!-- host component -->
<fx:Metadata>
[HostComponent("spark.components.Application")]
</fx:Metadata>
<!-- states -->
<s:states>
<s:State name="normal" />
<s:State name="disabled" />
<s:State name="normalWithControlBar" />
<s:State name="disabledWithControlBar" />
</s:states>
<s:Group id="backgroundRect" width="100%" height="100%">
<s:layout>
<s:VerticalLayout gap="0" horizontalAlign="justify" />
</s:layout>
<s:BitmapImage source="#Embed('assets/css/1.jpg')" left="0" right="0" top="0" bottom="0" scaleMode="stretch"/>
</s:Group>
</s:Skin>
It Display Background Image.but if i put any Component/Container in application then that Component/Container not Display on Application. Once i remove skin then only that Component/Container Display on Application.
Your custom skin does not have a Group called "contentGroup"
This is where Flex usually puts in all mxml-added components that should be displayed in a container.
Try adding:
<s:Group id='contentGroup' width='100%' height='100%' />
to your skin.
I think that will do.
In general it's often easier to take a copy of the original skin file and alter things in there rather than writing a new one. This way, you make sure, you don't forget anything important.
Here my app skin with a gradient background:
<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
alpha.disabledWithControlBar="0.5"
alpha.disabled="0.5">
<fx:Metadata>
<![CDATA[
[HostComponent("spark.components.Application")]
]]>
</fx:Metadata>
<fx:Script fb:purpose="styling">
<![CDATA[
import flash.filters.DropShadowFilter;
private static const W:uint = 700;
private static const H:uint = 525;
private static const COLORS:Array = [0xFFFFFF, 0xFFFFFF];
private static const ALPHAS:Array = [1, 0];
private static const RATIOS:Array = [0, 255];
private static const SHADOW:Array = [new DropShadowFilter(0, 0, 0x000000, 1.0, 12.0, 12.0, 1.0, 3, true)];
private var _matrix:Matrix = new Matrix();
private function drawBG(w:Number, h:Number):void {
_bgShading.graphics.clear();
_matrix.createGradientBox(w * 1.2, h * 2.2, 0, -w * 0.1, -h * 0.8);
_bgShading.graphics.beginGradientFill(GradientType.RADIAL,
COLORS,
ALPHAS,
RATIOS,
_matrix,
SpreadMethod.PAD,
InterpolationMethod.LINEAR_RGB,
0);
_bgShading.graphics.drawRect(0, 0, w, h);
_bgShading.graphics.endFill();
_bgShading.filters = SHADOW;
_bgTexture.graphics.clear();
_bgTexture.graphics.beginFill(0x99CC99);
_bgTexture.graphics.drawRect(0, 0, w, h);
_bgTexture.graphics.endFill();
_bgShading.blendMode = BlendMode.OVERLAY;
}
public function setBackgroundSize(w:uint=W, h:uint=H):void {
var screenRatio:Number = w / h;
var stageRatio:Number = stage.stageWidth / stage.stageHeight;
var ratio:Number = screenRatio / stageRatio;
// ratio > 1 if screen is broader than stage
mainGroup.width = stage.stageWidth * Math.max(1, ratio);
drawBG(mainGroup.width, H);
}
public function showBackground(b:Boolean):void {
_bgTexture.visible = b;
_bgShading.visible = b;
}
]]>
</fx:Script>
<s:states>
<s:State name="normal" />
<s:State name="disabled" />
<s:State name="normalWithControlBar" />
<s:State name="disabledWithControlBar" />
</s:states>
<mx:UIComponent id="_bgTexture" />
<mx:UIComponent id="_bgShading" />
<s:Group id="mainGroup" x="0" y="0" width="700" height="525">
<s:layout>
<s:VerticalLayout gap="0" horizontalAlign="justify" />
</s:layout>
<s:Group id="contentGroup" width="700" height="100%" minWidth="0" minHeight="0" />
<s:Group id="topGroup" minWidth="0" minHeight="0"
includeIn="normalWithControlBar, disabledWithControlBar" >
<s:Rect left="1" right="1" top="1" bottom="1" >
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="#66BBEE" />
<s:GradientEntry color="#3399CC" />
</s:LinearGradient>
</s:fill>
</s:Rect>
<s:Rect left="2" right="2" bottom="0" height="1" alpha="0.5">
<s:fill>
<s:SolidColor color="#333333" />
</s:fill>
</s:Rect>
<s:Group id="controlBarGroup" left="0" right="0" top="1" bottom="1" minWidth="0" minHeight="0">
<s:layout>
<s:HorizontalLayout paddingLeft="6" paddingRight="6" paddingTop="6" paddingBottom="6" gap="10" />
</s:layout>
</s:Group>
</s:Group>
</s:Group>
</s:Skin>

Hiding minimize button in fullscreen Flex

I have a Windowed application with a custom skin and the skin contains Title bar which too uses a custom skin. Now the problem is that I need to hide the minimize and maximize button dynamically if the window is set to full-screen. Please help...
my title bar skin code
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009" xmlns:mx="library://ns.adobe.com/flex/mx"
minHeight="24">
<fx:Metadata>
[HostComponent("spark.components.windowClasses.TitleBar")]
</fx:Metadata>
<s:states>
<s:State name="normal" />
<s:State name="disabled" />
<s:State name="normalAndMaximized" stateGroups="maximizedGroup" />
<s:State name="disabledAndMaximized" stateGroups="maximizedGroup" />
</s:states>
<!-- fill -->
<!--- Defines the background color of the skin. -->
<s:Rect id="background"
left="0" right="0" top="0" bottom="0">
<s:fill>
<s:LinearGradient>
<s:GradientEntry color="#2ecbd8"/>
<s:GradientEntry color="white" ratio="0.45"/>
<s:GradientEntry color="white" ratio="0.55"/>
<s:GradientEntry color="#2ecbd8"/>
</s:LinearGradient>
</s:fill>
</s:Rect>
<s:Group
id="contentGroup"
minHeight="24"
width="100%"
height="100%"
left="10"
right="10" >
<s:layout>
<s:HorizontalLayout verticalAlign="middle" horizontalAlign="center" gap="5" />
</s:layout>
<s:BitmapImage id="titleIconImage" minWidth="0" fillMode="clip"/>
<s:Label id="titleText" text="{hostComponent.title}" minWidth="0" fontSize="9" color="#585858" maxDisplayedLines="1" width="100%" />
<s:Button id="minimizeButton"
skinClass="spark.skins.spark.windowChrome.MinimizeButtonSkin"
top="2" bottom="2" verticalCenter="0"
/>
<s:Button id="maximizeButton"
skinClass="spark.skins.spark.windowChrome.MaximizeButtonSkin"
top="2" bottom="2" verticalCenter="0"
/>
<s:Button id="closeButton"
skinClass="spark.skins.spark.windowChrome.CloseButtonSkin"
verticalCenter="0" />
<fx:Script>
<![CDATA[
import spark.skins.spark.windowChrome.MaximizeButtonSkin;
]]>
</fx:Script>
</s:Group>
</s:SparkSkin>
my windowed application skin code
<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:ui="com.youspin.components.ui.*"
depth="-10">
<!-- host component -->
<fx:Metadata>
[HostComponent("spark.components.WindowedApplication")]
</fx:Metadata>
<!-- states -->
<s:states>
<s:State name="disabledAndInactive" />
<s:State name="normalAndInactive" />
<s:State name="disabled" />
<s:State name="normal" />
</s:states>
<s:TitleBar left="0" right="0" top="1"
title="YouSpin"
height="{0.067*height}"
skinClass="skins.titleSkin"/>
<s:Group id="contentGroup" left="0" top="0" right="0" bottom="0" />
</s:Skin>
this is my application
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
applicationComplete="fullScreen()"
width="910" height="728"
skinClass="skins.uiskin">
<fx:Declarations>
</fx:Declarations>
<fx:Script>
<![CDATA[
public function fullscreen():void{
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
//hide button from here but how??
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:WindowedApplication>
try making a bindable boolean somewhere, where you store the fullscreenstate. then minimizebutton should have attributes includeinLayout and visible binded to it. (and maximize would be the opposite:
<s:Button id="minimizeButton"
skinClass="spark.skins.spark.windowChrome.MinimizeButtonSkin"
top="2" bottom="2" verticalCenter="0"
visible="{!isFullScreen}"
/>

Flex mouse over area issue (custom button skin)

I created a custom button skin:
<?xml version="1.0" encoding="utf-8"?>
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="65" minHeight="22"
creationComplete="GlassButtonSkin_creationCompleteHandler(event)">
<fx:Metadata>[HostComponent("spark.components.Button")]</fx:Metadata>
<fx:Declarations>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.graphics.RadialGradient;
import spark.effects.Fade;
import spark.effects.animation.RepeatBehavior;
[Bindable]
private var rectRollOverEffect:Rect = new Rect();
private var radialGradientRollOverEffect:RadialGradient = new RadialGradient();
private var gradientEntryRollOverEffect1:GradientEntry = new GradientEntry(0x8dbdff,NaN,0.7);
private var gradientEntryRollOverEffect2:GradientEntry = new GradientEntry(0x8dbdff,NaN,0);
private var indexOfRollOverEffect:int;
private var myFade:Fade;
protected function GlassButtonSkin_creationCompleteHandler(event:FlexEvent):void{
parent.mouseChildren = true;
this.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler,true);
this.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHandler,true);
this.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandler,true);
this.addElement(rectRollOverEffect);
indexOfRollOverEffect = this.getElementIndex(rectRollOverEffect);
this.removeElementAt(indexOfRollOverEffect);
}
private function mouseOverHandler(event:MouseEvent):void{
if(this.currentState == "disabled")
return;
createRollOverEffect(event,0);
myFade = new Fade(this.getElementAt(indexOfRollOverEffect));
myFade.alphaFrom = 0;
myFade.alphaTo = 1;
myFade.duration = 200;
myFade.end();
myFade.play();
}
private function mouseMoveHandler(event:MouseEvent):void{
if(this.currentState == "disabled")
return;
this.removeElementAt(indexOfRollOverEffect);
createRollOverEffect(event,1);
}
private function mouseOutHandler(event:MouseEvent):void{
if(this.currentState == "disabled")
return;
this.removeElementAt(indexOfRollOverEffect);
}
private function createRollOverEffect(event:MouseEvent,alpha:int):void{
rectRollOverEffect.alpha = alpha;
rectRollOverEffect.left = 2;
rectRollOverEffect.right = 2;
rectRollOverEffect.bottom = 2;
rectRollOverEffect.top = 2;
rectRollOverEffect.radiusX = 4;
rectRollOverEffect.radiusY = 4;
radialGradientRollOverEffect.entries = [gradientEntryRollOverEffect1,gradientEntryRollOverEffect2];
radialGradientRollOverEffect.x = event.localX;
radialGradientRollOverEffect.y = height-2;
radialGradientRollOverEffect.scaleX = width/1.5;
radialGradientRollOverEffect.scaleY = height;
rectRollOverEffect.fill = radialGradientRollOverEffect;
this.addElementAt(rectRollOverEffect,indexOfRollOverEffect);
}
]]>
</fx:Script>
<s:states>
<s:State name="up"/>
<s:State name="over"/>
<s:State name="down"/>
<s:State name="disabled"/>
</s:states>
<s:transitions>
<s:Transition fromState="over" toState="disabled">
<s:CallAction target="{this}" functionName="removeElement" args="{[this.rectRollOverEffect]}"/>
</s:Transition>
</s:transitions>
<!-- outer border -->
<s:Rect left="0" right="0" top="0" bottom="0" id="outerBorder" radiusX="4" radiusY="4">
<s:stroke>
<s:SolidColorStroke id="outerBorderStroke" weight="1" color="#ffffff" />
</s:stroke>
</s:Rect>
<!-- inner border -->
<s:Rect left="1" right="1" top="1" bottom="1" id="innerBorder" radiusX="4" radiusY="4">
<s:stroke>
<s:SolidColorStroke id="innerBorderStroke" weight="1" color="#000000"/>
</s:stroke>
</s:Rect>
<!-- fill -->
<!--- Defines the appearance of the Button component's background. -->
<s:Rect id="background" left="1" right="1" top="1" bottom="1">
<s:fill>
<s:SolidColor alpha="0.5" color="#000000"/>
</s:fill>
</s:Rect>
<s:Rect id="backgroundTopPart" left="1" right="1" top="1" height="50%"
includeIn="up,over,disabled">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="#ffffff" alpha="0.5" ratio="0.1"/>
<s:GradientEntry color="#ffffff" alpha="0.1"/>
</s:LinearGradient>
</s:fill>
</s:Rect>
<s:Label id="labelDisplay"
text="Send"
textAlign="center"
verticalAlign="middle"
color="#FFFFFF"
horizontalCenter="0" verticalCenter="1"
left="10" right="10" top="2" bottom="2">
</s:Label>
<s:Rect id="disableForeground" left="0" right="0" top="0" bottom="0"
includeIn="disabled">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="#7B7B7B" alpha="0.6" ratio="0.1"/>
<s:GradientEntry color="#aaaaaa" alpha="0.3"/>
</s:LinearGradient>
</s:fill>
</s:Rect>
</s:SparkSkin>
The problem is that my hitarea seems to be wrong. When I click, it is OK, the area is right but with the mouse over event, the area seems to be different and smaller than the click area. I just don't understand why.
I even tried to change manually the hit area of the button skin by adding a line this.hitArea = this.interactiveGroup Where interactiveGroup is a group that contains the component borders but it didn't change anything.
I think its to do with you labelDisplay element of the skin. It has a right and left of 10.... if the right and left are set to 0, then the effect appears straight off, withough being too small.

How can you display a multi-line column header using the Flex Spark Data Grid?

How can you display a multi-line column header using the Flex Spark Data Grid for Flex 4.5?
To expand upon Constantiner's answer, you'll have to create a custom HeaderRenderer and set the Label's maxDisplayedLines to 2. Here's a sample renderer I found:
MyRenderer.mxml
<?xml version="1.0" encoding="utf-8"?>
<!--
ADOBE SYSTEMS INCORPORATED
Copyright 2010 Adobe Systems Incorporated
All Rights Reserved.
NOTICE: Adobe permits you to use, modify, and distribute this file
in accordance with the terms of the license agreement accompanying it.
-->
<!---
The DefaultGridHeaderRenderer class defines the default header renderer
for the columns of a Spark DataGrid control.
<p>Subclasses defined in MXML can redefine the values of the <code>labelDisplay</code>
and <code>sortIndicator</code> properties.</p>
#see spark.components.DataGrid
#see spark.components.GridColumnHeaderGroup
#see spark.components.gridClasses.GridItemRenderer
#langversion 3.0
#playerversion Flash 10
#playerversion AIR 2.0
#productversion Flex 4.5
-->
<s:GridItemRenderer minWidth="21" minHeight="21"
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>
<!--- The default value of the <code>sortIndicator</code> property.
It must be an IFactory for an IVisualElement.
<p>This value is specified in a <code>fx:Declaration</code> block and can be overridden
by a declaration with <code>id="defaultSortIndicator"</code>
in an MXML subclass.</p>
#langversion 3.0
#playerversion Flash 10
#playerversion AIR 2.0
#productversion Flex 4.5
-->
<fx:Component id="defaultSortIndicator">
<s:Path data="M 3.5 7.0 L 0.0 0.0 L 7.0 0.0 L 3.5 7.0" implements="spark.components.gridClasses.IGridVisualElement">
<fx:Script>
<![CDATA[
import spark.components.DataGrid;
import spark.components.Grid;
/**
* #private
*/
public function prepareGridVisualElement(grid:Grid, rowIndex:int, columnIndex:int):void
{
const dataGrid:DataGrid = grid.dataGrid;
if (!dataGrid)
return;
const color:uint = dataGrid.getStyle("symbolColor");
arrowFill1.color = color;
arrowFill2.color = color;
}
]]>
</fx:Script>
<s:fill>
<s:RadialGradient rotation="90" focalPointRatio="1">
<!--- #private -->
<s:GradientEntry id="arrowFill1" color="0" alpha="0.6" />
<!--- #private -->
<s:GradientEntry id="arrowFill2" color="0" alpha="0.8" />
</s:RadialGradient>
</s:fill>
</s:Path>
</fx:Component>
<!--- Displays the renderer's label property, which is set to the column's <code>headerText</code>.
It must be an instance of a <code>TextBase</code>, like <code>s:Label</code>.
<p>This visual element is added to the <code>labelDisplayGroup</code> by the renderer's
<code>prepare()</code> method. Any size/location constraints specified by the labelDisplay
define its location relative to the labelDisplayGroup.</p>
<p>This value is specified with a <code>fx:Declaration</code> and can be overridden
by a declaration with <code>id="labelDisplay"</code>
in an MXML subclass.</p>
#langversion 3.0
#playerversion Flash 10
#playerversion AIR 2.0
#productversion Flex 4.5
-->
<s:Label id="labelDisplay"
verticalCenter="1" left="0" right="0" top="0" bottom="0"
textAlign="start"
fontWeight="bold"
verticalAlign="middle"
maxDisplayedLines="2"
showTruncationTip="true" />
</fx:Declarations>
<fx:Script>
<![CDATA[
import spark.components.gridClasses.IGridVisualElement;
import mx.core.IVisualElement;
import spark.components.DataGrid;
import spark.components.GridColumnHeaderGroup;
import spark.components.gridClasses.GridColumn;
/**
* #private
*/
private function dispatchChangeEvent(type:String):void
{
if (hasEventListener(type))
dispatchEvent(new Event(type));
}
//----------------------------------
// maxDisplayedLines
//----------------------------------
private var _maxDisplayedLines:int = 1;
[Bindable("maxDisplayedLinesChanged")]
[Inspectable(minValue="-1")]
/**
* The value of this property is used to initialize the
* <code>maxDisplayedLines</code> property of this renderer's
* <code>labelDisplay</code> element.
*
* #copy spark.components.supportClasses.TextBase#maxDisplayedLines
*
* #default 1
*
* #langversion 3.0
* #playerversion Flash 10
* #playerversion AIR 1.5
* #productversion Flex 4.5
*/
public function get maxDisplayedLines():int
{
return _maxDisplayedLines;
}
/**
* #private
*/
public function set maxDisplayedLines(value:int):void
{
if (value == _maxDisplayedLines)
return;
_maxDisplayedLines = value;
if (labelDisplay)
labelDisplay.maxDisplayedLines = value;
invalidateSize();
invalidateDisplayList();
dispatchChangeEvent("maxDisplayedLinesChanged");
}
//----------------------------------
// sortIndicator
//----------------------------------
private var _sortIndicator:IFactory;
private var sortIndicatorInstance:IVisualElement;
[Bindable("sortIndicatorChanged")]
/**
* A visual element that's displayed when the column is sorted.
*
* <p>The sortIndicator visual element is added to the <code>sortIndicatorGroup</code>
* by this renderer's <code>prepare()</code> method. Any size/location constraints
* specified by the sortIndicator define its location relative to the sortIndicatorGroup.</p>
*
* #default null
*
* #langversion 3.0
* #playerversion Flash 10
* #playerversion AIR 1.5
* #productversion Flex 4.5
*/
public function get sortIndicator():IFactory
{
return (_sortIndicator) ? _sortIndicator : defaultSortIndicator;
}
/**
* #private
*/
public function set sortIndicator(value:IFactory):void
{
if (_sortIndicator == value)
return;
_sortIndicator = value;
if (sortIndicatorInstance)
{
sortIndicatorGroup.includeInLayout = false;
sortIndicatorGroup.removeElement(sortIndicatorInstance);
sortIndicatorInstance = null;
}
invalidateDisplayList();
dispatchChangeEvent("sortIndicatorChanged");
}
/**
* #private
* Create and add the sortIndicator to the sortIndicatorGroup and the
* labelDisplay into the labelDisplayGroup.
*/
override public function prepare(hasBeenRecycled:Boolean):void
{
super.prepare(hasBeenRecycled);
if (labelDisplay && labelDisplayGroup && (labelDisplay.parent != labelDisplayGroup))
{
labelDisplayGroup.removeAllElements();
labelDisplayGroup.addElement(labelDisplay);
}
const column:GridColumn = this.column;
if (sortIndicator && column && column.grid && column.grid.dataGrid && column.grid.dataGrid.columnHeaderGroup)
{
const dataGrid:DataGrid = column.grid.dataGrid;
const columnHeaderGroup:GridColumnHeaderGroup = dataGrid.columnHeaderGroup;
if (columnHeaderGroup.isSortIndicatorVisible(column.columnIndex))
{
if (!sortIndicatorInstance)
{
sortIndicatorInstance = sortIndicator.newInstance();
sortIndicatorGroup.addElement(sortIndicatorInstance);
}
// Initialize sortIndicator
sortIndicatorInstance.visible = true;
const gridVisualElement:IGridVisualElement = sortIndicatorInstance as IGridVisualElement;
if (gridVisualElement)
gridVisualElement.prepareGridVisualElement(column.grid, -1, column.columnIndex);
sortIndicatorGroup.includeInLayout = true;
sortIndicatorGroup.scaleY = (column.sortDescending) ? 1 : -1;
}
else
{
if (sortIndicatorInstance)
{
sortIndicatorGroup.removeElement(sortIndicatorInstance);
sortIndicatorGroup.includeInLayout = false;
sortIndicatorInstance = null;
}
}
}
}
]]>
</fx:Script>
<s:states>
<s:State name="normal" />
<s:State name="hovered" />
<s:State name="down" />
</s:states>
<!-- layer 1: shadow -->
<!--- #private -->
<s:Rect id="shadow" left="-1" right="-1" top="-1" bottom="-1" radiusX="2">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="0x000000"
color.down="0xFFFFFF"
alpha="0.01"
alpha.down="0" />
<s:GradientEntry color="0x000000"
color.down="0xFFFFFF"
alpha="0.07"
alpha.down="0.5" />
</s:LinearGradient>
</s:fill>
</s:Rect>
<!-- layer 2: fill -->
<!--- #private -->
<s:Rect id="fill" left="0" right="0" top="0" bottom="0">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="0xFFFFFF"
color.hovered="0xBBBDBD"
color.down="0xAAAAAA"
alpha="0.85" />
<s:GradientEntry color="0xD8D8D8"
color.hovered="0x9FA0A1"
color.down="0x929496"
alpha="0.85" />
</s:LinearGradient>
</s:fill>
</s:Rect>
<!-- layer 3: fill lowlight -->
<!--- #private -->
<s:Rect id="lowlight" left="0" right="0" top="0" bottom="0">
<s:fill>
<s:LinearGradient rotation="270">
<s:GradientEntry color="0x000000" ratio="0.0" alpha="0.0627" />
<s:GradientEntry color="0x000000" ratio="0.48" alpha="0.0099" />
<s:GradientEntry color="0x000000" ratio="0.48001" alpha="0" />
</s:LinearGradient>
</s:fill>
</s:Rect>
<!-- layer 4: fill highlight -->
<!--- #private -->
<s:Rect id="highlight" left="0" right="0" top="0" bottom="0">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="0xFFFFFF"
ratio="0.0"
alpha="0.33"
alpha.hovered="0.22"
alpha.down="0.12"/>
<s:GradientEntry color="0xFFFFFF"
ratio="0.48"
alpha="0.33"
alpha.hovered="0.22"
alpha.down="0.12" />
<s:GradientEntry color="0xFFFFFF"
ratio="0.48001"
alpha="0" />
</s:LinearGradient>
</s:fill>
</s:Rect>
<!-- layer 5: highlight stroke (all states except down) -->
<!--- #private -->
<s:Rect id="highlightStroke" left="0" right="0" top="0" bottom="0" excludeFrom="down">
<s:stroke>
<s:LinearGradientStroke rotation="90" weight="1">
<s:GradientEntry color="0xFFFFFF" alpha.hovered="0.22" />
<s:GradientEntry color="0xD8D8D8" alpha.hovered="0.22" />
</s:LinearGradientStroke>
</s:stroke>
</s:Rect>
<!-- layer 6: highlight stroke (down state only) -->
<!--- #private -->
<s:Rect id="hldownstroke1" left="0" right="0" top="0" bottom="0" includeIn="down">
<s:stroke>
<s:LinearGradientStroke rotation="90" weight="1">
<s:GradientEntry color="0x000000" alpha="0.25" ratio="0.0" />
<s:GradientEntry color="0x000000" alpha="0.25" ratio="0.001" />
<s:GradientEntry color="0x000000" alpha="0.07" ratio="0.0011" />
<s:GradientEntry color="0x000000" alpha="0.07" ratio="0.965" />
<s:GradientEntry color="0x000000" alpha="0.00" ratio="0.9651" />
</s:LinearGradientStroke>
</s:stroke>
</s:Rect>
<!--- #private -->
<s:Rect id="hldownstroke2" left="1" right="1" top="1" bottom="1" includeIn="down">
<s:stroke>
<s:LinearGradientStroke rotation="90" weight="1">
<s:GradientEntry color="0x000000" alpha="0.09" ratio="0.0" />
<s:GradientEntry color="0x000000" alpha="0.00" ratio="0.0001" />
</s:LinearGradientStroke>
</s:stroke>
</s:Rect>
<s:HGroup left="7" right="7" top="5" bottom="5" gap="8" verticalAlign="middle">
<s:BitmapImage source="54.gif" />
<!-- layer 7: Container for labelDisplay:TextBase -->
<!--- Defines the size and location of the labelDisplay visual element.
<p>The <code>labelDisplay</code> is added to this Group by the renderer's
<code>prepare()</code> method. Any size/location constraints
specified by the labelDisplay
define its layout relative to the labelDisplayGroup.</p>
#langversion 3.0
#playerversion Flash 10
#playerversion AIR 2.0
#productversion Flex 4.5
-->
<s:Group id="labelDisplayGroup" width="100%" />
<!-- layer 8: Container for sortIndicator:IVisualElement -->
<!--- Defines the size and location of the sortIndicator visual element.
<p>The <code>sortIndicator</code> is added to this Group by the renderer's
<code>prepare()</code> method. Any size/location constraints specified
by the sortIndicator
define its layout relative to the sortIndicatorGroup. This Group is only
included in the layout when the sortIndicator is visible.</p>
#langversion 3.0
#playerversion Flash 10
#playerversion AIR 2.0
#productversion Flex 4.5
-->
<s:Group id="sortIndicatorGroup" includeInLayout="false" />
</s:HGroup>
</s:GridItemRenderer>
And then to use it in your DataGrid, just follow Constantiner's example:
<s:DataGrid>
<s:columns>
<s:ArrayList>
<s:GridColumn headerRenderer="MyRenderer" />
</s:ArrayList>
</s:columns>
</s:DataGrid>
Try to use custom headerRenderer the following way:
<s:DataGrid>
<s:columns>
<s:ArrayList>
<s:GridColumn headerRenderer="MyRenderer" />
</s:ArrayList>
</s:columns>
</s:DataGrid>
The sample renderer with single-line header can be founded here {flex4.5 SDK root}/frameworks/projects/spark/src/spark/skins/spark/DefaultGridHeaderRenderer.mxml.
I do not see headerRenderer property of GridColumn in the sdk I am using so I could not accept the other answers. Here was my solution:
MultiLineColumnHeaderRenderer.mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
autoDrawBackground="true">
<fx:Script>
<![CDATA[
import spark.components.supportClasses.GridColumn;
]]>
</fx:Script>
<s:TextArea editable="false" text="{(data as GridColumn).headerText}" />
</s:ItemRenderer>
An init function in the view with the datagrid:
public function init():void{
dataGrid.columnHeaderBar.firstItemRenderer = new ClassFactory(MultiLineColumnHeaderRenderer);
dataGrid.columnHeaderBar.itemRenderer = new ClassFactory(MultiLineColumnHeaderRenderer);
}
And using 
 in the headerText for the GridColumn:
<s:GridColumn headerText="Line1
Line2
Line2"/>
Make a copy of the DataGridSkin and place it in your source code. Then Edit Line 154 to this -
<fx:Component id="headerRenderer">
<s:DefaultGridHeaderRenderer maxDisplayedLines="2"/>
</fx:Component>
Hope this helps,
Rich
You have to do this:
-Create a custom SparkDatagrid Skin creating a copy of the default one
-Create a custom DataGrid HeaderRenderer
-Just create a new GridItemRenderer (A) and put the code of the default DataGridHeaderRenderer inside the new GridItemRenderer (A)
-Go into the label "labelDisplay" inside A and change its property "maxDisplayedLines" from 1 to 2
-Now return to you custom Spark Satagrid Skin and search for the "headerRenderer" component.
-Replace it with an instance of your custom GridItemRender (A)
It worked for me...hope will do the same for you
mARCO
Or,
if you don't want to create a new Renderer just for 1 propertie, you can just set the propertie like this :
...
<s:GridColumn width="100" dataField="myDataField" headerText="myHeaderText">
<s:headerRenderer>
<fx:Component>
<s:DefaultGridHeaderRenderer maxDisplayedLines="2" />
</fx:Component>
</s:headerRenderer>
</s:GridColumn>
...
if you look at the code inside the DefaultGridHeaderRenderer component, you'll see that when set, it change the value in the labelDisplay
But, if you have a lot of columns, and it can be boring to put the same code a lot of time, just create a new component which extends the spark Datagrid (or nests it depending of your need), then put the code :
public function set columns(value:IList):void
{
for each (var gridColumn:GridColumn in value.toArray())
{
var headerRenderer:ClassFactory = new ClassFactory(DefaultGridHeaderRenderer);
headerRenderer.properties = {maxDisplayedLines: 2};
gridColumn.headerRenderer = headerRenderer;
}
_columns = value;
}
[Bindable]
public function get columns():IList
{
return _columns;
}

Difficulty creating animated skin in Flex 4

I have been tasked with creating the equivalent Flex 4 implementation of graphical style of the buttons found on this page:
http://h.dwighthouse.com/temp/UDOP/2011-3-25_themeDevGlowing/
Namely, the animated glowing effect on the buttons. I've gotten what I think is the appropriate programmatic gradient-based skin basis, but I have two problems.
One, I can't get any mouse events to respond in the skin. I can't seem to find others with this problem. In the below code, startAnimation is never getting called when a mouse over occurs, but the event is apparently getting registered. To test this code, simply add skinClass="ButtonSkin" to a button declaration in your main application, the code below being the ButtonSkin.mxml file.
<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
initialize="init()"
mouseEnabled="true">
<fx:Metadata>
[HostComponent("spark.components.Button")]
</fx:Metadata>
<fx:Script>
<![CDATA[
import flash.events.Event;
[Bindable]
private var animatedAlpha:Number = 0.8;
private var animationDirection:Number = -1;
private function backAndForth(value:Number, max:Number, min:Number, increment:Number):Number {
value += (animationDirection * increment);
if (value < min || value > max)
{
animationDirection *= -1;
value += (animationDirection * increment * 2);
}
return value;
}
private function startAnimation(e:MouseEvent):void {
animatedAlpha = backAndForth(animatedAlpha, 0.8, 0.3, 0.1); // Or something
systemManager.addEventListener(MouseEvent.MOUSE_OUT, endAnimation);
}
private function endAnimation(e:MouseEvent):void {
animatedAlpha = backAndForth(animatedAlpha, 0.8, 0.3, 0.1); // Or something
systemManager.removeEventListener(MouseEvent.MOUSE_OUT, endAnimation);
}
private function init():void {
parent.mouseChildren = true; // Otherwise mouse events don't fire in the skin
clickableArea.addEventListener(MouseEvent.MOUSE_OVER, startAnimation);
}
]]>
</fx:Script>
<s:states>
<s:State name="up" />
<s:State name="over" />
<s:State name="down" />
<s:State name="disabled" />
</s:states>
<s:Group top="0" bottom="0" left="0" right="0" id="clickableArea">
<s:Rect top="0" bottom="0" left="0" right="0" radiusX="8" radiusY="8">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="#000000" color.down="#bb0000" color.disabled="#3b3b3b" ratio="0" />
<s:GradientEntry color="#353535" color.down="#ff0000" color.disabled="#555555" ratio="1" />
</s:LinearGradient>
</s:fill>
</s:Rect>
<s:Rect top="0" bottom="0" left="0" right="0" radiusX="8" radiusY="8">
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color.over="#8f1b1b" alpha="0" ratio="0" />
<s:GradientEntry color.over="#8f1b1b" alpha="0" ratio="0.4" />
<s:GradientEntry color.over="#8f1b1b" alpha="{animatedAlpha}" alpha.down="0" ratio="1" />
</s:LinearGradient>
</s:fill>
</s:Rect>
<s:Rect top="0" bottom="0" left="0" right="0" radiusX="8" radiusY="8">
<s:stroke>
<s:SolidColorStroke color="#000000" color.disabled="#333333" weight="1" />
</s:stroke>
<s:fill>
<s:LinearGradient rotation="90">
<s:GradientEntry color="#ffffff" color.disabled="#9e9e9e" alpha="0.6" alpha.down="0.7" ratio="0" />
<s:GradientEntry color="#ffffff" color.disabled="#848484" alpha="0.2" alpha.down="0.4" ratio="0.45" />
<s:GradientEntry color="#ffffff" alpha="0" ratio="0.46" />
</s:LinearGradient>
</s:fill>
</s:Rect>
<s:Label id="labelDisplay" color="#ffffff" color.disabled="#aaaaaa" textAlign="center" baseline="center" paddingTop="7" paddingBottom="5" paddingLeft="10" paddingRight="10">
<s:filters>
<s:DropShadowFilter distance="0" angle="45" blurX="5" blurY="5" />
</s:filters>
</s:Label>
</s:Group>
EDIT I found out why mouse events weren't firing. The button apparently has mouseChildren false by default, which specifically prevents events from firing lower than itself. Using parent.mouseChildren = true; in the constructor fixes this issue. On to the next part of the question: continuous animation.
Other than that, I'd appreciate some help or point me in the right direction of calling a function every frame, and the ability to turn said incremental call on and off using mouse events. (If that's not how you animate in Flex, forgive me, I know nothing about Flash-based animation.) Thanks!
Answers to both questions have been found:
Buttons prevent their children (including Skins) from receiving mouse events. By setting parent.mouseChildren = true; in the skin's initializing function, mouse events are received normally.
Turns out you can animate in Flex (Actionscript) the same way you animate in Javascript: setInterval and clearInterval.

Resources