Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionScript 3 object's property name to string?

I want to eliminate usage of magic strings in these:

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

or

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

it would be sweet to just type something like:

ddl.labelField = GetPropertyName(ComplexType.propertyName);

It would allow easy refactoring and would eliminate runtime errors when property name changes.

Any ideas?

like image 349
mizi_sk Avatar asked May 08 '26 22:05

mizi_sk


1 Answers

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

// In class ConstantContainer

public static const PROPERTY_NAME:String = "propertyName";

// In anywhere else
ddl.labelField = ConstantContainer.PROPERTY_NAME;
like image 79
taskinoor Avatar answered May 10 '26 22:05

taskinoor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!