JabbyPanda’s travel to RIA world / 35 posts / categories / 85 comments / feed / comments feed

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

   Invalidation in Flex is a mechanism by which changes made to a component's property values are queued and processed.This property value invalidation 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)
    {
        commitProperties();
        invalidatePropertiesFlag = false;
    }
}

Inside commitProperties() function the actual changes occur to the invalidated property's value, for example, it can be "width" property.

My question is:

   Why dirty flag invalidatePropertiesFlag is reset after commitProperties() call, but not before this call?

I speculate this happens because:

   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 another component's property (e.g "height" property) 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 explanation:

public function invalidateProperties():void
    {
        if (!invalidatePropertiesFlag)
        {
            invalidatePropertiesFlag = true;

            if (parent && UIComponentGlobals.layoutManager)
                UIComponentGlobals.layoutManager.invalidateProperties(this);
        }
    }

   The following example (source code can be viewed here)
illustrates this problem:

Get Adobe Flash player

   In this example, Spark's DropDownMenu component selectedItem property is validated with mx:StringValidator validator.

   But the red border highlighting about error (selectedItem is blank) will not go away on the first successfull selection of selectedItem property in DropDownMenu.

   The validation error will only disappear on the second selection run, because DropDownMenu's "errorString" property is changed using invalidation mechanism, which in turn does not start on the first run because dirty flag invalidatePropertiesFlag is not yet reset.

The workaround to this sutuation is to trigger property invalidation mechanism manually by calling validateProperties method, but sometimes it can be not that convenient to call invalidation mechanism manually.

To sum up - I vote for the change in Flex SDK - dirty flag "invalidatePropertiesFlag" should be reset before the execution of commitProperties() method

No comments

Leave a comment

Powered by WP Hashcash