如何在flex中更改PopUp窗口的背景颜色

时间:2013-04-11 06:52:51

标签: actionscript-3 flex flex4 flex3

我开发了一个包含少量PopUp窗口的应用程序。每当弹出窗口弹出窗口的背景变得更亮时,有什么方法可以让PopUP背景变得更暗。

先谢谢..

1 个答案:

答案 0 :(得分:1)

如果您指的是警报组件,您可以执行以下操作:

<?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="Alert.show('Hello!')">
<fx:Style>
    @namespace s "library://ns.adobe.com/flex/spark";
    @namespace mx "library://ns.adobe.com/flex/mx";

    mx|Alert {
        backgroundAlpha: 0.4;
        backgroundColor: #00ff00;
    }
</fx:Style>

<fx:Script>
    <![CDATA[
        import mx.controls.Alert;
    ]]>
</fx:Script>

</s:Application>

//结果

enter image description here

<强> //修改

如果您想使用自定义组件,它可能如下所示:

// MyAlert.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx" width="175" height="100">
<fx:Script>
    <![CDATA[
        import mx.managers.PopUpManager;

        protected function onOkClick(event:MouseEvent):void
        {
            PopUpManager.removePopUp(this);
        }
    ]]>
</fx:Script>

<s:Rect top="0" bottom="0" left="0" right="0">
    <s:fill>
        <s:SolidColor color="0x00ff00" alpha="0.4"/>
    </s:fill>
</s:Rect>

<s:VGroup horizontalAlign="center" width="100%" height="100%">
    <s:Spacer height="10"/>
    <s:Label text="Hello!"/>
    <s:Button label="Ok" click="onOkClick(event)"/>
</s:VGroup>
</s:TitleWindow>

从应用程序中调用它:

var myAlert:MyAlert = new MyAlert();

PopUpManager.addPopUp(myAlert, this, true);
PopUpManager.centerPopUp(myAlert);

//结果

enter image description here