Flex Chronicles #8: backgroundColor

This style has mad significance. First, if you don’t set it on most containers, they won’t have a background. If they don’t have a background (fill/rect/what have you), you cannot use them as drop targets since there is nothing to detect a drop on.

Secondly, as you’ll see in my next post, if they don’t have a backgroundColor defined, they don’t draw one, so at runtime (at least as I’ve found), you can’t use setStyle(“backgroundColor”, 0xFF0000); there’s nothing there to color. I think by setting it at authortime, it draws a background, and from then on at runtime you can then use setStyle to color it.

3 Replies to “Flex Chronicles #8: backgroundColor”

  1. >if they don’t have a backgroundColor defined, they don’t draw one, so at runtime (at least as I’ve found), you can’t use setStyle(‘backgroundColor’, 0xFF0000);

    That’s not true, Jesse. You can set the backgroundColor at runtime even if one isn’t specified in the MXML definition.

  2. How? This doesn’t work:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml&quot;
    initialize="initApp();">
    <mx:Script>
    <![CDATA[

    function initApp():Void
    {
    setStyle("backgroundColor", 0xFF0000);
    }

    ]]>
    </mx:Script>
    <mx:Panel width="100%" height="100%">
    </mx:Panel>
    </mx:Application>

    But, this does:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml&quot;
    initialize="initApp();" backgroundColor="#0000FF">
    <mx:Script>
    <![CDATA[

    function initApp():Void
    {
    setStyle("backgroundColor", 0xFF0000);
    }

    ]]>
    </mx:Script>
    <mx:Panel width="100%" height="100%">
    </mx:Panel>
    </mx:Application>

Comments are closed.