PDA

View Full Version : checking multiple values



flash_noob
October 26th, 2005, 02:58 AM
Can someone lead me in the right direction?

I wanted to check the value of 5 different variables at the same time.

Based on the value each of variable I wanted to make 5 corresponding movie clips do something.


There has gotta be a better way to do this rather than me using a bunch of if else statements.

Any help would be awesome!

Thanks!

-T

virusescu
October 26th, 2005, 03:09 AM
It really depends on what you are trying to achieve.

flash_noob
October 26th, 2005, 03:42 AM
I have:
5 variables: problem001 - problem005 with a value of “complete” or “incomplete”
5 check mark movie clips: checkMark001 - checkMark005 with a _visible value of “true” or “false”

For each problem# that’s “complete” make the check mark _visible = true

virusescu
October 26th, 2005, 03:50 AM
Something like this


function updateMarks(){
for (var x = 1;x<=5;x++){
if (this["problem00"+x] == "complete"){
this["checkMark00"+x]._visible = true;
}else if (this["problem00"+x] == "incomplete"){
this["checkMark00"+x]._visible = false;
}
}
}
updateMarks();

Barn
October 27th, 2005, 11:35 AM
It's really better if you don't use leading zeros for the enumerations of your things in Flash, as it makes it necessary to do all sorts of string manipulations when you change the number of digits in counting. It is also better if you start with 0, rather than 1, as that corresponds to how Flash counts other things, such as array and string indexes. So, presuming you have changed your variables and instance names to problem0 through problem4, and checkMark0 through checkmark4:


fncMarkUpdate = function (nbrProblem) {
for (var icrIdx = 0; icrIdx<nbrProblem; icrIdx++) {
this["checkMark"+icrIdx]._visible = (this["problem"+icrIdx] == "complete");
}
};
fncMarkUpdate(5);