Checkbox component

the array assignment i’ll skip…

there’s just two parts:


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.


	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.

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(), a good practice.

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


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:


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

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.

ha ha! genders always gave me difficulty… ; )