When it is time to reset dirty flag “invalidatePropertiesFlag” in Flex invalidation framework?

December 24th, 2009

   Invalidation in Flex is a mechanism by which changes made to a component’s property values are queued and postponed for the final procession till the end of the current Flash movie frame play. This property value invalidation mechanism in Flex is controlled by setting and resetting boolean variables called dirty flags.

   One of such a dirty flags used internally in Flex invalidation mechanism is invalidatePropertiesFlag flag.

   This particular flag is reset in validateProperties() method from mx.core.UIComponent class from Flex 3 SDK:

public function validateProperties():void
    if (invalidatePropertiesFlag)
        invalidatePropertiesFlag = false;

   Inside commitProperties() function the actual change occur to the invalidated property’s value, for example, it can be “width” property.

   The question is – why dirty flag invalidatePropertiesFlag is reset after call to commitProperties() method, but not before this call?

    My far-fetched speculation is that this had happened because:

  • It is just a matter of life == code convention to put the dirty flag at the end of IF block;
  • If code within commitProperties() raises RTE, we will still have a chance to execute the code in commitProperties() during playing next frame in Flash Player and this time maybe the code will not throw RTE.

   At this point, you may start to wonder why the exact location (at the very beginning or at the very end of IF sequence) of the dirty flag can be important?

   The reason is:

   If the code within commitProperties() implementation will try to invalidate some other component’s property (e.g “height” property) that tries to invoke another invalidation routine by using dirty flag, then this invalidation call will not be added to mx.managers.LayoutManager.invalidatePropertiesQueue, because dirty flag invalidatePropertiesFlag is still equal to true, see the listing of invalidateProperties method from UIComponent for the method logic:

public function invalidateProperties():void
        if (!invalidatePropertiesFlag)
            invalidatePropertiesFlag = true;
            if (parent && UIComponentGlobals.layoutManager)