4 Replies Latest reply on May 18, 2009 11:56 AM by JimPlamondon

    JimP: When to draw?

    JimPlamondon Level 1



      Please forgive me for asking what is almost undoubtedly a stupid question: when should a Flex object draw itself?


      That is, what event/callback/method notifies a drawable Flex object that NOW is the time for it to draw itself?


      DisplayObject's RENDER event seems likely, but it is described as being "the last opportunity for objects listening for this event to make changes before the display list is rendered." That implies that some other event/callback/method is sent/called/dispatched to actually effect said rendering, for which the RENDER event was mere preparation.


      So: when should a Flex object draw itself?


      Hoping that the answer will turn out to be exquisitely complex with deep architectural implications (hence validating the question as being something other than moronic), I am


      Sincerely Yours,


      Jim Plamondon
      Austin, Texas



      P.S.: If a little more context would help, I've been trying to figure out how to draw an arrow that grows, over time, from nothing at Point A to a line (with arrowheard) starting at Point A and extending towards, and hence pointing to, Point B.  I figure that I need to draw the arrow progressively using a Tween effect (which is a whole 'nother can of worms), using a MovieClip that contains a line and an arrowhead. First, though, I need to know when to draw...anything, let alone something specific to an 'arrow.'

        • 1. Re: JimP: When to draw?
          Michael Borbor Level 4

          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.

          • 2. Re: JimP: When to draw?
            Gregory Lafrance Level 6

            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...

            • 3. Re: JimP: When to draw?
              JimPlamondon Level 1

              Michael --


              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?


              Thanks!  :-)


              Jim Plamondon

              Austin, Texas


              • 4. Re: JimP: When to draw?
                JimPlamondon Level 1

                I think I'm starting to understand Flash/AIR's drawing architecture.  My current thinking on the topic is described in this blog post:

                     Retained Mode Considered Harmful


                I would welcome the comments of the esteemed readers of this forum on the ideas discussed therein.


                Thanks!  :-)