Whenever i want to draw something in
Flash i subclass fl.core.UIComponent
instead of Sprite or Movieclip because
of it's saner width / height
implementation (NB this isn't the Flex
UIComponent).
I believe it pretty much depends on your project requirements. If you are using other fl.controls it might make sense to have your custom components compatible with the rest of the flash components for various reasons(like passing using dataProviders or other data around)
For example, imagine you have a button
- good use case for a UIComponent - but the button has an icon, a text
string and a disclosure arrow. ie 3
children. I would make these 3
children as UIComponents as well.
This example isn't a particularly good one because the Button component(fl.controls.Button) already has an icon you set using setStyle():
myButton.setStyle("icon", MyIconClass);
I know i could make my own subclass of
Sprite that overrides the width /
height methods & properties but does
anyone see any downsides to using
UIComponent in this manner?
Personally I try to keep things as simple as possible. If it's necessary for subclass a UIComponent, go for it, but be aware of the component's life cycle with the Flash V3 Component architecture (fl.controls). Try not to commit/invalidate to often as you might cause performance issues that become noticeable when using more instances.
There is a very good devnet article series on Creating ActionScript 3.0 components in Flash by Jeff Kamerer.
Here are some of the topics covered:
- Set up the layers and frames in your
component movie clip symbol
- Implement Live Preview for your
component
- Dispatch events
- Support styles and easily editable skins
- Manage drawing with the invalidation model
- Manage focus
- Handle keyboard input
- Create a compiled clip shim for your ActionScript definitions
- Deploy your component to the Components panel
So, in short, if you can handle resizing/positioning without subclassing UIComponents, I would recommend that. The simpler, the better. Also, you will not be introducing a dependency to the V3 components when you'll need to migrate parts of your projects.
If you must subclass UIComponents, keep them as simple/light as possible. Personally I think they're complex enough already, but at least they're better than the V2 (actionscript 2) components.
HTH