Hello :) in AS2 you can create constants with the ASSetProgFlags global method :
public static var CONNECTED:String = "CONNECTED" ; public static var FAILURE:String = "FAILURE" ; public static var NOT_CONNECTED:String = "NOT_CONNECTED"; private static var __ASPF__ = _global.ASSetPropFlags( ConnectionState , null , 7, 7 ) ; ConnectionState is the name of your enumeration static class :) For me.. your code is ok : public function setConnectionState(cs:String):Void { switch(cs) { case ConnectionState.CONNECTED : case ConnectionState.FAILURE : { break; } default : { cs = ConnectionState.NOT_CONNECTED ; } } this._connectionState = cs ; } EKA+ :) 2007/4/17, Andy Herrman <[EMAIL PROTECTED]>:
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