i've got to go out now so cant give the full answer i have in my head,
but one way of tackling it is to make each state variable's value a
power of 2
a = 1
b = 2
c = 4
d = 8
then you know that any combination of them has a unique value. (its
basically a 4 bit number)
then to handle the dispatch depending on the state combination you can
build a function table.
functionTable = new Array();
// create a handler for the combination a + b
functionTable[a + b] = Delegate.create(this,combinationAB);
and when you check the variables just call the function directly from
the table :
// a,b,c,d are just passed as boolean flags here
function handleUpdate(a:boolean,b:boolean,c:boolean,d:boolean)
{
// taking advantage of a true being 1 in flash
// and ideally you would setup these numbers
// as static class variables
var state = a + (b * 2) + (c * 4) + (d * 8);
// call the defined function
functionTable[state]();
}
of course you could do a check first to see if the function is defined
and do something like log a warning or whatever is appropriate for your
situation.
hope that makes sense.
martin
eric dolecki wrote:
I have 4 variables I need to check the states of routinely... and
combinations thereof.
I am assuming that if I have a counter, and interogate and += them values, I
can then check the value of the counter to determine the combinations.
psudeo-code:
var counter:Number = 0;
if ( a ){ counter += 2; }
if ( b ){ counter += 3; }
if ( c ){ counter += 6; }
if ( d ){ counter += 12;}
if ( counter == 2 ){
// only a was true
} else if ( counter == 3 ){
// only b was true
} ...
Which is fine, but thats gonna be one honkin' if else statement to catch all
the combinations.
Is there a better way of doing this that will catch all the possible
combinations in an elegant way?
- edolecki
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
--
Martin Wood
http://relivethefuture.com/choronzon
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders