Solved

Dynamic checkbox names

Posted on 2009-03-31
8
606 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

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!

Question has a verified solution.

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

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
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.

705 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