How to override the Spark theme in Flex 4? - css

What kind of styling is there in the default Spark theme in Flex 4?
And how to override the Spark theme? For example I want to provide another backgroundcolor and
nothing happens, the color css works as intended. The CSS looks like this:
<fx:Style>
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
#namespace local "*";
global
{
font-family: Georgia;
color: #260B01;
content-background-color: Red;
content-background-alpha: 0.8;
}
</fx:Style>

Hmm. This code works fine:
<?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:Style>
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
global {
font-family: Georgia;
color: #260B01;
content-background-color: Red;
content-background-alpha: 0.8;
}
</fx:Style>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
]]>
</fx:Script>
<s:List dataProvider="{new ArrayCollection(['First','Second'])}" />
</s:Application>
What did you expected and what is your result?

Related

flex: how do embed fonts in spark and mx?

My flex (4.5) application uses MX and Spark components.
I want to embed Arial fonts and I a mgetting crazy: it works for either Spark components, either for MX components but never for both.
Sometimes some components just diseappear, or both are bold etc !
<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" layout="absolute" xmlns:s="library://ns.adobe.com/flex/spark">
<mx:Style>
#namespace mx "library://ns.adobe.com/flex/mx";
#namespace s "library://ns.adobe.com/flex/spark";
#font-face {
src: url("c:/windows/fonts/arial.ttf");
fontFamily: Arial;
fontWeight:normal;
embed-as-cff: true;
}
#font-face {
src: local("Arial");
font-weight: normal;
fontFamily: Arial;
fontStyle:normal;
embed-as-cff:false;
}
#font-face {
src: local("Arial");
fontFamily: Arial;
fontWeight:bold;
fontStyle: normal;
embed-as-cff:false;
}
</mx:Style>
<mx:Label x="177" y="160" text="mx|normal"/>
<mx:Label x="177" y="201" fontWeight="bold" text="mx|bold"/>
<s:Label x="182" y="235" text="S|normal"/>
<s:Label x="182" y="278" text="S|bold" fontWeight="bold"/>
Remove the font styles that say: embedAsCFF: false and add the following:
mx|global {
textFieldClass: ClassReference("mx.core.UIFTETextField");
}
This will force all mx components that render text to use a textfield that can handle the CFF embedded fonts. It also has the advantage that you don't have to embed the same font twice.

Flex style inheriting issue when module include a chart

I meet a problem when migrate the application for flex 3.5 to flex 4.5. The char style cannot be apply correctly when set the style in application, it still use columnChart default style. But when I move the fx:Style declaration to ColumnchChartModule, the char style works. Could someone help me to explain why the style inheriting is broken?
BTW: the button style seems working, when I define a button style in application.
Below is my test code:
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Style>
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
.c01 {
fill: #0D7393;
areaFill: #0D7393;
}
.c02 {
fill: #A1B26B;
areaFill: #A1B26B;
}
.c03 {
fill: #C4843D;
areaFill: #C4843D;
}
.c04 {
fill: #5A4736;
areaFill: #5A4736;
}
.c05 {
fill: #994C34;
areaFill: #994C34;
}
.c06 {
fill: #649DA2;
areaFill: #649DA2;
}
.c07 {
fill: #D66D2B;
areaFill: #D66D2B;
}
.c08 {
fill: #C8E8B0;
areaFill: #C8E8B0;
}
.c09 {
fill: #6BB9D3;
areaFill: #6BB9D3;
}
mx|ColumnChart {
chartSeriesStyles: c01, c02, c03, c04, c05, c06, c07, c08, c09;
}
s|Button{
color: red;
}
</fx:Style>
<s:layout>
<s:VerticalLayout />
</s:layout>
<mx:ModuleLoader url="ColumnChartModule.swf" width="100%" height="100%"/>
---------------------------------------- ColumnChartModule.mxml
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%">
<fx:Script><![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var expenses:ArrayCollection = new ArrayCollection([
{Month:"Jan", Revenue:1200, Expenses:500},
{Month:"Feb", Revenue:1200, Expenses:550},
{Month:"Mar", Revenue:1240, Expenses:475},
{Month:"Apr", Revenue:1300, Expenses:600},
{Month:"May", Revenue:1420, Expenses:575},
{Month:"Jun", Revenue:1400, Expenses:600},
{Month:"Jul", Revenue:1500, Expenses:600},
{Month:"Aug", Revenue:1600, Expenses:750},
{Month:"Sep", Revenue:1600, Expenses:735},
{Month:"Oct", Revenue:1750, Expenses:750},
{Month:"Nov", Revenue:1800, Expenses:800},
{Month:"Dec", Revenue:2000, Expenses:850}
]);
private function onClick(): void{
var columnChart:CSSStyleDeclaration = this.styleManager.getStyleDeclaration("mx|ColumnChart");
var columnChart1:CSSStyleDeclaration = this.styleManager.getMergedStyleDeclaration("mx|ColumnChart");
var columnChart2:CSSStyleDeclaration = this.styleManager.getStyleDeclaration("s|Button");
trace(columnChart);
trace(columnChart1);
trace(columnChart2);
}
]]></fx:Script>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:Button label="GetChartStyle" click="onClick()" />
<s:Panel title="Floating Column Chart">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<mx:ColumnChart
dataProvider="{expenses}"
showDataTips="true">
<mx:horizontalAxis>
<mx:CategoryAxis
dataProvider="{expenses}"
categoryField="Month"/>
</mx:horizontalAxis>
<mx:series>
<mx:ColumnSeries
yField="Revenue"
displayName="Revenue"/>
<mx:ColumnSeries
yField="Expenses"
displayName="Expenses"/>
</mx:series>
</mx:ColumnChart>
</s:Panel>
On your module ie. MyCustomModule.mxml put this override code.
override public function get moduleFactory():IFlexModuleFactory{
return FlexGlobals.topLevelApplication.moduleFactory;
}

