I guess I must be missing something here - I still don't understand the advantage of 'encoding' the conditions as numbers. As I see it, there is no way around evaluating 16 conditions. We can either make this transparent or we can 'elegantly' hide it behind numbers - which we'll have to comment heavily to 'decode' the meaning of the numbers and to make the code readable for humans.
It's about reacting to the possible combinations of 4 different events, right? Let's say the events are 'Inited','Clicked','Bedazzeled','Dragged'. We could now just do this: // When event 'Inited' is dispatched, set the flag Inited to true, etc. combo = ''; if(events[i]){ combo += 'Inited';} if(events[i]){ combo += 'Clicked';} if(events[i]){ combo += 'Bedazzeled';} if(events[i]){ combo += 'Dragged';} switch(combo){ case "": //do stuff here break; case "Bedazzeled": //do stuff here break; case "BedazzeledDragged": //do stuff here break; case "Clicked": //do stuff here break; case "ClickedBedazzeled": //do stuff here break; case "ClickedBedazzeledDragged": //do stuff here break; case "ClickedDragged": //do stuff here break; case "Dragged": //do stuff here break; case "Inited": //do stuff here break; case "InitedBedazzeled": //do stuff here break; case "InitedBedazzeledDragged": //do stuff here break; case "InitedClicked": //do stuff here break; case "InitedClickedBedazzeled": //do stuff here break; case "InitedClickedBedazzeledDragged": //do stuff here break; case "InitedClickedDragged": //do stuff here break; case "InitedDragged": //do stuff here break; } //---------------------------------------------------------------------- ----------------- Imo this is a very readable solution - no comments needed to explain what the code is doing. Above code is generated and traced to the Output window with this: events = ['Inited','Clicked','Bedazzeled','Dragged']; numElems = events.length; combos = new Array(); // find the combinations c=0; while(c<numElems*numElems){ combo = ''; for(var i=0; i<numElems; i++){ if(Math.random() < 0.5){ combo += events[i]; } } inArray = false; for(var i=0, len=combos.length; i<len; i++){ if(combo == combos[i]){ inArray = true; break } } if(!inArray){ combos[c++] = combo; } } combos.sort(); // write the code for copy/paste from the output window trace("// When event '"+ events[0]+"' is dispatched, set the flag "+events[0]+" to true, etc."); trace("combo = '';"); for(var i=0, len=events.length; i<len; i++){ trace("if(events[i]){ combo += '"+events[i]+"';}"); } trace('\nswitch(combo){'); // write the switch statement for(var i=0, len=combos.length; i<len; i++){ trace('\n case "'+combos[i]+'":'); trace(' //do stuff here'); trace(' break;'); } trace('}'); Just overwrite the 'events' Array to accommodate your needs. hth -------------- Andreas Weber motiondraw.com -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of eric dolecki Sent: Mittwoch, 25. Januar 2006 21:17 To: Flashcoders mailing list Subject: Re: [Flashcoders] checking combinations Thats interesting. A bit more involved than what I was doing but it is indeed interesting. On 1/25/06, Daniel Cascais <[EMAIL PROTECTED]> wrote: > > What about something like this: > > > var results:Array = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", > "j", "k", "l", "m", "n", "o", "p" ]; > > function getResult( value1:Boolean, value2:Boolean, value3:Boolean, > value4:Boolean ):Number { > var resultIndex:Number = 0; > > if( value1 ) resultIndex |= 8; > if( value2 ) resultIndex |= 4; > if( value3 ) resultIndex |= 2; > if( value4 ) resultIndex |= 1; > > return results[ resultIndex ]; > } > > trace( getResult( true, true, false, true) ); > > /* > Results Table > > value1 value2 value3 value4 Results > 0 0 0 > 0 a > 0 0 0 > 1 b > 0 0 1 > 0 c > 0 0 1 > 1 d > 0 1 0 > 0 e > 0 1 0 > 1 f > 0 1 1 > 0 g > 0 1 1 > 1 h > 1 0 0 > 0 i > 1 0 0 > 1 j > 1 0 1 > 0 k > 1 0 1 > 1 l > 1 1 0 > 0 m > 1 1 0 > 1 n > 1 1 1 > 0 o > 1 1 1 > 1 p > */ > > On 1/25/06, eric dolecki <[EMAIL PROTECTED]> wrote: > > I have 4 variables I need to check the states of routinely... and > > combinations thereof. > > -- > Daniel Cascais > Tel: +56 (0)2 4589495 > Cel: +56 (0)9 9417355 _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders