Oh, it works correctly, assuming I'm not dumb and give a couple
"constants" the same values.  It just seems strange for this to be
allowed.  Thus the question "why does this work".  I would think it
shouldn't even compile.

 -Andy

On 4/17/07, Hans Wichman <[EMAIL PROTECTED]> wrote:
Hi,
what were your own test results? :)

Yes you can do this, and flash will execute the first matching case
statement. Any other matches will be ignored.

greetz
JC


On 4/17/07, Andy Herrman <[EMAIL PROTECTED]> wrote:
>
> I just realized that there are a number of switch statements in my
> code which probably shouldn't work, yet appear to, and I'm wondering
> why.
>
> Here's a really simple example.  I have a class that tracks the
> connection state of my app, with the following values used as the
> states (read-only attributes simulating constants):
>
> public static function get CONNECTED():String { return "CONNECTED"; }
> public static function get FAILURE():String { return "FAILURE"; }
> public static function get NOT_CONNECTED():String { return
> "NOT_CONNECTED"; }
>
> In the code that lets you set the state to a particular value it does
> a sanity check to make sure the state value is one that's expected
> (since in theory the user could provide any string value):
>
> public function setConnectionState(cs:String):Void {
>    switch(cs) {
>      case ConnectionState.CONNECTED:
>      case ConnectionState.FAILURE:
>      case ConnectionState.NOT_CONNECTED:
>        break;
>      default:
>        cs = ConnectionState.NOT_CONNECTED;
>        break;
>    }
>    this._connectionState = cs;
> }
>
> Now in Java switch statements must use constants for the case values.
> You can do something like I just did, but the variables being
> referenced must be declared final (so the compiler knows they won't
> change).  There isn't any equivalent to this in Flash (I simulate
> constants by doing read only properties), so why does the case
> statement work?  Does flash actually execute the stuff after the
> 'case' keyword?  What happens if multiple of those things return the
> same value (for instance, say both CONNECTED and FAILURE returned
> "foo")?
>
>   -Andy
> _______________________________________________
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to