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 8043309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:51:38+00:00 2026-06-05T04:51:38+00:00

I have a problem that has been driving me nuts. I create a Form

  • 0

I have a problem that has been driving me nuts. I create a Form dynamically in Flex using the following code:

private function init():void {
            //Dynamically create form based on profiles
            for each(var role:AclRoleDTO in _profiles) { 
                //Create form item
                var fi:FormItem = new FormItem();
                fi.label = role.name;

                //Create checkbox
                var cbx:CheckBox = new CheckBox();
                cbx.id = "role_"+role.id.toString();
                cbx.label = role.description;
                cbx.width = 250;
                cbx.selected = true;

                //Add Checkbox for form item
                fi.addChild(cbx);
                profileForm.addChild(fi);
            }

            //Add save button
            var fib:FormItem = new FormItem();
            var btn:Button  = new Button();
            btn.name    = "Save";
            btn.label   = "Save";
            btn.id      = "saveButton";

            btn.addEventListener(MouseEvent.CLICK, onSubmitClicked);

            fib.addChild(btn);

            profileForm.addChild(fib);
        }

This works fine and creates a Form with FormItems that include CheckBoxes based on the available profiles + a save button to save these profiles.

However, when a user clicks on the save button to save the profiles, I use the following method to retrieve the selected boxes but the function only recognizes the last added CheckBoxes as a CheckBox…

private function onSubmitClicked(event:MouseEvent):void {
            var formElements:Array = profileForm.getChildren();
            var roleIds:ArrayCollection = new ArrayCollection();
            var i:int = 0;
            var j:int = 0;

            //Parse the entire form
            for (i; i < formElements.length; i++) {

                if (formElements[i] is FormItem) {
                    var formItem:FormItem = formElements[i];
                    var itemElements:Array = formItem.getChildren();

                    for (j;j<itemElements.length;j++) {

                        //If form item is a checkbox, check if the box is checked!
                        if (itemElements[j] is CheckBox) {
                            var tmpBox:CheckBox = itemElements[j];

                            if (tmpBox.selected) {
                                //random stuff
                            }
                        }
                    }
                }
            }

            //Send event with roleIds!
            //More random stuff

        }

I have tried all sorts of things to make sure that the loop works properly and it does: it loops through the proper amount of FormItem elements and retrieves the proper amount of childrenElements. It just doesn’t recognize any child as a CheckBox other than when looping through the last FormItem that was added. If I use flash.utils.getQualifiedClassName(itemElements[j]) to find out what the other FormItem children are it returns an empty string.

What am I doing wrong?

  • 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-06-05T04:51:40+00:00Added an answer on June 5, 2026 at 4:51 am

    Here is working code for your problem:

            private function onSubmitClicked(event:MouseEvent):void
            {
                var selectedRoles:ArrayCollection = new ArrayCollection();
    
                var formItems:Array = rolesForm.getChildren();
    
                for (var i:int = 0; i < formItems.length; i++)
                {
                    var formItem:FormItem = formItems[i];
                    var formItemElements:Array = formItem.getChildren();
                    for each (var control:UIComponent in formItemElements)
                    {
                        if (control is CheckBox)
                        {
                            var tempBox:CheckBox = control as CheckBox;
    
                            if(tempBox.selected)
                                selectedRoles.addItem(tempBox);
                        }
                    }
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been driving me nuts all day. I have a weird bug that
I have a javascript function that has been driving me nuts. This is the
I a problem that has been driving me nuts for awhile now. Here is
I have a dropdown in my form that has a problem to populate when
This has been driving me nuts all day. I've seen this problem crop up
This has been driving me nuts for a week now. I have a class
This problem has been driving me mad. Here's the general gist: I have two
I have a problem that is and has been perplexing me for hours. I
So this has just been driving me nuts! I have looked through tons of
This problem has been driving me nuts all day and there has to be

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.