Oct 2, 2008

Forcing layout using validateNow()

Sometimes, (although rare) we may come across situations wherein we’d like flex to layout components at runtime immediately. As an example, you may have to increase the width of an image in a canvas at runtime and would immediately like to use this width for some processing. . If you let Flex do it, it might delay the processing of certain properties that may take long in computing. It might take sometime for the commitProperties() to be executed. To avoid this you may want to force the layout immediately.
             To do this, we use the validateNow() method of the component. According to LiveDocs,
validateNowValidates and updates the properties and layout of this object by immediately calling validateProperties(), validateSize(), and validateDisplayList(), if necessary.”
Also,
validateNow()-Validate and update the properties and layout of this object and redraw it, if necessary. Processing properties that require substantial computation are normally not processed until the script finishes executing. For example setting the width property is delayed, because it may require recalculating the widths of the objects children or its parent. Delaying the processing prevents it from being repeated multiple times if the script sets the width property more than once. This method lets you manually override this behavior
          However, since validateNow() forces validation in the same frame it may be processor intensive. So try and not use it unless it is absolutely necessary.

Thanks,
Shaleen Jain

3 comments:

  1. You write very well.

    ReplyDelete
  2. yaar ! yeh color combinition kya hai ? kuch change karo yaar ! mera toh sar chakragaya yahan land karke

    ReplyDelete
  3. @Anonymous...thanks for your feedback.Hope you are good now...

    ReplyDelete