0

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.

Vinnie
  • 12,400
  • 15
  • 59
  • 80

1 Answers1

1

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...");
        }
Joe
  • 80,724
  • 18
  • 127
  • 145
  • Two comments: 1.) I don't want to style all the alerts, just this one in particular. 2.) I already mentioned that this approach produces a compiler warning (CSS type selectors are not supported in components: 'Alert') – Vinnie Sep 13 '11 at 17:47
  • This is an "id10t" error. For some reason, code to create the same exact alert box is duplicated in multiple places. Not expecting this, I attempted to style the first one I came to (of course it was the wrong one). Anyway, it appears that all these approaches will work - even setting the CSS styleName on the already create alert box. – Vinnie Sep 13 '11 at 18:26