Is it possible to style a Spark Button like an old Halo Button? (with CSS only)

I think Adobe are messing with me, from all the docs and tutorials it seems like styling a simple button got much more difficult in Flex 4 (Spark). I used to be able to have my designer create the CSS as it wasn't too far off from web standard CSS. Now it seems like I need to make a skin first as outlined in this post?
Below is the old button style.
Button {
fontFamily: "Arial, Helvetica";
fontWeight: bold;
fontSize: 11px;
paddingTop: 0px;
paddingBottom: 0px;
highlightAlphas: 0.42, 0.13;
fillAlphas: 1, 1, 1, 1;
fillColors: #B9DEF8, #9AC3EB, #B9DEF8, #9AC3EB;
color: #477199;
textRollOverColor: #477199;
textSelectedColor: #3399cc;
borderStyle: none;
}
thanks!
Skinning the Spark Button would be a programmatic approach to which you could mimic the Halo mx:button very closely.
If you just wanted your application to use the Halo theme, you could use Halo theme.
It's also important to note mx:Button included things like icon, which Spark Button does not.
As you denote you want to use CSS only, you'll have to dive in to mx skin class at:
mx.skins.halo.ButtonSkin
Spark theme:
Halo theme:
Based upon your CSS for spark:
<?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:Style>
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
s|Button
{
fontFamily: "Arial, Helvetica";
fontWeight: bold;
fontSize: 11px;
paddingTop: 0px;
paddingBottom: 0px;
highlightAlphas: 0.42, 0.13;
fillAlphas: 1, 1, 1, 1;
fillColors: #B9DEF8, #9AC3EB, #B9DEF8, #9AC3EB;
color: #477199;
textRollOverColor: #477199;
textSelectedColor: #3399cc;
borderStyle: none;
}
</fx:Style>
<s:VGroup width="100%"
height="100%"
paddingTop="10"
paddingLeft="10">
<s:Button label="Hello, world!" />
<mx:Button label="Hello, world!" />
</s:VGroup>
</s:Application>
Yes, it is possible.
Check out the styles on the Spark Button to find out what can be modified using CSS.

Flex 3 css style on a mx:panel

I am trying to override the default panel style on Flex 3.
And the following doesn't work.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" minWidth="955" minHeight="600"
creationComplete="init();">
<mx:Style>
.panel {
borderAlpha: 1;
borderColor: white;
}
</mx:Style>
I got the style properties via here:
http://www.loscavio.com/downloads/blog/flex3_css_list/flex3_css_list.htm#Panel
Please kindly help. Thank you.
The style should be Panel{...} instead of ".panel"
<mx:Style>
Panel {
borderAlpha: 1;
borderColor: white;
}
Your identifier is wrong, try using 'Panel' instead of '.panel'.

Bug with embedding fonts in Flex - panel's title won't show up

Good morning,
I face a curious bug as I try to set a fontstyle in a mx:Panel object in Flex.
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
layout="absolute" title="Test"
titleStyleName="titleAssumed" >
<mx:Label x="0" y="-5" styleName="othersAssumed" />
<mx:Label x="0" y="16" styleName="othersAssumed"/>
The associated CSS file contains the following relevant styles:
/* CSS file */
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
#font-face{
src: url("ttf\\ControlSign Bold.ttf");
fontFamily: ControlSign;
fontWeight: bold;
}
#font-face{
src: url("ttf\\ControlMono Regular.ttf");
fontFamily: ControlMono;
}
.titleAssumed
{
fontFamily: ControlSign;
font-weight: bold;
font-size: 12;
color: #FFFFFF;
}
.othersAssumed
{
fontFamily: ControlMono;
font-size: 15;
color: #ADADAD;
}
With this configuration, and once I have set the compiler properties in Eclipse for the compiler to use the Flash text engine for MX components, I can see the two labels of the Panel in the correct font and style ; but the Panel's title will not show up. Even if I add the "embedAsCff: false" line to my style .titleAssumed, the title refuses to show up.
Any idea about what could be causing the trouble? Thanks !
EDIT: syntax error fixed.
You need to set embedAsCFF: true in your font. Also you have a syntax error where you are not closing your curly brackets on the fonts. Below is an example and here are some more.
#font-face{
src: url("ttf\\ControlSign Bold.ttf");
fontFamily: ControlSign;
fontWeight: bold;
embedAsCFF: true;
}

Resources