cssapache-flexflash-builderflex-mx

Unable to apply css style to Alert in flex


I'm trying to skin a mx.controls.Alert component using CSS in flex 4.6, but the style does not apply to the alert. I have successfully implemented this before but this time I'm unable to isolate the issue.

Here is my code:

<?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>

This is the component I'm using in the main application. It gives a warning at mx:Alert that "CSS type selectors are not supported in components: 'mx.controls.Alert'"

I have also tried the following link: Flex Alert.styleName not working for me

But it gives an error:

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

At line:

alertCSS = StyleManager.getStyleDeclaration("Alert");

Any help is highly appreciated. Please excuse me for any mistake I might have made as I'm fairly new to flex.


Solution

  • You should define your styles in the top level application it is the file which contains the s:Application tag.

    Simply moving your fx:style block to the top level application should do the trick.