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.
Comments
3 responses to “Flex Chronicles #8: backgroundColor”
>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.
How? This doesn’t work:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
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"
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>
Apparently that’s true only of the Application container.