Hi, I have been working on my portfolio website like forever. I am struggling with one problem that I can not solve for nothing. Can someone please help me. I don't know what I am doing wrong.

I have two checkboxes. When selected the selected checkbox will appear in mytxt.text box. This is how I am checking that everything is working. Instead of the selected checkbox showing up in mytxt.text result it show up true and false, false and true, and if both boxex are check true and true. I am trying to get the result of the one check box that is check and for it to dispay the name. Could someone please help? I will place the code below. I have tried everything I could think of. I know it is easier to make my checkboxes into radio buttons, but I really would like to have checkboxes.

My check boxes are name apple and orange

import fl.controls.*;
import fl.controls.RadioButtonGroup;

//This sets a group name for the radio button instances.
var myradioGroup:RadioButtonGroup = new RadioButtonGroup("RadioButtonGroup");

//This assigns the radio button instances to the radio group.
cRadio1.group = myradioGroup;
cRadio2.group = myradioGroup;


//Gives labels to the checkboxes.
applecb.label="Apple";
orangecb.label="Orange";

//Event listener for the checkboxes.
applecb.addEventListener(MouseEvent.CLICK, changelist);
orangecb.addEventListener(MouseEvent.CLICK, changelist);

function changelist(event:MouseEvent):void {
    mytxt.text = "";


}

submit_btn.addEventListener(MouseEvent.CLICK, submitFunc);
var radBtns = [cRadio1,cRadio2];
var errorsNum = 0;
function submitFunc(e:MouseEvent)
{
    var finalData = "";
    var errorFlag = "Followings errors were found.\n";
    if (name_txt.text == "")
    {
        errorsNum++;
        errorFlag +=  errorsNum+". Enter ur name.\n";
    }
    if (email_txt.text == "")
    {
        errorsNum++;
        errorFlag +=  errorsNum+". Enter ur email.\n";
    }
    if (mobile.text == "")
    {
        errorsNum++;
        errorFlag +=  errorsNum+". Enter ur phone number.\n";
    }
    if (!myradioGroup.selection)
    {
        errorsNum++;
        errorFlag +=  errorsNum+". Select ur gender.\n";
    }

    if (age.selectedIndex < 0)
    {
        errorsNum++;
        errorFlag +=  errorsNum+". Select any of the course.\n";
    }
    {
    if (applecb.selected == true) mytxt.appendText(applecb.label + "\n");
if (orangecb.selected == true) mytxt.appendText(orangecb.label + "\n");
}




        if (message_txt.text == "")
    {
        errorsNum++;
        errorFlag +=  errorsNum+". Enter ur message.\n";
    }

    if (errorsNum > 0)
    {
        mytxt.text = errorFlag;
        errorFlag = "";
        errorsNum = 0;
        return false;
    }

    else
    {
        finalData += "Thank you "+name_txt.text+" for contacting me! I will call you at "+mobile.text+", "+"else I can mail you also at "+email_txt.text+" in "+applecb.selected+" response "+orangecb.selected+" of your message "+message_txt.text+"\n\n Your other information is, you're a "+myradioGroup.selection.value+" and is between "+age.value+"\nThanks";
        mytxt.text = finalData;
    }
}

Dani AI

Generated

Quick diagnosis: the form is printing true/false because your code concatenates the checkboxes' boolean .selected values into the output string instead of their labels, and your changelist handler just clears mytxt so nothing else shows. Also it looks like a RadioButtonGroup is being used — don't group CheckBox instances (that forces radio-like behaviour). Use the checkbox labels when building the visible message, listen for Event.CHANGE on each CheckBox, and read the checkbox that actually fired the event with e.currentTarget.

A concise, safe pattern (keeps logic DRY and readable):

var checkboxes:Array = [applecb, orangecb];

for each (var cb:CheckBox in checkboxes) {
    cb.addEventListener(Event.CHANGE, onCheckboxChange);
}

function getCheckedLabels(list:Array):Array {
    var out:Array = [];
    for each (var box:CheckBox in list) {
        if (box.selected) out.push(box.label);
    }
    return out;
}

function onCheckboxChange(e:Event):void {
    mytxt.text = getCheckedLabels(checkboxes).join(", ");
}

When you build the submission string, convert the selected booleans into a human string instead of concatenating booleans directly:

function submitForm(e:MouseEvent):void {
    var errors:int = 0; // use a local counter
    var selected:Array = getCheckedLabels(checkboxes);
    var selText:String = selected.length ? selected.join(" and ") : "none selected";
    mytxt.text = "Thanks " + name_txt.text + ". You selected: " + selText + ".";
}

Notes and quick checks: confirm the Stage instance names exactly (case-sensitive), ensure the components are CheckBox (not RadioButton) unless you want mutual exclusion, and reset any global error counters inside submitFunc. was right to focus on reading the selection state and not just clearing the text — their suggestion pointed in the right direction, but use Event.CHANGE + e.currentTarget and display labels (not booleans) for the clearest output.

Member Avatar for Member #949455

This is how I am checking that everything is working. Instead of the selected checkbox showing up in mytxt.text result it show up true and false, false and true, and if both boxex are check true and true

The code you provided doesn't work.

The issue you mention doesn't make sense:

function changelist(event:MouseEvent):void {
mytxt.text = "";
}

How can this:

mytxt.text = "";

know true or false when you never establish whether it's true or false in the beginning.

It should look something like this:

submit_btn.addEventListener(MouseEvent.CLICK, _selected);
function _selected(e:MouseEvent):void{

var bool:Boolean = e.target.selected;

if(bool){
    trace("true);
    // if it's true this is where the true code begin 
}
else if{
    trace("false");
    // if it's false this is where the false code begin 
}
else{
    trace("both");
    // if it's both true/true or false/false this is where the both true/true or false/false code begin 
}
}

From this:

function changelist(event:MouseEvent):void {
mytxt.text = "";
}

it should look like this:

function changelist(event:MouseEvent):void { 
applecb.enabled = event.target.selected; 
orangecb.enabled = event.target.selected;     
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.