[flexcoders] FLEX BUG: Nested switch case statements fail to compile correctly
I have found that code containing nested switch/case statements fail to work correctly even though they compile without errors. I'm including two different versions of the same code, one using switch/case statements, the other using if/else statements. The switch/case version won't allow me to set breakpoints or examine variables in the code following the switch/case statements, although I can single-step through each line of the code during debugging. The if/else version works as expected. * SWITCH/CASE VERSION * private function clickHandler(clickEvent:ItemClickEvent):void { switch (clickEvent.index) { case VIEW_PREVIOUS: // Previous { switch (ecModel.viewingMode) { case (EventCalendarModel.VIEWING_MODE_DAYS): ecModel.addDaysToSelectedTime(-1); break; case (EventCalendarModel.VIEWING_MODE_WEEKS): ecModel.addWeeksToSelectedTime(-1); break; case (EventCalendarModel.VIEWING_MODE_MONTHS): ecModel.addMonthsToSelectedTime(-1); break; } } break; case VIEW_DATESELECTOR: // Select date break; case VIEW_NEXT: // Next switch (ecModel.viewingMode) { case (EventCalendarModel.VIEWING_MODE_DAYS): ecModel.addDaysToSelectedTime(1); break; case (EventCalendarModel.VIEWING_MODE_WEEKS): ecModel.addWeeksToSelectedTime(1); break; case (EventCalendarModel.VIEWING_MODE_MONTHS): ecModel.addMonthsToSelectedTime(1); break; } break; } // Explicitly generate a PropertyChangeEvent so binding will work as expected if (ecPreviousDate.getTime() != ecModel.selectedTime.getTime()) { var pcEvent:PropertyChangeEvent = new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE); pcEvent.kind = "update"; pcEvent.property = "selectedTime"; pcEvent.oldValue = ecPreviousDate.getTime(); pcEvent.newValue = ecModel.selectedTime.getTime(); pcEvent.source = ecModel; dispatchEvent(pcEvent); } } } * IF/ELSE VERSION * private function clickHandler(clickEvent:ItemClickEvent):void { var ecPreviousDate:Date = new Date(ecModel.selectedTime); if (clickEvent.index == VIEW_PREVIOUS) // Previous button clicked { if (ecModel.viewingMode == EventCalendarModel.VIEWING_MODE_DAYS) { // Previous Day ecModel.addDaysToSelectedTime(-1); } else if (ecModel.viewingMode == EventCalendarModel.VIEWING_MODE_WEEKS) { // Previous Week ecModel.addWeeksToSelectedTime(-1); } else if (ecModel.viewingMode == EventCalendarModel.VIEWING_MODE_MONTHS) { // Previous Month ecModel.addMonthsToSelectedTime(-1); } } else if (clickEvent.index == VIEW_NEXT) // Next button clicked { if (ecModel.viewingMode == EventCalendarModel.VIEWING_MODE_DAYS) { ecModel.addDaysToSelectedTime(1); } else if (ecModel.viewingMode == EventCalendarModel.VIEWING_MODE_WEEKS) { ecModel.addWeeksToSelectedTime(1); } else if (ecModel.viewingMode == EventCalendarModel.VIEWING_MODE_MONTHS) { ecModel.addMonthsToSelectedTime(1); } } // Explicitly generate a PropertyChangeEvent so binding will work as expected if (ecPreviousDate.getTime() != ecModel.selectedTime.get
Re: [flexcoders] FLEX BUG: Nested switch case statements fail to compile correctly
Hello, the problem might be caused by the { and } you place around you switch statements. The following code works just fine. Greetz Erik public function testAS() { var x1:Object = {type: "x", data: {a: 1}}; var x2:Object = {type: "x", data: {a: 2}}; var y1:Object = {type: "y", data: {a: 3}}; var y2:Object = {type: "y", data: {a: 4}}; check(x1); check(x2); check(y1); check(y2); };private function check(o:Object):void { switch (o.type) { case "x": switch (o.data.a ) {case 1: trace("1 X"); break;case 2: trace("2 X"); break; }; break; case "y": switch (o.data.a) { case 3: trace("3 Y"); break;case 4: trace("4 Y"); break; }; break; }; }; output: 1 X 2 X 3 Y 4 Y __._,_.___ -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com SPONSORED LINKS Software development tool Software development Software development services Home design software Software development company Your email settings: Individual Email|Traditional Change settings via the Web (Yahoo! ID required) Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe __,_._,___
RE: [flexcoders] FLEX BUG: Nested switch case statements fail to compile correctly
Turns out this is a Player bug. An engineer investigated and filed it. Some notes: In this case, it turns out the bug is in the player, not the compiler. It's actually even worse than he says: you can have a single switch statement, not a nested one, and still reproduce the problem. The workarounds are the ones he already discovered: either to set a breakpoint earlier in the function and then step until you get to the code you want to examine, or else don't use if/then instead of a switch statement. So we’ll see what we can do but you know what you can do in the meantime. Matt From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of EECOLOR Sent: Tuesday, October 10, 2006 1:47 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] FLEX BUG: Nested switch case statements fail to compile correctly Hello, the problem might be caused by the { and } you place around you switch statements. The following code works just fine. Greetz Erik public function testAS() { var x1:Object = {type: "x", data: {a: 1}}; var x2:Object = {type: "x", data: {a: 2}}; var y1:Object = {type: "y", data: {a: 3}}; var y2:Object = {type: "y", data: {a: 4}}; check(x1); check(x2); check(y1); check(y2); }; private function check(o:Object):void { switch (o.type) { case "x": switch (o.data.a ) { case 1: trace("1 X"); break; case 2: trace("2 X"); break; }; break; case "y": switch (o.data.a) { case 3: trace("3 Y"); break; case 4: trace("4 Y"); break; }; break; }; }; output: 1 X 2 X 3 Y 4 Y __._,_.___ -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com SPONSORED LINKS Software development tool Software development Software development services Home design software Software development company Your email settings: Individual Email|Traditional Change settings via the Web (Yahoo! ID required) Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe __,_._,___