4 Replies Latest reply on Feb 13, 2007 8:42 PM by jpwrunyan

    Force a redraw before further processing

    FlightGuy Level 1
      Hi All,

      I'm having performance problems with a complex mxml component that is being drawn once for each instance in an ArrayCollection - similar to using an mx:Repeater, though it's simply iterating AS3.

      It doesn't take that long to draw enough to fill the screen, and what I'm wanting to do is to draw enough to fill the screen, force a redraw so it's actually rendered, then draw the rest while the user reads the first page. I've tried using callLater, but that gets called before Flex actually redraws the screen. I could use a timer, but I don't really want a delay - I want it to continue as soon as the redraw is finished.

      Does anybody have any suggestions about how I can force a redraw without using the timer?

      Tim
        • 1. Re: Force a redraw before further processing
          jpwrunyan Level 1
          Add a listener using the enterFrame event. Remove the listener after it has been called once.
          • 2. Re: Force a redraw before further processing
            FlightGuy Level 1
            Thanks - works a treat.
            • 3. Re: Force a redraw before further processing
              FlightGuy Level 1
              Sorry, correction - had some remaining artefacts of my timer hack that made it look like it was working. This still doesn't work. The event gets fired and it does all the work, but it delays updating the display until it's finished.
              • 4. Re: Force a redraw before further processing
                jpwrunyan Level 1
                That's right. Maybe I misunderstood the timing you wanted this to execute. But if you add a listener to EnterFrame, then the component will display for one frame before correcting itself. Usually, you can catch this with the naked eye, especially since frame rate slows down during heavy processing.

                Maybe I should have gone to the fundamentals first and asked if you are trying the invalidation methods?
                invalidateDisplayList()
                invalidateSize()
                invalidateProperties()

                unfortunately, I think you may end up getting slower and slower performance if you are iterating content and calling the above each time--even though they techinically should update once per frame despite the amount of times you call them. So maybe we should take another step back to something even more fundamental:

                One more thing you might try is looking into creationPolicy. With creationPolicy you can set a container component to draw its children one by one instead of waiting until all of them are finished before displaying them. The default value is "all" which means you don't see the entire component until all its children are instantiated. Does this sound like what you are trying to do?

                Hope that helps, and I am sorry if I misunderstood your question.