ActionScript.org Flash, Flex and ActionScript Resources - http://www.actionscript.org/resources
Styling a dataGrid (the badly documented parts)
http://www.actionscript.org/resources/articles/955/1/Styling-a-dataGrid-the-badly-documented-parts/Page1.html
Mikael Wirén
Rich Media developer since back in -96. Prefered tools of war: -Flash -Flex -Director (still can´t get over Macromedias backstab)  
By Mikael Wirén
Published on November 24, 2009
 
Have you ever had to style a dataGrid?
Did you find it easy?
Well, i didn´t and spent four work days finding the information i needed to style the dataGrid just so.
Now i´ve tried to put all the tricky parts in one place to make your search a little easier.

Background

I´ve recently done a nice little thingy in flash 8 (don´t ask).

As usual when using components, there are some things you want to customize, like coloring, borders and such.

I for one don´t find skinning very easy to manage. I´m a code mokey for crying out loud.

So i decided to roll with styling the component instead easy peasy or so i thought. The documentation should tell me how to do it. Yeah right!

I had forgotten how many un truths are in those pages.

 

Now i´ve spent some four work days trying to tap the internet resources about styling / skinning a flash 8 datagrid.

Let´s start by giving dues:
First stop. http://www.flashgamer.com  who has an old blogpost from 2006 about skinning the flash dataGrid.
http://www.flashgamer.com/2006/02/skinning_the_flash_datagrid.html


-Ah, ok, thats where you start!
I quickly realized this is way too much work for this budget.


-Hmmm...
I guess i need to rethink my strategy here.

-What to do?
Tell the client they have to roll with the basic look of the datagrid.

-Naaaah, too easy!
Wouldn´t feel right.

-Actually skin the component?
I gave this approach some research.
The datagrid component consists of a LOT of sub components.
There is the list component, the UIScrollbar component and the rectBorder component to name some.

The documentation is very vague about how to apply styles to the subcomponents. There is next to no information of what part does what.

Here you will find what i found during my extensive research and actually end up with a pretty customable component without having to skin it.

Along the way i had most help from a blog i think is discontinued. Last post is from 2008-01-10 but credits are due anyway. If you have information about the owner/ author, please let me know so i can thank her / him personaly.
http://www.nerdabilly.com
That blog has a post about scrollpane customization that to this day is the ONLY information about styling a scrollBar component i have found.
http://nerdabilly.com/blog/2006/09/26/on-scrollpane-or-scrollpian-customization/



Setting up the dataGrid

OK, let´s take this from the begining.

Put a dataGrid component in your library.

To add it to the stage manually, drag it to the stage and give it an instance name of myDg.

To do the same with code:

[as]import mx.controls.DataGrid;
var myDg:DataGrid;
myDg = createClassObject(mx.controls.DataGrid, "myDg", 10, {initObject.parameters});[/as]


Let´s start with the easy part, styling the grid.
For the brevity of this article i assume you know how to populate your grid.
Here is a good article on the subject anyway:
http://philflash.inway.fr/dgperf/index_en.html

This is what took me all those hours to put together

To style a dataGrid you can use one of three ways. Well do this somewhat backwards and start by looking at two ways to do it.
First you can use:


[as]myDg.backgroundColor = 0xeb0000;[/as]

or you can use:

 

[as]aGrid.setStyle(“backgroundColor”, “0xeb0000”);[/as]


to get this result:



A third way to apply styles to a data grid if you add it with code is:

[as]myDg = content_clip.createClassObject(mx.controls.DataGrid, "trackDg", 10, {backgroundColor:"0xeb0000", headerColor:"0xeb0000", color:"0xffffff", borderStyle:"solid", vGridLines:"false", borderColor:"0xff0000", rollOverColor:"0xff2929", selectionColor:"0xffffff", selectionDuration:"300", scrollTrackColor:"0xff0000", highlightColor:"0xffffff", shadowColor:"0xf2f2f2", symbolColor:"0xff0000"});[/as]


dataGrid properties
Well, that was easy.
Here is a list of the properties of the dataGrid component.

backgroundColor

Both

The background color, which can be set for the whole grid or for each column.

backgroundDisabledColor

Both

The background color when the component's enabled property is set to "false". The default value is 0xDDDDDD (medium gray).

borderStyle

Both

The DataGrid component uses a RectBorder instance as its border and responds to the styles defined on that class. See RectBorder class.

The default border style value is "inset".

headerColor

Both

The color of the column headers. The default value is 0xEAEAEA (light gray)

headerStyle

Both

A CSS style declaration for the column header that can be applied to a grid or column to customize the header styles.

color

Both

The text color. The default value is 0x0B333C for the Halo theme and blank for the Sample theme.

disabledColor

Both

The color for text when the component is disabled. The default color is 0x848384 (dark gray).

embedFonts

Both

A Boolean value that indicates whether the font specified in fontFamily is an embedded font. This style must be set to true if fontFamily refers to an embedded font. For example (using a DataGrid instance my_dg):

my_dg.setStyle("fontFamily", "yourFont");

my_dg.embedFonts=true;

Otherwise, the embedded font is not used. If this style is set to true and fontFamily does not refer to an embedded font, no text is displayed. The default value is false.

fontFamily

Both

The font name for text. The default value is "_sans".

fontSize

Both

The point size for the font. The default value is 10.

fontStyle

Both

The font style: either "normal" or "italic". The default value is "normal".

fontWeight

Both

The font weight: either "none" or "bold". The default value is "none". All components can also accept the value "normal" in place of "none" during a setStyle() call, but subsequent calls to getStyle() return "none".

textAlign

Both

The text alignment: either "left", "right", or "center". The default value is "left".

textDecoration

Both

The text decoration: either "none" or "underline". The default value is "none".

vGridLines

Both

A Boolean value that indicates whether to show vertical grid lines (true) or not (false). The default value is true.

hGridLines

Both

A Boolean value that indicates whether to show horizontal grid lines (true) or not (false). The default value is false.

vGridLineColor

Both

The color of the vertical grid lines. The default value is 0x666666 (medium gray).

hGridLineColor

Both

The color of the horizontal grid lines. The default value is 0x666666 (medium gray).


That takes you a bit of the way.

In the next section we will look at the really tricky part. Styling the scroll bar.

styling the scrollBar component

This far, we haven´t really stumbled into anything tricky, have we?
Of course not, i put it all together in the end.

Styling the scrollBar.
This part was what took me the most time to track down. And it´s not simple, netiher straight forward, but it´s definitely doable.
Even though i almost forgot how to do it, before writing this.

To be able to style the scrollbar we have to change skin it´s skin. Very logical isn´t it?
You can change skins on a component by drag/dropping the components assets in your library.
The search path to the "sample theme" skin we´re after is:

..\Macromedia\Flash 8\en\Configuration\ComponentFLA\sampleTheme.fla

screen shot of of theme to open in flash

and in the library there finding the folder scrollBar Assets under Themes/MMDefault


with that folder in your library you can access the following styles:


scrollTrackColor (sets the background color for the scrollbar)

highlightColor (sets the color of the buttons)

shadowColor (sets the “drop shadow” of the scrollbar items)

symbolColor (sets the color for the symbol in the buttons)


if you set

[as]lockRoot = true; [/as]

on the movieClip containing the dataGrid.
You should be good to go. With a custom fitted dataGrid.
Next round we do it with as3 instead.