Flex ScrollPolicy.AUTO Not Good Enough

by Gordon. 21 Comments

One of my biggest gripes so far with the flex scrolling system is the automatic scrolling policy: a container’s viewing area is not changed by the introduction of scroll bars. This is especially troublesome in the vertical case and seems to be a pretty shitty way of doing things in general. For example, if the vertical size of the children increases beyond the height of their container, a vertical scroll bar will be created and displayed, however the children will not be resized. Consequently, if some of the children have variable widths (e.g. width=”100%”), they may be overlapped by the vertical scroll bar, causing a horizontal scroll bar to be displayed. When the scrolling policy is set to ScrollPolicy.ON, however, the children are resized to take the scroll bar into account at the price of the scroll bar always displaying, even when it is not needed. Yuck. I have heard several justifications for this. One is that it prevents a cascading resize effect where all the descendants of the container are resized, each one introducing a vertical scroll bar. Another is that it is faster due to the fact that it requires only a single pass on the children, whereas to do it the correct way would require sizing the children, checking if scroll bars are required, and then adjusting the size of the children based on the new size when scroll bars are introduced. In both cases the justification is entirely dwarfed by the current behavior. Fortunately there is a fix for this: create a custom container and add the following override for the validateDisplayList method:
import mx.core.ScrollPolicy;
public override function validateDisplayList():void
{
    super.validateDisplayList();
 
    if(null != verticalScrollBar && verticalScrollBar.maxScrollPosition == 0
        && verticalScrollPolicy != ScrollPolicy.AUTO)
    {
        verticalScrollPolicy = ScrollPolicy.AUTO;
    }
 
    else if(null != verticalScrollBar)
    {
        verticalScrollPolicy = ScrollPolicy.ON;
    }
}
This is a hack which toggles between ScrollPolicy.AUTO and ScrollPolicy.ON as needed to gain the desired behavior. It comes at the price of invalidating the verticalScrollPolicy property. Hopefully this behavior will be more tightly integrated into future versions of Flex (maybe another ScrollPolicy is in order?).
  • http://www.evokedesign.com miami web design

    Can’t help but agree. The two most popular and easiest way to build flex projects are by using Flex Builder, or through the use of the Flex SDK Ant tasks.

  • http://www.evokedesign.com miami web design

    Can’t help but agree. The two most popular and easiest way to build flex projects are by using Flex Builder, or through the use of the Flex SDK Ant tasks.

  • Anonymous

    Very cool. I am looking forward to trying this out.

  • Anonymous

    Very cool. I am looking forward to trying this out.

  • http://www.zoombits.de Speicherkarten

    I have heard several justifications for this. One is that it prevents a cascading resize effect where all the descendants of the container are resized, each one introducing a vertical scroll bar

  • guodan
  • guodan
  • http://www.rebornbabiesuk.com reborn baby

    I have heard several justifications for this. One is that it prevents a cascading resize effect where all the descendants of the container are resized, each one introducing a vertical scroll bar. Another is that it is faster due to the fact that it requires only a single pass on the children, whereas to do it the correct way would require sizing the childrens…


    Thanks and Regards

  • guodan
  • guodan
  • guodan
  • guodan
  • sharadjha

    Barcelona apartment – The most important thing to choose an accommodation for vacations is to be achieving like home. Today, holidays represent more than stay in a huge resort or a very important chain hotel. Fortunately you can find a rent apartment for short term to long term; it’s the way that you are going to plan your itineraries, meals and everything with your family.

  • guodan
  • http://www.ecenglish.com/Destinations/Learn-English-in-London study english in london

    New information changes markets in minutes. Global conversations are no longer restricted by physical space. There are some great courses available now, which offer rich interactive learning environments and give you the opportunity to listen, speak, read and write.

  • guodan
  • guodan
  • chary1112004

    Thanks Gordon very much! You are writing things Iam finding. Thanks again.

    – chary1112004 –

  • chary1112004

    Thanks Gordon very much! You are writing things Iam finding. Thanks again.

    – chary1112004 –

  • http://www.cliffsidemalibu.com/dual-diagnosis/severe-depression/ Depression Treatment

    Depression Treatment

  • https://www.revolutionweb.com Info Revolutionweb