Enumeration on a property – Flex 3

Posted on Apr 7, 2010

Often when you create custom controls in flex application, you create custom properties and the apps consuming your components needs to set those properties for the component to work properly.

lack of documentation often lead to situation when the developer consuming your component doesn’t know what are the values you expect of him to set.

Well, there’s a solution for this, Flex introduced the “Inspectable” metadata tag, you can simply set this tag above your setter and the developer will get full intellisense and be able to know what you meant.

In this simple application, I create a custom mxml component based on Canvas, I create a property called myString and created an “Inspectable” metatag.

like so:

[actionscript3]

[Bindable]

private var _myString:String;

[Inspectable (enumeration=“stringValue1,stringValue2,stringValue3”)]

public function set myString(val:String):void

{

_myString = val;

}

[/actionscript3]

So far, it’s as simple as it can get, now, check out a screenshot of my flex builder when setting this property from outside

And that’s it, that’s how simple it is to create enumeration and ease the life on your fellow developers.