Comments on: Typesafe assignable enumerations in AS3 https://www.liranuna.com/typesafe-assignable-enumerations-in-as3/ Just another coder Thu, 29 Aug 2019 13:52:12 +0000 hourly 1 https://wordpress.org/?v=5.1.2 By: Robert Cesaric https://www.liranuna.com/typesafe-assignable-enumerations-in-as3/comment-page-1/#comment-6884 Wed, 28 Sep 2011 02:58:02 +0000 http://www.liranuna.com/?p=769#comment-6884 Great work!! I combined sameer’s and chris’ ideas above. I ran a few tests and it appears to work the same and doesn’t require the recursive constructor:

public class Direction
{

public static const NONE:Direction = new Direction(“undefined”);
public static const UP:Direction = new Direction(“UP”);
public static const DOWN:Direction = new Direction(“DOWN”);
public static const LEFT:Direction = new Direction(“LEFT”);
public static const RIGHT:Direction = new Direction(“Right”);

private var _value:String;

public function Direction(value:String)
{
this._value = value;
}

public function toString():String
{
return _value;
}

}

]]>
By: chris https://www.liranuna.com/typesafe-assignable-enumerations-in-as3/comment-page-1/#comment-6866 Mon, 10 Jan 2011 10:07:08 +0000 http://www.liranuna.com/?p=769#comment-6866 what’s stopping you from passing in “null” into the constructor?

]]>
By: wyrmmage https://www.liranuna.com/typesafe-assignable-enumerations-in-as3/comment-page-1/#comment-6621 Wed, 02 Dec 2009 17:33:39 +0000 http://www.liranuna.com/?p=769#comment-6621 Very useful!

Thank you for this :)

]]>
By: Mohan https://www.liranuna.com/typesafe-assignable-enumerations-in-as3/comment-page-1/#comment-6617 Wed, 28 Oct 2009 16:58:11 +0000 http://www.liranuna.com/?p=769#comment-6617 Was quite useful, especially Sameer’s comment. I think I’d go with that :)

]]>
By: sameer https://www.liranuna.com/typesafe-assignable-enumerations-in-as3/comment-page-1/#comment-6605 Wed, 12 Aug 2009 19:44:13 +0000 http://www.liranuna.com/?p=769#comment-6605 instead of the switch statement inside toString() how about have a instance variable _value and pass in the hard-coded value through the constructor:
public function Direction(d:Direction, value:String) {
this._value = value
}

and return _value inside toString() method. Would this work?

]]>
By: Alex Russell https://www.liranuna.com/typesafe-assignable-enumerations-in-as3/comment-page-1/#comment-6569 Sat, 28 Feb 2009 06:18:25 +0000 http://www.liranuna.com/?p=769#comment-6569 Thanks for this! Really useful.

]]>
By: justin https://www.liranuna.com/typesafe-assignable-enumerations-in-as3/comment-page-1/#comment-6538 Mon, 15 Sep 2008 21:36:28 +0000 http://www.liranuna.com/?p=769#comment-6538 you should declare the class as final, so it can not be extended to override anything you’ve done.

]]>