Checkbox component

Hey guys,
Does anybody know a way of getting all the checkbox (what’s the plural for box ???) that have been checked by a user, without browsing through them ?


pom :asian:

I’m just fine, except for a bad headache and total exhaustion. :pirate: Thanks for asking Inigo. I hope you’re fine too. :stuck_out_tongue:

When I say browsing through them, I mean check one by one if it is checked. Which is long. That’s why I wondered if there wouldn’t be a function that checkes all the checkboxES and returns all those which are checked.

pom :asian:

OK, this is what I’ve done, and it works, but there has to be a better way. I have 5 checkboxes, with 5 labels and 5 instance names that are in an array

// Array of the instace names of the checkboxes
myCheck = new Array (flash,games,beer,sport,art) ;

// Function
checkDisplay = function (component) {
trace ("
You have checked:
") ;
for (i=0;i<myCheck.length;i++) {
if ( myCheck[ i].getValue() ) {
trace (myCheck[ i].getLabel());
if (!j) trace (“Nothing”) ;
// blabla
for (i=0;i<myCheck.length;i++) {
myCheck[ i].setChangeHandler (“checkDisplay”) ;

The thing that bothers me is that this function I made has nothing to do with the component put as a parameter. Anyone has an idea ?

pom :asian:

That’s not exactly what I wanted. If you test my code, you’ll see that it returns the checkboxes that are actually checked WHEN YOU CHECK OR UNCHECK ANY CHECKBOX. So it’s not really the same.

Thanks anyway :slight_smile:

pom :asian:

Did you try that code, Inigo ? Because I don’t know how to use it :slight_smile:

And anyway, this will trace the checkbox you’ve just clicked, not all the checkboxes that are clicked, and it doesn’t check if the checkboxes are unchecked…

Sorry to be a pain in the ass :ninja:

pom :asian:

Yep. Shorter code but that’s basically what I was trying to do. I could never use that for (j in that) thing, because I never know what it returns (clips, clips and buttons, objects ?, here the index of the array…) And it works great !! Except the fact that you have to remove the “” in the myCheck array.

Thanks a lot Supra and Inigo!

pom :asian:

One more question : I’d like to put the ckecked checkboxes in an array. Can I declare a

var s = new Array () ;

And will I be able to use it in the next scene ? Is the var destroyed right when the function ends or can I still access it ?

pom :asian:

The main benefit of ASSetPropFlags is to allow you to add properties and methods to a Class prototype without risking the property showing up in for…in loops over instances of the class** which could cause any number of problems in your script.**
What kind of problems ?

And that site is crazy by the way. Very interesting stuff there =)

pom :asian:

And your prototype thing works indeed ! If anybody else is interested :

myA = new Array ("1","2","3") ;
Array.prototype.tracing = function () {
	trace (this[0]);
for (j in myA) {trace (j);}

Returns :

pom :asian:

Thank you. And I have to say that you explain it very well. :slight_smile: Puis-je user et abuser de ces informations pour un éventuel petit article général sur l’Actionscript ? (You speak French, don’t you ?)

pom :asian:

Well, Inigo, the Zoo example was pretty much as clear as it can get… if you know what a class is. I’m going to try and explain, I hope Supra won’t have to correct anything.

Imagine that you have an array like I wrote in a previous post.

myA = new Array ("1","2","3") ;
for (j in myA) {count++;}
trace ("There are "+count+" elements in myA");

Everything is cool, it returns 3.

Now if you add a prototype to the object Array, it will be taken into account in the loop, hence giving a wrong result

myA = new Array ("1","2","3") ;
Array.prototype.tracing = function () {
	trace (this[0]);
for (j in myA) {count++;}
trace ("There are "+count+" elements in myA");

Big big Badaboom, it returns 4.

Which means that all the regular array methods have already been ASSetPropFlaged, so that they don’t appear.

Clear ? :stuck_out_tongue:

pom :asian:

If that’s not in the best of Kirupa, I don’t know what is. :slight_smile:

pom :asian:

:stuck_out_tongue: Excuse me but your post made me laugh: you answer in French to tell me that you don’t speak french, and then you say that you are a canadienne (female), but a white male. Am I the only one to see a contradiction here?

Thanks again for all the info:), I will definitely use it (what was it again ?)

pom :asian:

How are ya?

what do you mean, browsing through them?

checkboxes is the plural!

Hmm… never tried it, but a function wrapped around an array might work. What do you think?

Here’s what you requested. I put it together and I think it makes for cleaner code.

function OnChange(Fcheckbox) {

I put a button on the main timeline with trace(_root.answers);

what do you think?

I understand…

this does the same:

function OnChange(Fcheckbox) {
		case flash:
		trace("you clicked on Flash");
		case games:
		trace("you clicked on games");
		case beer:
		trace("you clicked on beer");
		case sport:
		trace("you clicked on sport");
		case art:
		trace("you clicked on art");

Sbeener…Can you please dissect that code for me. Ilya… We can probably combine this to make it work. I was just a bit unsure where you were trying to go with it.

No problem at all, though… I love playing with this stuff.

As far as components go.

I gave the checkbox instances names (flash, beer, sports, etc.)

In the properties panel, under ChangeHandler I put onChange

that’s when the code takes over…
it basically says (I write this part for the sake of others. Not you.)

Any time one of these buttons changes…do this…

If Sbeeners’ solution does not work, I’ll be happy to take another stab at it.

well… Ilya… since you understood it so well… can you explain it to me? Maybe it has something to do with the fact that it is 1:15 in the morning…

I have been trying to understand the whole prototype thing, perhaps that is part of my problem.

Have a good night!


Beener, I know you’re the Man! (or Woman!). Thanks or all your help!


i think the board munged your code … it’s a little strange.

i’m not familiar with components, but here’s a rewrite of what i thought you meant above, it’s essentially the same:

myCheck = ["flash","games","beer","sport","art"]; 

function checkDisplay(component) { 
	var j,s;
	for(j in myCheck){
		if(myCheck[j].getValue()) s += myCheck[j].getLabel()+"
You checked:
" + ((s.length) ? s : "Nothing"));

untested, maybe it works…