Q:

Flex 4 Change Main Application Background Color at Runtime

Is it possible within Flex 4 to change the background color of an <s:Application> at runtime? I've seen examples of how to do this with the MX version of the Application component, but not the spark version.
I cannot bind the backgroundColor property to a variable and modify that. However, I am thinking that I should use the styleManager property of the component to perform this change.
Could anyone explain how to do this?
Thank you for your time.

A:

I recommend you go through this:
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7fee.html
The video tutorial steps through using CSS and using skins in Flex 4 which are the primary means of changing visual components.
Application has a backgroundColor style still:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/Application.html
<?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"
               creationComplete="application1_creationCompleteHandler(event)">
    <s:layout>
        <s:HorizontalLayout/>
    </s:layout>
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                setStyle('backgroundColor',0xCCCCCC);
            }

        ]]>
    </fx:Script>
    <s:Button click="setStyle('backgroundColor','0xff0000');" label="turn red"/>
    <s:Button click="setStyle('backgroundColor','0x0000ff');" label="turn blue"/>
    <s:Button click="setStyle('backgroundColor','0x00ff00');" label="turn green"/>
</s:Application>

A Better way to go IMO
<?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">
    <s:layout>
        <s:HorizontalLayout/>
    </s:layout>
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace mx "library://ns.adobe.com/flex/mx";
        s|Application{
            backgroundColor:#CCCCCC;
        }
    </fx:Style>
    <s:Button click="setStyle('backgroundColor','0xff0000');" label="turn red"/>
    <s:Button click="setStyle('backgroundColor','0x0000ff');" label="turn blue"/>
    <s:Button click="setStyle('backgroundColor','0x00ff00');" label="turn green"/>
</s:Application>

Better still pull the CSS out into it's own file and just reference it with a
<fx:Style source="myStyle.css"/>

