actionscript behind mxml component properties

I was wondering how Flex implements certain properties in components that can be declared in the mxml but don’t show up in the ActionScript properties. For example, you can set the background color on a VBox in mxml but there is no corresponding backgroundColor in either the direct or inherited properties of VBox:

<mx:VBox width=”100%” backgroundColor=”#ffff80″ horizontalAlign=”center”>

My first guess was that this was being accomplished using CSS styles behind the scenes, so I set the -keep-generated-actionscript property on the compiler to be able to see the actual AS code that my application is writing to generate the mxml.

Here’s an excerpt of what I found:

propertiesFactory: function():Object { return {
childDescriptors: [
new mx.core.UIComponentDescriptor({
type: mx.containers.VBox
stylesFactory: function():void {
this.backgroundColor = 16777088;
this.horizontalAlign = “center”;

Ah, so it does look like CSS after all… ‘stylesFactory’… but that code isn’t terribly easy on my eyes!

So I guess the way to set something like the background color of a VBox on the fly in your AS code would be to use something like the styleName property of the component…

Leave a Reply