A few introspection classes to keep things going

Okay, it has been way to long since I have had the opportunity to post anything of value. So, here are a few classes I wrote called Constructor, Field, Method and Klass. They also use one additional class named MetaData tools. These classes roughly mirror the java.lang.reflect classes. They aren’t quite as thorough, but there is some good stuff in here.

In the next few weeks these will be released as part of a larger project, but I thought I would take the opportunity to throw these early versions online as I have found them extremely useful over the last month. In addition to the ‘normal’ stuff you would expect in introspection, these also take care of a few gotchas that you might run into if you are used to Java and now play in the AS sandbox.

First, the default describeType method of the flash.utils package doesn’t actually know how to get constructor parameters from the metadata until the class has been constructed, in some capacity, once. This is really frustrating but can be handled by doing a behind the scenes instantiation and capture. Not gorgeous, but it works and gets me the parameters I wanted.

Second, DescribeTypeCache has a few issues regarding when a description is cached. If you cache it for the first time before the first instance is built, you will forever get that version back. This means that the cached record may look different dependent upon the order you called it… so not cool.

Third, pre-flash player 10, you can’t specify that an array will contain a given type of data. Flex has a metadata tag called ArrayElementType, which MXML will respect (in some cases) but overall it is mostly useless. This library will actually look at that ArrayElementType at runtime and at least tell you what data you expected to go into the array. This is actually quite useful in a number of situations ( however, you need to ensure you instruct your project to keep the ArrayElementType metadata.

Fourth, you can fake out having a constructor.apply() at least for a limited set of arguments.

Fifth, actually, I’m not sure what’s fifth, so just grab these classes and give them a whirl if you are interested. I promise they will be documented and have some asdocs by the time they are released, but these are a start.

Also, in the next month I will be presenting at both 360|Flex Indianapolis and webDU (within a few days of each other). These are two of my favorite conferences. They both have a unique message and a great crew behind them. I hope to post more about these soon, but if you can make either of these conferences, I would love to sit down and explain the bigger picture of where these classes come from, and, hopefully, get you playing with some very interesting new code.

Cheers,
Labriola Download

There are no comments.

Leave a Reply