Solved

Dynamic checkbox names

Posted on 2009-03-31
8
599 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
  • 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
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 set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now