25
Aug
07

Changing a CheckBox control’s icon

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 Responses to “Changing a CheckBox control's icon”


  1. 1 benjy Apr 23rd, 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?

  2. 2 peterd Apr 23rd, 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

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".