createEnumIndex

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

createEnumIndex

Nathan Hüsken
Hi,

I have the following code:

(...)
enum Color {
  RED;
  GREEN;
  BLUE;
  ORANGE;
}
(...)
  static public function randomColor() : Color {
    var index : Int = Std.random(4);
    return Type.createEnumIndex<Color>(index); // This is line 19
  }

Compiling this, I get:
Box.hx:19: characters 11-37 : Cannot compare e : Enum<Unknown<0>> ->
index : Int -> ?params : Array<Dynamic> -> Unknown<0> and #Color

I marked line 19 in the code.
What is wrong, I do not get it ...?

Thanks!
Nathan

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: createEnumIndex

Jan_Flanders


On Thu, Sep 22, 2011 at 2:36 PM, Nathan Hüsken <[hidden email]> wrote:
Hi,

I have the following code:

(...)
enum Color {
 RED;
 GREEN;
 BLUE;
 ORANGE;
}
(...)
 static public function randomColor() : Color {
   var index : Int = Std.random(4);
   return Type.createEnumIndex<Color>(index); // This is line 19
 }

Compiling this, I get:
Box.hx:19: characters 11-37 : Cannot compare e : Enum<Unknown<0>> ->
index : Int -> ?params : Array<Dynamic> -> Unknown<0> and #Color

I marked line 19 in the code.
What is wrong, I do not get it ...?

Thanks!
Nathan

--
haXe - an open source web programming language
http://haxe.org


var c = Type.createEnumIndex(Color, 3);

or:

using Type;
var c = Color.createEnumIndex(3);

Jan
 


--
haXe - an open source web programming language
http://haxe.org