Flex doesn't have the linguistic support for enums that Java has. They are often just used as a constants file with a unique namespace in Flex.
The other difficulty is that larger Flex projects can cause colliding worlds between Flex developers, Javascript developers, Java/C#/C developers and other front-end technologies as well. As a consequence there can be many differing ideas as to how to do things as what is considered the norm for each language and platform gets written into one codebase.
The type safe enum pattern can be adhered to in Flex but with the difficulty of Actionscript having no private constructors. For instance:
package {
public final class CreditCardEnum {
public static const AMERICAN_EXPRESS:CreditCardEnum = new CreditCardEnum("American Express");
public static const MASTERCARD:CreditCardEnum = new CreditCardEnum("Mastercard");
private var type:String;
public function CreditCardEnum(type:String):void {
this.type = type;
}
}
} Where this would be instantiated with:
var creditCardEnum:CreditCardEnum = CreditCardEnum.AMERICAN_EXPRESS;Rather than hiding the private constructor off as a class outside the package name, it is often easier in the ECMAscript based languages to put in a comment saying please don't use the constructor, instead use it as an enum. Alternatively type safe enums can be created by the enum class itself, though again this requires the discipline of passing in the object's public static const's as the argument.
package {
public final class DebitCardEnum {
public static const BEAR_SEARNS:String = DebitCardEnum.create("Bear Stearns");
public static const WAMU:String = DebitCardEnum.create("WaMu");
private var type:String;
private static function create(debitCardType:String):DebitCardEnum {
var enum:DebitCardEnum = new DebitCardEnum();
enum.type = debitCardType;
return enum;
}
}
} Where this would be instantiated with:
var debitCardEnum:DebitCardEnum = DebitCardEnum.WAMU;Both examples are typical of the trade offs you make in Flex and ECMA script languages with object oriented patterns.








