css - 无法将 css 样式应用于 flex 中的警报

标签 css apache-flex flash-builder flex-mx

我正在尝试使用 Flex 4.6 中的 CSS 为 mx.controls.Alert 组件设置外观,但该样式不适用于警报。我之前已经成功实现过这个,但这次我无法隔离问题。

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas 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="400" height="400">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Style>
    @namespace flexlib "http://code.google.com/p/flexlib/";
    @namespace s "library://ns.adobe.com/flex/spark";
    @namespace mx "library://ns.adobe.com/flex/mx";
    @namespace components "components.*";
    @namespace flexgif "org.gif.flexgif.*";

    mx|Alert{
        background-color:#FFFFFF;
        background-alpha:1;
        color:#FFFFFF;
        border-color:#223f56;
        border-style:solid;
        border-thickness:1;
        button-style-name:"alertButton";
        chromeColor:#223f56;
        header-height:30;
        drop-shadow-enabled: true;
        messageStyleName:"messageStyle";
        titleStyleName:"titleStyle";     

    }

    .alertButton{
        emphasizedSkin: ClassReference('skins.CustomButtonSkin');
        skin: ClassReference('skins.CustomButtonSkin');
        buttonHeight: 30;
        color: #FFFFFF;
        verticalAlign: middle;
        horizontalAlign:center;
        paddingBottom: 4;
        textRollOverColor: #FFFFFF;
        fontFamily:MavenPro_R;

        /*  drop-shadow-enabled:false;
        theme-color:#40779f;
        chromeColor:#40779f;
        color:#FFFFFF;
        backgroundColor:#40779f;
        verticalAlign:middle;
        horizontalAlign:center;
        buttonHeight:30;
        paddingBottom:5px;  */
    }


    .messageStyle{
        fontFamily:MavenPro_R;
        font-size :12;
        color:#595959;
    }
    .titleStyle{
        backgroundColor:#223f56;
        font-size :14;
        font-weight:bold;
        color:#FFFFFF;

    }
    mx|Alert, mx|Button {
        fontFamily:MavenPro_B;
        textFieldClass: ClassReference("mx.core.UIFTETextField");
    }
</fx:Style>

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

        public function showAlert(event:MouseEvent):void{

            Alert.show("Hi, I'm a test alert");
        }
    ]]>

</fx:Script>

<mx:Button id="testButton" click="showAlert(event)" label="Alert" x="200" y="200"/>
</mx:Canvas>

这是我在主应用程序中使用的组件。 它在 mx:Alert 处发出警告“组件不支持 CSS 类型选择器:'mx.controls.Alert'”

我也试过以下链接: Flex Alert.styleName not working for me

但是报错:

1067: Implicit coercion of a value of type mx.styles:CSSStyleDeclaration to an unrelated type mx.controls:Alert

在线:

alertCSS = StyleManager.getStyleDeclaration("Alert");

非常感谢任何帮助。 请原谅我可能犯的任何错误,因为我是 flex 的新手。

最佳答案

您应该在顶级应用程序中定义您的样式,它是包含 s:Application 标记的文件。

只需将您的 fx:style block 移动到顶级应用程序就可以解决问题。

关于css - 无法将 css 样式应用于 flex 中的警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27916722/

相关文章:

flash - 是否可以嵌入文件夹中的所有文件?

html - 将较宽的 div 置于较窄的 div 中

actionscript-3 - 在使用 Actionscript 和 MXML 编写的 Flex 程序中调试内存泄漏的最佳方法是什么?

apache-flex - Flex : Get self SWF file name?

css - 你知道这个奇怪的事情吗? "AS3, Button width cannot change by setStyle(). However, inline CSS can change width."

apache-flex - 组织 Flex 项目供团队使用

Flash Builder 4 空格而不是制表符?

css - HTML 表格 - 从特定单元格中删除单元格间距/边框

css - 如何躲避CSS中的顶部栏

css - 未选中单选按钮时禁用 number_field