Changing a CheckBox control’s icon

by Peter deHaan on August 25, 2007

in CheckBox

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.

{ 2 comments… read them below or add one }

1 benjy April 23, 2008 at 7:23 am

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?

Reply

2 peterd April 23, 2008 at 7:28 am

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

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can 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

Previous post:

Next post: