[flexcoders] double check that this Switch statement can't work...
Hi, I was hoping I could use a switch statement to test what Object type is selected on my ADG but I don't think it's possible and need to use an if, else if, chain... if ( orgStructureADG.selectedIndex = 0 ) { switch ( orgStructureADG.selectedItem ) { case VendorCompcodeData: { trace( VendorCompcodeData ); } case VendorPurchorgData: { trace( VendorPurchorgData ); } default: { trace( default ) } } } I can't drop in the is statement. Is this right, or am I going mad? :) Cheers, Nick
Re: [flexcoders] double check that this Switch statement can't work...
In AS3 switch construction uses break - otherwise it'll fall through (all cases will be executed after the first case that matches the condition). Besides, you can leave the condition blank and put any statement in the case block, however, you have to be careful that the cases are unique. Example: switch ( true ) { case (orgStructureADG.selectedItem is VendorCompcodeData): { trace( VendorCompcodeData ); } break; case (orgStructureADG.selectedItem is VendorPurchorgData): { trace( VendorPurchorgData ); } break; default: { trace( default ) } } However, I would do it like this: switch ((orgStructureADG.selectedItem as Object).prototype) { case VendorCompcodeData: { trace( VendorCompcodeData ); } break; case VendorPurchorgData: { trace( VendorPurchorgData ); } break; default: { trace( default ) } } Best. Oleg
Re: [flexcoders] double check that this Switch statement can't work...
Sorry, typo... switch ((orgStructureADG.selectedItem as Object).constructor) { case VendorCompcodeData: { trace( VendorCompcodeData ); } break; case VendorPurchorgData: { trace( VendorPurchorgData ); } break; default: { trace( default ) } }
Re: [flexcoders] double check that this Switch statement can't work...
Ah nice... Cheers Oleg. I always put my break; statement inside the case brackets. I quite like the 1st way... Easier to read I think. Thanks, Nick On 25 March 2010 12:49, Oleg Sivokon olegsivo...@gmail.com wrote: In AS3 switch construction uses break - otherwise it'll fall through (all cases will be executed after the first case that matches the condition). Besides, you can leave the condition blank and put any statement in the case block, however, you have to be careful that the cases are unique. Example: switch ( true ) { case (orgStructureADG.selectedItem is VendorCompcodeData): { trace( VendorCompcodeData ); } break; case (orgStructureADG.selectedItem is VendorPurchorgData): { trace( VendorPurchorgData ); } break; default: { trace( default ) } } However, I would do it like this: switch ((orgStructureADG.selectedItem as Object).prototype) { case VendorCompcodeData: { trace( VendorCompcodeData ); } break; case VendorPurchorgData: { trace( VendorPurchorgData ); } break; default: { trace( default ) } } Best. Oleg