views:

24

answers:

0

I would really like to be able to write something like the following:

<magical:ClassFactory id="factory">
  <some:UIComponentOrWhatever with_event="handlers(event)"
                              event_snippets="like.so()"
                              code_values="{ foo + ' ' + bar }"
                              bound_values="{bindable_foo}"
                              the_works="true" />
</magical:ClassFactory>

So that later on in the code, I can do:

var instance:UIComponentOrWhatever = factory.newInstance(); 
instance.id="whatever";
some_group.addChild(instance);

Thus taking advantage of all the happy IDE autofill conveniences, and all the bound variable conveniences of MXML, but being able to make "more of them on request." Problems:

  1. The simple ClassFactory can't be instantiated, it's not an IMXMLObject
  2. You can wrap it, but need to pass it the properties as an <fx:Object>, which can't do binding properly
  3. And none of the nice IDE auto-fill things help out at all, obviously
  4. Cloning UIComponents isn't recommended
  5. And even if I manage to do all the introspection, there are still write-only fields on some objects that you can no longer introspect on the original and then set on the copy

Sure, it can be done 100% in AS3, but all the binding is a pain. Sure, you can subclass UIComponentOrWhatever and fill in the values, then instantiate copies of that... but then you're baking the values into the class and not the caller that knows what they need to be, and which might be passing protected or private stuff to them that wouldn't be available in a separate file/class.

I investigated trying to make just such a thing as the above, but my Flex juju isn't strong enough. A little guidance from an MXML jedi would be appreciated. :-)