The following example shows how you can customize the check icon in a CheckBox control and use embedded images instead.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/25/changing-a-checkbox-controls-icon/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            [Bindable]
            [Embed(source="assets/icon_accept.gif")]
            public var AcceptIcon:Class;

            [Bindable]
            [Embed(source="assets/icon_alert.gif")]
            public var AlertIcon:Class;
        ]]>
    </mx:Script>

    <mx:CheckBox id="checkBox"
            label="Custom icon test (selected={checkBox.selected})"

            disabledIcon="{AlertIcon}"
            downIcon="{AlertIcon}"
            overIcon="{AlertIcon}"
            upIcon="{AlertIcon}"

            selectedDisabledIcon="{AcceptIcon}"
            selectedDownIcon="{AcceptIcon}"
            selectedOverIcon="{AcceptIcon}"
            selectedUpIcon="{AcceptIcon}"
         />

</mx:Application>

View source is enabled in the following example.

 
Tagged with:
 
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.

0 Responses to Changing a CheckBox control’s icon

  1. benjy says:

    please ,could you add image ,in the source code,or you can make a link .
    here ,y should make AlertIcon/AcceptIcon.is it possible please?

  2. peterd says:

    benjy,

    You can click the “View source” link above, or right-click the Flex application and select “View Source” from the context menu, and get the images and all the code.

    Peter

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