as 使用类模拟枚举类

//这种类一般不需要继承(final), 成员也应该是静态常量(static const)
//---------------------------------
package {
    public final class CTest {
        public static const MALE:String   = "male";
        public static const FEMALE:String = "female";
    }
}
//---------------------------------
var age:String;
age = "female";
//age = "male";
 
switch (age) {
    case CTest.MALE:
        trace("Male");
        break;
    case CTest.FEMALE:
        trace("Female");
        break;
    default:
        trace("?");
}

posted on 2014-01-21 16:14  主人的成长  阅读(195)  评论(0编辑  收藏  举报

导航