The following example shows how you can control the Button control’s text color using the color, disabledColor, textRollOverColor, and textSelectedColor styles.

Full code after the jump.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/26/changing-a-button-controls-text-color/ -->
<mx:Application name="Button_color_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:ApplicationControlBar dock="true">
        <mx:Label text="color:" />
        <mx:ColorPicker id="colorCB" />
 
        <mx:Spacer width="33%" />
 
        <mx:Label text="textRollOverColor:" />
        <mx:ColorPicker id="textRollOverColorCB" />
 
        <mx:Spacer width="33%" />
 
        <mx:Label text="textSelectedColor:" />
        <mx:ColorPicker id="textSelectedColorCB" />
 
        <mx:Spacer width="33%" />
 
        <mx:Label text="disabledColor:" />
        <mx:ColorPicker id="disabledColorCB" />
        <mx:CheckBox id="enabledCh" label="enabled" selected="true" />
    </mx:ApplicationControlBar>
 
    <mx:Button id="button"
            label="Label"
            toggle="true"
            enabled="{enabledCh.selected}"
            color="{colorCB.selectedColor}"
            disabledColor="{disabledColorCB.selectedColor}"
            textRollOverColor="{textRollOverColorCB.selectedColor}"
            textSelectedColor="{textSelectedColorCB.selectedColor}" />
 
</mx:Application>

View source is enabled in the following example.

 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

3 Responses to Changing a Button control’s text color

  1. Umer says:

    how can i chagned the background color of button? on mouseover

  2. Adam says:

    Is it possible to change the font color of the “Selected Up” state? I think it would have to be done in a customized Button component.

  3. screenworker says:

    Nope.
    Set the stylename of the button by click to another Style with the color for selection. thats it.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree