ActionScript 3 object property name for string?

I want to exclude the use of magic strings in the following cases:

BindingUtils.bindProperty(obj1, "propertyName", obj2, ["childObj", "anotherProperty"]);

or

var ddl:DropDownList = new DropDownList();
ddl.labelField = "propertyName";

it would just type something like:

ddl.labelField = GetPropertyName(ComplexType.propertyName);

This will simplify refactoring and eliminate runtime errors when changing a property name.

Any ideas?

+3
source share
3 answers

Not sure if I understand your problem correctly. You can easily define static constants in a separate class to eliminate the entire magic string.

// In class ConstantContainer

public static const PROPERTY_NAME: String = "propertyName";

// In anywhere else
ddl.labelField = ConstantContainer.PROPERTY_NAME;
+4
source

. , , . .

, , , .

+1

A discussion on a similar topic with some ideas that might interest you:

Using the vs string vs enum object

0
source

All Articles