Home > Flex > Can a Flex programmatic skin draw text?

Can a Flex programmatic skin draw text?

March 17th, 2007

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: , , ,

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
Author: David Coletta Categories: Flex Tags:
Comments are closed.