Flash Builder 4 / Flex,为Web应用设置透明背景?

时间:2010-08-04 16:33:21

标签: background flexbuilder transparent

我正在使用最新版本的swfobject.js将flex应用程序嵌入到网页中。我已经将wmode设置为透明,除了我为嵌入对象默认大小输入的所有内容之外,我的应用程序中都是白色背景。我已经将应用程序的backgroundAlpha设置为0,我知道该部分有效,因为我的aplication在完成加载后会调整大小。应用程序的已调整大小部分是透明的,但其余部分仍然具有白色背景,因此很明显它与应用程序有关,而不是嵌入它的html或javascript。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

查看默认的应用程序外观,我注意到它使用backgroundColor样式属性来设置应用程序的backgroundRect的填充颜色。但是,没有提到backgroundAlpha,所以我创建了一个新的应用程序外观并添加了一行代码!

在这一行之下:
bgRectFill.color = getStyle('backgroundColor');
添加以下内容:
bgRectFill.alpha = getStyle('backgroundAlpha');

在您的应用程序.mxml文件中,将skinClass属性设置为:

skinClass="YourSkinsDirectory.YourApplicationSkin" 

我将 ApplicationSkin.mxml 保存在名为 皮肤 的文件夹中 所以我看起来像这样:skinClass="Skins.ApplicationSkin"

这是完整的皮肤:

<?xml version="1.0" encoding="utf-8"?>

<!--

    ADOBE SYSTEMS INCORPORATED
    Copyright 2008 Adobe Systems Incorporated
    All Rights Reserved.

    NOTICE: Adobe permits you to use, modify, and distribute this file
    in accordance with the terms of the license agreement accompanying it.

-->

<!--- The default skin class for the Spark Application component. 

       @see spark.components.Application

      @langversion 3.0
      @playerversion Flash 10
      @playerversion AIR 1.5
      @productversion Flex 4
-->
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:fb="http://ns.adobe.com/flashbuilder/2009" alpha.disabled="0.5" alpha.disabledWithControlBar="0.5">

    <fx:Metadata>
    <![CDATA[ 
        /** 
         * A strongly typed property that references the component to which this skin is applied.
         */
        [HostComponent("spark.components.Application")]
    ]]>
    </fx:Metadata> 

    <fx:Script fb:purpose="styling">
        <![CDATA[
            /**
             *  @private
             */
            override protected function updateDisplayList(unscaledWidth:Number, 
                unscaledHeight:Number) : void
            {
                bgRectFill.color = getStyle('backgroundColor');
                bgRectFill.alpha = getStyle('backgroundAlpha');
                super.updateDisplayList(unscaledWidth, unscaledHeight);
            }
        ]]>
    </fx:Script>

    <s:states>
        <s:State name="normal" />
        <s:State name="disabled" />
        <s:State name="normalWithControlBar" />
        <s:State name="disabledWithControlBar" />
    </s:states>

    <!-- fill -->
    <!--- 
        A rectangle with a solid color fill that forms the background of the application.
        The color of the fill is set to the Application's backgroundColor property.
    -->
    <s:Rect id="backgroundRect" left="0" right="0" top="0" bottom="0">
        <s:fill>
            <!--- @private -->
            <s:SolidColor id="bgRectFill" color="#FFFFFF" alpha="1"/>
        </s:fill>
    </s:Rect>

    <s:Group left="0" right="0" top="0" bottom="0">
        <s:layout>
            <s:VerticalLayout gap="0" horizontalAlign="justify" />
        </s:layout>

        <!--- 
            @private
            Application Control Bar
        -->
        <s:Group id="topGroup" minWidth="0" minHeight="0"
                    includeIn="normalWithControlBar, disabledWithControlBar" >

            <!-- layer 0: control bar highlight -->
            <s:Rect left="0" right="0" top="0" bottom="1" >
               <s:stroke>
                    <s:LinearGradientStroke rotation="90" weight="1">
                        <s:GradientEntry color="0xFFFFFF" />
                        <s:GradientEntry color="0xD8D8D8" />
                    </s:LinearGradientStroke>
               </s:stroke>
            </s:Rect>

            <!-- layer 1: control bar fill -->
            <s:Rect left="1" right="1" top="1" bottom="2" >
               <s:fill>
                    <s:LinearGradient rotation="90">
                        <s:GradientEntry color="0xEDEDED" />
                        <s:GradientEntry color="0xCDCDCD" />
                    </s:LinearGradient>
               </s:fill>
            </s:Rect>

            <!-- layer 2: control bar divider line -->
            <s:Rect left="0" right="0" bottom="0" height="1" alpha="0.55">
                <s:fill>
                    <s:SolidColor color="0x000000" />
                </s:fill>
            </s:Rect>

            <!-- layer 3: control bar -->
            <!--- @copy spark.components.Application#controlBarGroup -->
            <s:Group id="controlBarGroup" left="0" right="0" top="1" bottom="1" minWidth="0" minHeight="0">
                <s:layout>
                    <s:HorizontalLayout paddingLeft="10" paddingRight="10" paddingTop="7" paddingBottom="7" gap="10" />
                </s:layout>
            </s:Group>
        </s:Group>

        <!--- @copy spark.components.SkinnableContainer#contentGroup -->
        <s:Group id="contentGroup" width="100%" height="100%" minWidth="0" minHeight="0" />

    </s:Group>

</s:Skin>