[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Dynamic checkbox names

Posted on 2009-03-31
8
Medium Priority
?
609 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 total points
ID: 24038883
//here you go... 3 for the price of 1 ;o)

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

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
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.
Suggested Courses

649 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