Archive

Monthly Archives: March 2010

I’ve recently had to parse dates and it turned out that Flex is not very good at it. According to specs, Date.parse() only handle following formats:

MM/DD/YYYY HH:MM:SS TZD
HH:MM:SS TZD Day Mon/DD/YYYY
Mon DD YYYY HH:MM:SS TZD
Day Mon DD HH:MM:SS TZD YYYY
Day DD Mon HH:MM:SS TZD YYYY
Mon/DD/YYYY HH:MM:SS TZD
YYYY/MM/DD HH:MM:SS TZD

Which is fine as long as you live in United States. Not all of us do so I needed to look further. There’s parseDateString method on mx.formatters.DateFormatter but it too does not provide required functionality.

So here is my implementation of date parser. It accepts specified format string and tries to parse given data accordingly. You can use D, M and Y to define this format string and any other character in it will be treated as separator and matched directly. You can refer to unit test provided together with source for usage examples. Please note that set of supported features matches my requirements and you can probably find more complete and feature rich solutions out there.

Advertisements

I’ve been recently working on a component that contained rotated label in it and I discovered that using width and height attributes (MXML) in such case might result in unexpected behaviour.

The problem occurs when you start using absolute values for these properties. If for example you set height to be 100% then actual height of the component will be influenced. However if you set height to be 500, width of the component will be changed instead.

It turns out, that percent size (which is calculated relative to parent and post-transform) would take component’s rotation into account while explicit size is calculated pre-transform (which is a change in Flex 4). While it is all working according to specification trying to use “proxy setters” like width/height might cause some confusion.

You can use this little app to try it.