Vinnie
Vinnie

Reputation: 12720

Flex Alert.styleName not working for me

I have this code, but the style is not being applied. I've seen articles on the web where this should work. Any ideas?

var alert:Alert = Alert.show("You have not saved you changes.\n\nWould you like to save now?",
                             "Save Answers?",
                             Alert.NO | Alert.YES | Alert.CANCEL, 
                             this, 
                             handleUnsavedChanges,
                             null, 
                             Alert.YES);

alert.styleName = "alertStyle";

Attempting to set the style using the Alert class in my stylesheet seems to work, but throws a warning. I'd like to find the "approved" way.

BTW, this is Flex 3.

PS - I've also tried stuff like

alert.setStyle("backgroundColor", "0x00FF00");

but this does not seem to work either. I feel like I need to call something to tell the Alert box to redraw itself, but I don't know how.

Upvotes: 0

Views: 638

Answers (1)

Joe
Joe

Reputation: 82554

You could create a custom class in order to use specific css:

public class CustomAlert extends Alert {}

... Then in the CSS

CustomAlert 
{
    background-color: #00FF00;
}

Or a little more complicated example:

        import mx.styles.StyleManager;
        private function init():void {
            alertCSS = StyleManager.getStyleDeclaration("Alert");
        }

        private function showAlert(color:Object):void {
            alertCSS.setStyle("backgroundColor", "0x00FF00");
            alert = Alert.show("The quick brown fox...");
        }

Upvotes: 1

Related Questions