Or even shorter: public function handleUpdate(a:Object,b:Object,c:Object,d:Object) { var handlerName:String = 'onUpdate'; if (a.selected){handlerName+= 'A'}; if (b.selected){handlerName+='B'}; // etc.
if (this[handlerName]==undefined) { trace("We haven't got a handler called:"+handlerName); return; } this[handlerName](); } public function onUpdateA() { // do stuff for A etc. } public function onUpdateAB() { // do stuff for AB etc. } Cheers, Ian On 1/26/06, Andreas Weber <[EMAIL PROTECTED]> wrote: > > Nice! > And I was determined not to post again, but at a certain stage my mental > block irresistibly kicked in again: > why ingeniously bit-wise encode the combinations just to later decode them > for better readabilty? > > Why not drop this altogether as we won't do any encoding: > static var STATE_A:Number = 1; // 1 << 0 > > Define the handlers like > handlers = {};// or type it/ make it a class > handlers["STATE_A"] = Delegate.create(this,handleAOnly); > // etc. > > And finally: > > public function handleUpdate(a:Object,b:Object,c:Object,d:Object) > { > state = 'STATE_'; > if(a.selected){ state += 'A'}; > if(b.selected){ state += 'B'}; > // etc. > > handlers[state](); > } > > What's the benefit of encoding/decoding numbers? Please enlighten me! > > Cheers! > -------------- > Andreas Weber > motiondraw.com > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders