Hi Jim, very interesting question. I think you'll find reading this informative about the components instantiation:
I don't think if should have to be that complicated you could just pre-design your custom arrow using AS3 and then show it using an effect, or a sequence of effects.
I would let Flex worry about when to draw. Create your component and when you add it with addChild(), it draws.
If you need to draw inside an object, then what user or system event is proper for the behavior of the application? creationComplete, click, rollOver? When such a UI "significant event" event is handled, you could even call a function that tells your drawing component to draw.
Or you could just use SWFLoader to load an animation created in Flash, which for your purpose sounds really a good way to go, maybe...
I appreciate your response, and your suggestion to avoid (needless) complication -- with which I heartily agree. :-)
You suggest specifically that I "could just pre-design your custom arrow using AS3 and then show it using an effect, or a sequence of effects." This is indeed exactly what I'm trying to do, so we're on the same page. I'm attempting to define an arrow class in AS3, and then use a Tween/TweenEffect/TweenEffectInstance to animate it within Flash.
Unfortunately, the problem lies in "pre-designing the custom arrow using AS3." How should I do this, exactly?
I figure that the Arrow class has to be a subclass of MovieClip, so that Flash can tween it. I figure that the Arrow class should instantiate (through code, not MXML) two child views:
- one to draw the line, and
- one to draw the arrowhead on the end of the line.
But -- and this is the initial question -- where do I put those child views' drawing code?
I've got to put the drawing code for the line and arrowhead somewhere...in a event handler, callback, or method of their class definitions. If the line and arrowhead were UIComponents, that would be easy: put the drawing code into an override of updateDisplayList(). But my arrows involve no user interactivity; they are just shapes animated on the screen. Making them subclasses of UIComponent would give them a ton of excess baggage, and make me turn off a lot of functionality that would otherwise default to being on.
Perusing the Flex class hierarchy, the line and arrowhead seem like they ought to be subclasses of the Shape class. As mentioned in the original post, the Shape class has a RENDER event, but it seems to be sent to tell and object to PREPARE to be rendered, to not actually render itself.
Which brings me back to my initial question: in what event/callback/method should a Shape actually render itself? Or, perhaps, is the architecture of my proposed solution wrong?
I think I'm starting to understand Flash/AIR's drawing architecture. My current thinking on the topic is described in this blog post:
I would welcome the comments of the esteemed readers of this forum on the ideas discussed therein.