FLEX: is possible to use AreaStroke and AreaFill in a css file? - apache-flex

I would like to simplify my code and add the possible to the css file:
<mx:AreaSeries styleName="timeArea" name="A" yField="A" areaStroke="{new Stroke(0x0033CC, 2)}" areaFill="{new SolidColor(0x0033CC, 0.5)}" />
Can I move areaStroke and areaFill to css ? What would be the resulting css ?
thanks

So, while you can't specify the strokes in css, you can specify the properties of the strokes, ie:
<mx:Metadata>
[Style(name="areaFillColor",format="Color",type="Number)]
[Style(name="areaStrokeColor",format="Color",type="Number)]
</mx:Metadata>
<mx:Script>
<![CDATA[
[Bindable]
protected var strokeColor:Number;
[Bindable]
protected var fillColor:Number;
override public function styleChanged(styleProp:String):void{
super.styleChanged(styleProp);
//you really ought to do this in a switch statement
strokeColor = getStyle("areaStrokeColor");
fillColor = getStyle("areaFillColor");
}
]]>
</mx:Script>
<mx:AreaSeries styleName="timeArea" name="A" yField="A" areaStroke="{myStroke}" areaFill="{myFill}" />
<mx:SolidColor id="myFill" color="{fillColor}" alpha=".3"/>
<mx:Stroke id="s1" color="{strokeColor}" weight="2"/>
And your CSS would look like (where myAreaChart is the styleName set on the parent area chart):
.myAreaChart{
areaFillColor: #f3f3f3;
areaStrokeColor: #333333;
}

Related

Flex change css properties at runtime

I am developing one dashboard application in flex which is a replica of the flex dashboard. Here there are multiple Panels which are displaying different contents. What i want is whenever user clicks on any particular panel say for example "Yearly Revenues" then i just want to highlight that particular panel.
So basically all the panels in their initial state would be in "inactive" state but as soon as user clicks on it, it will become active providing user a better experience for knowing that he is working with "xyz" panel and remaining would go in inactive state.
So what i mean by "active" and "inactive" state is, in any HTML page when we hover over any Hyperlink it becomes "blue" ( for example ), so i will call it as active and inactive otherwise.
Now, talking about the panel.
The panel is having a skin which defines its layout. To fulfill my requirement what i tried is applying "css" to the panel. Now i have applied css in this way
public class Pod extends Panel
{
...properties
public function init():void
{
setStyle('styleName',"panelOff");
}
}
Now, in this class itself i am handling the "CLICK" on the panel. So in click event what i am doing basically is ,
setStyle('styleName',"panelOn");
Since, panel is having skin applied i need to change properties of the components contained in the skin. So that i must be able to access the css properties in the skin.
in skin file i am doing something like this
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
{
setStyle('border-alpha', hostComponent.getStyle('border-alpha'));
}
So my question is, is it the right way of fulfilling my requirement ?
How can i access the css properties of the hostcomponent in the skin
class ?
Here in my main.mxml i have defined the style file. So if
style file contains a style class named "panelOn" and if i give that
class to the panel so will it be able to access the styles associated
with that class ?
Please don't advice to put each and every css property using setStyle method of the panel because then there would be no advantage of using css file to me and also it would be bad css styling.
If there is any other better solution then please share your views. I hope i am clear. Anykind of help would be appreciated.
Best way for your requirement - use spark states. Panel component and Mxml skin, have two state: active and inactive (or your new states). Panel component has logic to set current skin state. If you want use css for keeping properties, each state apply own stylename for skin.
Main application:
<?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"
xmlns:classes="classes.*">
<fx:Style>
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
#namespace classes "classes.*";
classes|Pod
{
skinClass : ClassReference("skins.PodSkin");
}
.active
{
backgroundColor: #ff0000;
}
.inactive
{
backgroundColor: #00ff00;
}
</fx:Style>
<classes:Pod x="800" width="300" height="300" />
</s:Application>
Pod component:
package classes
{
import flash.events.MouseEvent;
import spark.components.Panel;
public class Pod extends Panel
{
private var _isActive:Boolean = false;
public function Pod()
{
super();
}
override protected function childrenCreated():void
{
super.childrenCreated();
addEventListener(MouseEvent.CLICK, onClickHandler, false, 0, true);
}
protected function onClickHandler(event:MouseEvent):void
{
_isActive = !_isActive;
invalidateSkinState();
}
override protected function getCurrentSkinState():String
{
if (_isActive) return "active";
return "inactive";
}
}
}
And part of PodSkin mxml skin where you set stylename for each states:
<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"
blendMode="normal" mouseEnabled="false"
styleName.active="active" styleName.inactive="inactive"
minWidth="131" minHeight="127" alpha.disabled="0.5" alpha.disabledWithControlBar="0.5">
<s:states>
<s:State name="normal" />
<s:State name="active" />
<s:State name="inactive" />
<s:State name="disabled" />
<s:State name="normalWithControlBar" stateGroups="withControls" />
<s:State name="disabledWithControlBar" stateGroups="withControls" />
</s:states>
Enjoy Flex

mx:Legend fontSize not working

I have a PieChart... now that I'm moving to support tablets as well, I need to make the fontSize of the legend larger. However, the following has no effect:
<mx:Legend dataProvider="{industryChart}"
height="110" bottom="40"
height.groupTablets="220" bottom.groupTablets="80"
fontSize="8" fontSize.groupTablets="16"
markerHeight="10" markerHeight.groupTablets="20"
verticalGap="3"
/>
I know that the state is correct because the other attributes change.
I've also tried adding a style section:
<fx:Style>
.legend {
fontSize:24;
}
</fx:Style>
<mx:Legend dataProvider="{industryChart}"
height="110" bottom="40"
height.groupTablets="220" bottom.groupTablets="80"
markerHeight="10" markerHeight.groupTablets="20"
verticalGap="3"
styleName="legend"
/>
No change. Nor does it work if I move the style to Main.css.
Using this gives a warning: CSS type selectors are not supported in components: 'mx.charts.LegendItem':
<fx:Style>
#namespace mx "library://ns.adobe.com/flex/mx";
mx|LegendItem {
fontSize:24;
}
</fx:Style>
But if I put the same in Main.css, it does work:
#namespace mx "library://ns.adobe.com/flex/mx";
mx|LegendItem {
fontSize:24;
}
The problem I have with that is that I have to be able to make the font larger when in the tablet state, and not just for all states, or the font will be too large on a phone.
Pseudo-selectors don't appear to work:
mx|LegendItem:groupTablets {
fontSize:24;
}
IDs do not work, in either Main.cc or fx:Style:
#pieLegend {
fontSize:24;
}
<mx:Legend id="pieLegend"
dataProvider="{industryChart}"
height="110" bottom="40"
height.groupTablets="220" bottom.groupTablets="80"
markerHeight="10" markerHeight.groupTablets="20"
verticalGap="3"
/>
However, even if that approach worked it would have difficulties when the code behind the mxml needs to reference a particular component by id.
I even got frustrated and tried this in the code:
pieLegend.setStyle("fontSize", 24);
Nope. Grrrr.
Any ideas?
Caught the same issue. Here's from the adobe forum, might have to wait for apache flex for a real fix:
The problem is based on a bug that was deferred ( http://bugs.adobe.com/jira/browse/FLEXDMV-1656). There are several workarounds, but the simplest is to set the fontSize on the LegendItem type selector, like this:
<mx:Style>
LegendItem {
fontSize:24;
}
</mx:Style>

How to hide axis lines with CSS?

How do I hide my axis lines with CSS? Shouldn't this work?
<mx:Style>
#namespace mx "library://ns.adobe.com/flex/mx";
mx|ColumnChart {
horizontalAxisStyleName: myAxisStyles;
verticalAxisStyleName: myAxisStyles;
}
.myAxisStyles { showLine: false; }
</mx:Style>
I also tried display: none.
Prior to this I used:
<mx:horizontalAxisRenderers>
<mx:AxisRenderer showLine="false" axis="{someName.horizontalAxis}" />
</mx:horizontalAxisRenderers>
<mx:verticalAxisRenderers>
<mx:AxisRenderer showLine="false" axis="{someName.verticalAxis}" />
</mx:verticalAxisRenderers>
But it produced some annoying warnings:
Data binding will not be able to detect assignments to "horizontalAxis".
Data binding will not be able to detect assignments to "verticalAxis".
Thanks!
In Flex 4.5 ,setting showLine:false thru CSS didn't work for me too. Later I found that the CartesianCharts takes an array not a string as an input for horizontalAxisStyleNames.Note it is not horizontalAxisStyleName, it is horizontalAxisStyleName*s*.I did a quick work around and the showLine property was applied to the chart. It may not seem meaningful, but I had no other choice and this works like a charm!
Code for your reference:
<fx:Style>
#namespace mx "library://ns.adobe.com/flex/mx";
#namespace s "library://ns.adobe.com/flex/spark";
mx|ColumnChart {
horizontalAxisStyleNames:myAxisStyles,myAxisStyles;
}
.myAxisStyles {
showLine:false;
}
</fx:Style>

Extending TextItem Class in Flex 4

I am trying to extend the TextItem class in Flex 4 but I keep getting the following error:
Could not resolve <custom:txtIdNumber> to a component implementation.
My txtIdNumber.as is as follows
package custom {
import spark.components.TextInput;
public class txtIdNumber extends TextInput {
public function txtIdNumber()
{
super();
}
override protected function width():void
{
super.width();
this.width = 100;
}
}
}
and the module I want to use it in looks like this
<?xml version="1.0" encoding="utf-8"?>
<mx:Module 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:custom="../custom.*"
layout="absolute" width="100%" height="100%">
<s:BorderContainer width="100%" height="100%" >
<custom:txtIdNumber />
</s:BorderContainer>
</mx:Module>
Initially I thought that I might be extending the class in the wrong way, but all the examples I found look the same.
Without knowing the structure of your source tree, my hunch is that the compiler is not able to parse the namespace you set for custom. Try it without the "../" and if that still doesn't work, post more details about your source tree structure, specifically where does your custom component live and where does the module code live relative to the top level "src" package. Your namespace should be relative to "src".

"Type DataGrid in CSS selector 'DataGrid' must be qualified with a namespace" warning when styling in Flex

I am attempting to style the headers in a flex datagrid and I keep getting the warning:
Type DataGrid in CSS selector 'DataGrid' must be qualified with a namespace
What does this mean? I have gone through a bunch of tutorials and none of them have worked. It seems like changing a the colors in a datagrid should be relatively simple.
Here is a code sample:
<mx:Style>
.headerCustomStyle
{
fontWeight: "bold";
textAlign: "center";
color: #0000FF;
}
DataGrid {
alternating-item-colors: #F4FBFF, #FFFFFF;
}
</mx:Style>
<mx:DataGrid draggableColumns="true" width="100%" id="topTracks" headerStyleName="headerCustomStyle" dataProvider="{_trackData.track}" >
<mx:columns>
<mx:DataGridColumn id="artistName" dataField="artist.name" headerText="Artist" width="250" />
<mx:DataGridColumn id="trackName" dataField="name" headerText="Track" width="250"/>
</mx:columns>
</mx:DataGrid>
If you're using Flex 4, you need to define namespaces like this:
#namespace mx "library://ns.adobe.com/flex/halo";
#namespace s "library://ns.adobe.com/flex/spark";
#namespace tlf "library://ns.adobe.com/flashx/textLayout";
/* Halo DataGrid */
mx|DataGrid
{
...
}
/* Spark Button */
s|Button
{
...
}
They might be referring to that if you're using a new version of Flex/Flash Builder. Not sure if Flex 3 requires namespaces though.
Here's Adobe's doc on CSS Namespace Support
If you're using Flex 4, you normally DO NOT use CSS at all.
You think I'm telling tales?
Well, read this:
http://www.adobe.com/content/dotcom/en/devnet/flex/articles/migrating-flex-apps-part2.html
Port your Flex 4 applications to CSS-free code and you won't have any of these problems.
I'm not sure why its telling you that you need a namespace, but in your CSS, DataGrid is a type.
So try and give it the fully qualified namespace for DataGrid (mx.controls.DataGrid)

Resources