Can a Flex programmatic skin draw text?
Can a Flex programmatic skin draw text? The short answer is, yes! The longer answer is, it’s a little tricky. Let me break it down. First of all, in Flash, the only way to draw text is with a TextField. Flex can’t do anything about that, so any Flex class that wants to draw text has to do it using a TextField.
Your programmatic skin is going to derive from ProgrammaticSkin, which is a DisplayObject, not a DisplayObjectContainer. So it’s not as simple as creating a TextField and adding it as a child. However, it is as simple as creating a TextField and adding it as a child of the parent. Here’s how you get the parent’s child list:
var childrenList:IChildList = parent is Container ? Container(parent).rawChildren : IChildList(parent);
This technique was brazenly stolen from mx.skins.RectangularBorder, so I’m assuming it’s a reasonable thing to do. Any opinions to the contrary?
Why would you want to draw text in a skin, though? Admittedly, it’s kind of an edge case. Mostly skins are about pretty chrome, funny-shaped borders, light and shadows, etc. Our particular case is a worthwhile exception, though. Trust me.
Technorati Tags: ActionScript, Flash, Flex, Programmatic skin




Recent Comments