Alex Rivera | Logout

How to define enum in as3?

Asked 2010-03-06T21:23:00.403
22

Is there a way to define an enum in AS3 in a way we do it in other languages? I can define constants with defined values like that:

private const CONST_1:int = 0;
private const CONST_2:int = 1;
private const CONST_3:int = 2;

and so on. If I want to insert some other constant between 3 these I need to move all values like that:

private const CONST_1:int = 0;
private const CONST_2:int = 1;
private const CONST_2A:int = 2;
private const CONST_3:int = 3;

while in other language I would end up with only adding a new member to enum closure like that:

enum {
    CONST_1 = 0,
    CONST_2,
    CONST_2A,
    CONST_3
} MyConstEnum;

Does AS3 has something similar?

Thanks

Edit
Report

1 Answer

13
public static var NUM_ENUM_VALUES:int = 0;
public static const EV_MONDAY:int = NUM_ENUM_VALUES++;
public static const EV_TUESDAY:int = NUM_ENUM_VALUES++;
public static const EV_WEDNESDAY:int = NUM_ENUM_VALUES++;
public static const EV_THURSDAY:int = NUM_ENUM_VALUES++;
answered 2012-03-19T11:25:46.820

Your Answer