Apr 24 2008
Styles + (Graphical Skins vs Programmatic Skins)
Styles provide a good additional layer of customization in Flex. If the available styles for a component do not meet your needs, then you re-skin the component using your own graphical or programmatic skins.
Styles and skins complement each other and more than that, you can’t have one without the other. The skins do the actual drawing, while the styles specify parameters on how to do the drawing.Here’s where we need to make the decision (programmatic vs graphical).
Using graphical skins is pretty simple, you set the skin styles to the graphic object ( a JPEG/GIF image, an SVG vector graphic, or an asset/symbol from a SWF file ). This can be done with css, mxml-inline or in actionscript.
The big downfall is that graphical skins do not support any customizations. Which is a big minus comparing to programmatic skinning.
For the programmatic skins you should take a look at the mx.skins.* package and the default halo skin package in flex sdk (mx.skins.halo.*). Here you will find how a component is drawn based on the style you set on it. The base class for a skin is mx.skins.ProgrammaticSkin which extends FlexShape. It provides the measuring, positioning, invalidation along with various graphic utilities.
Any skin extending this class should consist of a constructor (for an ActionScript class), an updateDisplayList() method, and a set of getters and setters for the skin’s properties. Extending ProgrammaticSkin is not a requirement, you can easily extend UIComponent and you can create both actionscript and mxml skins.
Here’s a short demo on using programmatic skins:
[Demo](right-click for source)
If you look at the code you’ll see that it’s very simple. It adds a rectangle, 2 borders and some custom styles to the button skin. You can step in deeper and create advanced skins, combine effects,filters,s.o.
All in one I encourage people to use programmatic skin, because it gives you great control over the looks of your application. And when you combine this with runtime css then sky is the limit.
Many people say that runtime css is not that useful since you need to compile it to a swf, but that is not a really a problem when you have the compiler available on many platforms. It’s not that hard to create a script that executes a simple command like “mxmlc myCss.css”. Or you can create your own css parser which also is not that difficult ( … wouldn’t be surprised if an open-source project for this is already out there ).
In any case, I’ll let you think about the possibilities when using programmatic skins.
Happy skinning !


