Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6856959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:57:17+00:00 2026-05-27T01:57:17+00:00

I want to show the user a confirmation box when they deselect a checkbox.

  • 0

I want to show the user a confirmation box when they deselect a checkbox. My code works although I think it is a bit of a hack. I listen to the checkbox click and then show the alert. Depending on the result I then set the checkbox to be checked again.

My code is

<?xml version="1.0"?>
<s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009"   xmlns:s="library://ns.adobe.com/flex/spark" >
<fx:Script><![CDATA[
    import mx.controls.Alert;
    import mx.events.CloseEvent;

    private function handleCheckBoxChange(e:Event):void {
        if (!CheckBox(e.target).selected) {
            Alert.show("Are you sure you want to deselect?", "Confirm",
                Alert.YES | Alert.NO, null, handleAlert, null, Alert.YES);
        }
    }

    public function handleAlert(event:CloseEvent):void {
        if (event.detail == Alert.YES) {
            trace("yes clicked");
        }
        else if (event.detail == Alert.NO) {
            cb1.selected = true;
            trace("no clicked");
        }
    }
    ]]></fx:Script>

    <s:CheckBox id="cb1" label="cb1" click="handleCheckBoxChange(event)"/>
</s:NavigatorContent>

There are two things I do not like about this

  1. the code is specific to cb1 and cannot be reused for other checkboxes
  2. the checkbox is deselected when the alert shows. Then when the user clicks no the checkbox is selected again.

What I ideally want is to stop the uncheck event if the user clicks no on the alert box. Is it possible to intercept this in Flex?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:57:17+00:00Added an answer on May 27, 2026 at 1:57 am

    One solution for your two problems: Create a custom class that extends CheckBox.
    You cannot use e.stopImmediatePropagation() in click Event because yours is added later. However, if you trace up, you can see in ToggleButtonBase (which is parent of CheckBox) contains a protected function named buttonReleased; this function will do the change for selected value and dispatch a change Event. All you need to do in your new class is overriding this function.

    public class AlertCheckBox extends CheckBox
        {
            public function AlertCheckBox()
            {
                super();
            }
    
            override protected function buttonReleased():void
            {
                if (selected) {
                    Alert.show("Are you sure you want to deselect?", "Confirm",
                        Alert.YES | Alert.NO, null, handleAlert, null, Alert.YES);
                    return;
                }
    
                super.buttonReleased();
            }
    
            public function handleAlert(event:CloseEvent):void {
                if (event.detail == Alert.YES) {
                    selected = false;
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to show the confirmation box in asp.net from server side: I want
Similar to the Simon games of old, I want to show the user a
I use Lucene.Net to index some documents. I want to show the user a
...I want to Show the 'delete' button when user is an admin, and show
I want to show a open dialog for the user, where the user can
I want to show messagebox to the user, such that the user cannot refuse
We want to show a hint for a JList that the user can select
I want to show a modal dialog/pop-up window when the user has not filled
i want to show all the vehicle maintenance history when user click on the
I want to show a dialog that will allow the user to select a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.