Flex default bgcolor is it a color or an image?

Posted on July 22, 2006 | 12 comments

[lang_en]
By the docs it’s covered by an image, so its a color. Let me explain what I am getting at, I was reading Ted’s post on preloaders. If you download the source and run the code from a new project in Flex Builder 2 you get a background flicker. The flicker I am talking about is the Blue-ish defualt Flex application color. I was trying to figure out how the default blue-ish color background was showing up. As I didn’t change any code from the downloaded source code.

I found this information in the livedocs.

The Application container’s style uses an image as the default background image. This image obscures any background color settings that you might make. So, to make the value of the bgcolor property display properly, you must clear the Application container’s backgroundImage style property. To do this, you can set it to the value of a space character, as the following example shows:
Application { backgroundImage: ” “; }

No it is talking about the default background color setting being obscured by an image. But what doesn’t make sense is I tried setting the style backgroundImage: ” “; as stated above and it does not do anything.

What I had to do to get rid of the flicker was actually look at the HTML source of Ted’s example and compare to the one generated by my local Flex Builder 2 project. The difference was the “bgcolor” attribute. This attribute is set by the compile through a parameter ${bgcolor} in the index.template.html template. I tried to find the proper way to set some value in the application or the Flex Builder 2 project properties but couldn’t find anything. So to fix the flicker I ended up modifying the index.template.html, changing all ${bgcolor} with #ffffff.

To view it for your self take a look at:
Ted’s example link

Download source in new Flex Builder project link

You’ll see the bgcolor=”#ffffff” in Ted’s html and bgcolor=”#869ca7″.
[/lang_en]
[lang_zh]
靠着文件就是一个图片, 所以就有颜色。我的意思是说, 在preloaders,我看到Ted的评论。用Flex Builder
2而从新的项目下载来源和开始代码, 背景就会闪光。我所说的闪光就是Flex应用的缺省蓝色。我是想了解这缺省蓝色背景怎么出来,
我没有改过代码的任何部分。在livedocs,我找到这些。

应用的风格就是用图片为缺省背景的图片。这图片把你所定的背景颜色把水搅浑。所以为了使背景颜色表现好,
你必须除掉应用背景图片的样子。你需要把他定为space character。如下:
Application { backgroundImage: ” “; }

他是讲缺省背景颜色被图片把水搅浑。我一直不懂的就是我试过定背景图片为上述的例子, 但是没什么不同。所以为了取掉那个闪光,
我把Ted的HTML代码程序和当地Flex Builder
2的做个比较。不同在于属性。在index.template.html的${bgcolor}范围内属性就定的。我试过找在应用或者Flex
Builder 2一中合适的办法定好一些值量。为了修改闪光的问题我就在index.template.html内把所有的${bgcolor}改成#ffffff

自己看在:

Ted的例子

Flex Builder下载

在Tedçš„HTML你会看到bgcolor=”#ffffff”å’Œbgcolor=”#869ca7″。
[/lang_zh]

  • http://www.onflex.org Ted Patrick

    If you want to remove the background color do this:

    In Flex Builder:

    1. Right Click on the Project + Properties
    2. Click > Flex Compiler
    3. Add this line to the compiler arguments:

    -locale en_US -default-background-color #FFFFFF

    This will force the background SWF color to White or #FFFFFF.

    It is unfortunate but custom compiler options can only be set in the project not in MXML. :(

    I will note that in the next build.

    Ted :)

  • http://www.renaun.com Renaun Erickson

    Thanks, I was hoping it wasn’t a compiler argument.

  • http://www.onflex.org Ted Patrick

    The compiler argument will change the SWF header color, there are 2 proprties in the Application tag that can help here:

    The backgroundGradientColors array allow you to specify 2 colors to change the default background gradient. Adding the property below will create a vertical grey to white background

    backgroundGradientColors=”[#cccccc, #ffffff]”

    The other option is embedding an image as the background, you can use SWF, GIF, PNG, JPG for this.

    backgroundImage=”welcome.gif”

    Additionally if you specify the Embed 9 slice scale arguments you can control scaling of the image or SWF

    backgroundImage=”{backWelcomeImage}”

    With all these options you can make the background do just about anything you want to.

    Cheers,

    Ted :)

  • http://www.onflex.org Ted Patrick

    <mx:Script>
    <![CDATA[ [
    Embed(source="logowithborder.gif", scaleGridTop="5", scaleGridBottom="25", scaleGridLeft="5", scaleGridRight="25")]
    [Bindable]
    public var backWelcomeImage:Class;
    ]]>
    </mx:Script>

  • http://www.renaun.com Renaun Erickson

    See what I tried was to blank out the image, as it stated in the docs, and then have the backgroundGradientColors attribute color it in. But that did not work.

    I did not try making a transparent png as the backgroundImage to see if the backgroundGradientColors would come through.

    That scaleGridXxxx is cool to know, thx for the info.

  • http://- jacob

    how do you get an repeating background image in flex?
    and if you don’t want to repeat the background but set it in the center of the application?
    greetz me.

  • Romain

    Finally, how can I have a transparent background?
    I tried what the livedocs stated (add a style : Application { backgroundImage: ” “; } (….)
    To make your application’s background transparent, set the alpha property on the tag to 0) but that does not work.

    What I want to do is to have a div defined behind the SWF in HTML page, and then I want to see some parts of the div with the transparancy part of the SWF. But for the moment I just have white rectangular swf hidding the div… no transparency at all.

    Thanks for your help

  • http://www.renaun.com Renaun Erickson

    You’ll have to set the wmode=transparent on the HTML tag for it to be transparent over HTML elements.

    NOTE: There is a performance degrade when using wmode=transparent.

  • Chris Ellem

    Thanks Renaun and Ted!!!

    Useful and Informative Blog…

    Bye the way

    a transparent background image works a treat!

    Thanks Again

    Chris

  • blanco

    hey i got the background to change however i want it to be gradiant?? where do i put this?

    please help

  • http://www.renaun.com Renaun Erickson

    Use the backgroundGradientColors style attribute.

  • Sven

    And what brillant well educated engineer came up with the idea of locking defualt design features into the compiler in the first place?