Flex Builder has that great "Constraints" UI that allows you to anchor components to their parent that I'm sure everyone has used.

But what happens if you create an object in actionscript and then you want add constraints to it? There is no "top" property you can set to anchor the component to the top. It turns out the constraint system is entirely based on Flex's style system and can be used as follows:
var someComponent:SomeComponent = new SomeComponent();
var style:CSSStyleDeclaration = new CSSStyleDeclaration();
style.setStyle("top", 0);
style.setStyle("horizontalCenter", 0);
someComponent.styleDeclaration = style;
And BAMN, someComponent will be anchored to the top, center of it's parent (assuming it's parent is a container that supports anchors.) Available style selectors are:
- top
- left
- right
- bottom
- horizontalCenter
- verticalCenter
You could also specify the styles in a css sheet, or by adding them to an already existing style.
Edit...
As a commenter has posted you can also use the setStyle method in addition to the various other methods I mentioned. So the following would also work:
someComponent.setStyle("top",0);
Labels: Actionscript, development, flex