[CLOSED] UnityScript - enum to numeric value error

I get error: The type ‘int’ does not have a visible constructor that matches the argument list ‘(States)’. But I don’t see the error - it’s explicit conversion from enum to int.

enum States
{
   IDLE, FALLING, FLYING
}

var listStates : State[] = new State[NUMBER_OF_STATES];

function initialize() : void
{
    //init list of states
    listStates[int(States.IDLE)] = new IdleState();  // ERROR
    listStates[int(States.FALLING)] = new FallingState(); // ERROR
    listStates[int(States.FLYING)] = new FlyingState();   // ERROR
}

Why this error message?

Try :

function initialize() : void
{
    //init list of states
    listStates[States.IDLE] = new IdleState();
    listStates[States.FALLING] = new FallingState();
    listStates[States.FLYING] = new FlyingState();
}

Or if you really want an explicite cast :

function initialize() : void
{
    //init list of states
    listStates[(int)States.IDLE] = new IdleState();
    listStates[(int)States.FALLING] = new FallingState();
    listStates[(int)States.FLYING] = new FlyingState();
}