# Checkbox component

**URL:** <https://forum.kirupa.com/t/checkbox-component/672>\
**Category:** Uncategorized\
**Created:** [July 17, 2002, 6:23pm UTC](https://forum.kirupa.com/t/checkbox-component/672 "2002-07-17T18:23:50Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 20, 2002, 7:41am UTC](https://forum.kirupa.com/t/checkbox-component/672/21 "2002-07-20T07:41:07Z")

</div>

the array assignment i’ll skip…

there’s just two parts:

```auto

function checkDisplay(component) { 
	var j,s;
	for(j in myCheck){
		if(myCheck[j].getValue()) s += myCheck[j].getLabel()+"
";
	}

```

for each item in myCheck, if myCheck\* is checked, add it’s label and a linebreak to s.

```auto

	trace("
You checked:
" + ((s.length) ? s : "Nothing"));
}

```

trace “You checked”, then if s has a length (greater than 0) trace s, otherwise trace “Nothing”.

i didn’t bother with assigning the handler, i’d assume that has to be done too.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 20, 2002, 7:23pm UTC](https://forum.kirupa.com/t/checkbox-component/672/22 "2002-07-20T19:23:09Z")

</div>

if you use var to declare a variable within a function, it will not exist outside of that function.

when using a for in loop, you’ll iterate through everything within the object; variables, objects, methods … everything.

had you defined any array prorotypes, the code i posted would iterate through them as well, unless you hid them with [ASSetPropFlags()](http://chattyfig.figleaf.com/flashcoders-wiki/index.php?ASSetPropFlags), a good practice.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 20, 2002, 8:31pm UTC](https://forum.kirupa.com/t/checkbox-component/672/23 "2002-07-20T20:31:17Z")

</div>

well, let’s say you have an object of the calss Zoo which holds a variable number of animals, each with associatied data.

you want to write a method which will return the total number of animals in the zoo

```auto

Zoo.prototype.animalCount = function(){
   var c;
   for(i in this){ c++; }
   return(c);
}

```

problem is that animalCount is iterated over in the for in loop along with any other methods defined for Zoo, so you get the wrong number of animals. then if you take that value and use it in another script, say Zoo.prototype.feedAnimals(), and you end up feeding animals that don’t exist!

depending on the complexity and purpose of the scripts, this can cause major problems.

for in loops are great for trouble shooting. ever need to know just what’s going on in a particular object? something like this can be helpful:

```auto

Object.prototype.showContents = function(){
   for(i in this){ trace(i+":"+this*); };
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 22, 2002, 8:30am UTC](https://forum.kirupa.com/t/checkbox-component/672/24 "2002-07-22T08:30:42Z")

</div>

ily, malheursement, je ne peux pas parler le francais. je suis canadienne. ici, tout le monde apprend un peu dans l’ecole.

user et abuser to your hearts content.

inigo - just another white male i’m afraid.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 23, 2002, 8:15am UTC](https://forum.kirupa.com/t/checkbox-component/672/25 "2002-07-23T08:15:27Z")

</div>

ha ha! genders always gave me difficulty… ; )

[Previous page](https://forum.kirupa.com/t/checkbox-component/672.md?page=1)
