Solved

Dynamic checkbox names

Posted on 2009-03-31
8
604 Views
Last Modified: 2013-11-11
Hello,

I have around 70 checkboxes in my AIR application, which all have names like: c1 - c70 (this means that first checkbox has id="c1" , second id="c2"..... id="c70")

Now i would like to check all 70 checkboxies and determine which one is selected and which one is not.  I would like to use one for loop because it would be too much to write 70 if conditions to check all that manualy.
0
Comment
Question by:Didica
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 12

Expert Comment

by:scooby_56
ID: 24032025
create an array to hold the controls

var checkBoxes:Array = new Array();
checkBoxes.push(new Checkbox());

//access like this
checkBoxes[69].checked = true;

//loop round like this
for (var i:int = 0;i<checkBoxes.length; i ++){
   checkBoxes[i].checked = true;
}  
0
 

Author Comment

by:Didica
ID: 24033451
Hmm, i don't think that i understand your solution...

I will try to explain what i need one more time:

I have one Flex (AIR) application in which i have 70 Checkboxies, when user press one button i want to check state of those 70 checkboxies with one loop. Because of that i gave namese to those checkboxies from c1 - c70
0
 
LVL 12

Expert Comment

by:scooby_56
ID: 24037114
Are the checkboxes created using actionscript?
example
var c1:Checkbox = new Checkbox();
or at design time by draggin them onto the stage?

either way.. to loop through them you will need to insert them into an array
var checkBoxes:Array = new Array();
checkBoxes.push(c1);
checkBoxes.push(c2);
checkBoxes.push(c3); ///etc..

then you can loop through as-per the exmple i gave in the above post.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:scooby_56
ID: 24037200
Actually if you added at design time and gave instance names via the properties panel just use
for (var i=0;i<70;i++){      
     CheckBox(getChildByName('c'+(i+1))).selected= true;
}
0
 

Author Comment

by:Didica
ID: 24037433
Ok tnx, it seems that it is working. But just can you tell me one more think:

In some cases there will not always be c1 -  c70 , mybe some times there will be missing c2 or c43...
So is there a way to first check if checkbox with specific ID exists and then to manipulate it.

If i don't check it i will get   null object reference  error
0
 
LVL 12

Expert Comment

by:scooby_56
ID: 24038263
//try this

for (var i=0;i<70;i++){    
 if(getChildByName('c'+(i+1)) ){
     CheckBox(getChildByName('c'+(i+1))).selected= true;
  }
}
0
 

Author Comment

by:Didica
ID: 24038477
Tnx, that is great.

And if it is not big problem for you, can you please tell me how following line will looklike for chechbox that is located in component file (which i include in main file and give it id="CompCheckBox")

 CheckBox(getChildByName('c'+(i+1))).selected


in "noraml" - manual access to each checkbox i would use
CompCheckBox.c1.selected .....

Tnx in advance!
0
 
LVL 12

Accepted Solution

by:
scooby_56 earned 500 total points
ID: 24038883
//here you go... 3 for the price of 1 ;o)

CheckBox(CompCheckBox.getChildByName('c'+(i+1))).selected

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Flash being Disabled - help! 20 343
High definition conversion videos in YouTube 12 296
FlashBuilder allocate more memory using FlashBuilder.ini 18 280
Running Mp4 or Flash Video 1 141
I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question