Example: you have 2 types of buttons in you app - one with gradient fill and one with solid fill.
One way is to create GradientFillButtonSkin and SolidFillButtonSkin. Wouldn't it be nice to have only one skin and just fill it with what you wish to use - gradient or solid? You can!
<templatebutton>To accomplish this we define a custom class TemplateButton:
<fill><gradientcolor.../></fill>
</templatebutton>
TemplateButton extends Button {and in its respective skin class TemplateButtonSkin (which is probably a copy of spark ButtonSkin), you define a host component and a default fill:
...
[Bindable]
var buttonFill:IFill;
[HostComponent("TemplateButton")]Following this approach you can have with all types of fills: Solid, Linear, Radial, etc. and just use as following
<fx:declarations>
<s:lineargradient id="defaultButtonFill">
</s:lineargradient>
</fx:declarations>
...
<s:rect>
<s:fill>
{hostComponent.buttonFill!=null ? hostComponent.buttonFill : defaultButtonFill}
</s:fill>
</s:rect>
<templatebutton skinclass="TemplateButtonSkin">The same approach can be applied to strokes, (up, over, down states for fill and strokes), styles for text in the button and many others.
<fill>
<solidfill.../>
</fill>
0 comments:
Post a Comment