Bug: Tree Scrollbar Doesn’t Show Up

A customer pointed out to us that in some cases when a Tree’s scrollPolicy is set to ‘auto’, the scrollbar doesn’t show up when you add data and it doesn’t disappear when you remove data. This bug only shows up in Flex 2.0.1 with our latest released hotFix. The bug is not in Flex 2.0.1 and it is NOT in the Moxie Public Beta. The example below is the original Application which has a delay (created by a Timer) before adding a bunch of nodes to the Tree. When the nodes are added and a scrollbar is needed, it does not show up.

Original Bug Application : treeScrollAuto.mxml, treeScrollAuto.swf

After spending some time looking at this Deepa Subramaniam came up with the following solution to this problem using a custom dataDescriptor.

Fixed Application : treeScrollAutoFixed.mxml, myDescriptor.as, treeScrollAutoFixed.swf

11 responses

  1. Thanks Deepa! Its nice to have the dev team at Adobe willing to help these unknown problems

  2. Thank for the tip!!!

  3. Any other solution for the issue????? I’m Using Flex 3 and still facing the same issue

  4. @Arun: Did using a custom dataDescriptor not work for you? If not, please file a bug at http://bugs.adobe.com/flex and include a simple sample showing the problem.

  5. hello all,

    first of all a big respect for this blog.

    Got also problems with the vertical scrolling….

    Here is nice tutorial for a tree with amfPHP (http://www.sephiroth.it/tutorials/fl…fphp/index.php)

    i’ve used it for my app, but running into some trouble now, with the scrollbars, what i really didn’t expect!!

    here you can see the app and the source code:
    http://www.rootop.de/testing/TestTree.html

    it’s all german, so when you click on Enomis -> Einzelstoffe->Obst , then there appears a scrollbar for a short time and then disappears again, even if there are more branches… it really makes me mad.. i tried serveral function like..

    //scroll always to bottom, otherwise, only the items are shown, that are in the visible area
    tree.verticalScrollPosition=tree.maxVerticalScroll Position;

    tree.invalidateList();

    tree.validateNow();

    but nothing really works. the general problem is, that i don’t know when flex display the scrollbar and when not. because in some cases it works.
    so, if there is a solution or a workaround, i would be very happy. thanks in advance. kind regards, peter

  6. Alexander Ioffe | Reply

    Ok, so I think I understand what you are doing. You seem to be adding the data via the dataDescriptor since changing the dataProvider is futile. My problem is Bindable dataProviders somehow seem to reset themselves on the next refresh cycle. Just try out the following in ‘addTreeChildren()’:

    for each(var child:XML in xmlCollection.children()){
    desc.removeChildAt(xmlCollection, child, 0);
    }

    for each(var nchild:XML in newData){
    desc.addChildAt(xmlCollection, nchild, 0);
    }

    The variable newData can be whatever you want. What will happen is that xmlCollection will be reassigned to the stuff inside of newData but it will go back to what it was before on the next refresh cycle. I don’t know why that is.

    Can anybody help here?

  7. Hi,

    had the same problem an used this code (Now it works as expected for me):

    public function onDataProviderChange(ce:CollectionEvent) {
    this.menuTree.invalidateList();
    this.menuTree.invalidateDisplayList();

    // Hack to fix the rendering issue – Note the scroll bar reset doesn’t work otherwise we could use this hack.

    // TODO – Talk to Adobe
    var scrollPosition:Number = this.menuTree.verticalScrollPosition;
    var openItems:Object = this.menuTree.openItems;
    this.menuTree.dataProvider = this.dataProvider;
    this.menuTree.openItems = openItems;
    this.callLater(this.setOldScroll, [scrollPosition]);

    }

    private function setOldScroll(os:Number) {
    this.menuTree.verticalScrollPosition = os;
    }

  8. Hi,
    Thank you..Deepa for the wonderfull workaround to the problem..I kind of ran on into main program suspending…on calling the reset…If you could tell me any solution to this.
    Thank You.
    undefined
    at mx.collections::ListCollectionView/http://www.adobe.com/2006/flex/mx/internal::reset()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1441]
    at mx.collections::ListCollectionView/listChangeHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1053]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.collections::XMLListAdapter/set source()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\XMLListAdapter.as:162]
    at mx.collections::XMLListCollection/set source()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\XMLListCollection.as:93]
    at data::myDescriptor/getChildren()[C:\_Tree_gallery\TreeGallery\src\data\myDescriptor.as:67]
    at mx.controls.treeClasses::DefaultDataDescriptor/hasChildren()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\DefaultDataDescriptor.as:180]
    at mx.controls.treeClasses::HierarchicalCollectionView/calculateLength()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:283]
    at mx.controls.treeClasses::HierarchicalCollectionView/calculateLength()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:259]
    at mx.controls.treeClasses::HierarchicalCollectionView/updateLength()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:420]
    at mx.controls.treeClasses::HierarchicalCollectionView/nestedCollectionChangeHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:745]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.collections::ListCollectionView/dispatchEvent()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:831]
    at mx.collections::ListCollectionView/http://www.adobe.com/2006/flex/mx/internal::reset()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1447]
    at mx.collections::ListCollectionView/listChangeHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1053]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.collections::XMLListAdapter/set source()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\XMLListAdapter.as:162]
    at mx.collections::XMLListCollection/set source()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\XMLListCollection.as:93]
    at data::myDescriptor/getChildren()[C:\_Tree_gallery\TreeGallery\src\data\myDescriptor.as:67]
    at mx.controls.treeClasses::DefaultDataDescriptor/hasChildren()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\DefaultDataDescriptor.as:180]
    at mx.controls.treeClasses::HierarchicalCollectionView/calculateLength()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:283]
    at mx.controls.treeClasses::HierarchicalCollectionView/calculateLength()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:259]
    at mx.controls.treeClasses::HierarchicalCollectionView/updateLength()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:420]
    at mx.controls.treeClasses::HierarchicalCollectionView/nestedCollectionChangeHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:745]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.collections::ListCollectionView/dispatchEvent()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:831]
    at mx.collections::ListCollectionView/http://www.adobe.com/2006/flex/mx/internal::reset()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1447]
    at mx.collections::ListCollectionView/listChangeHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1053]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.collections::XMLListAdapter/set source()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\XMLListAdapter.as:162]
    at mx.collections::XMLListCollection/set source()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\XMLListCollection.as:93]
    at data::myDescriptor/getChildren()[C:\_Tree_gallery\TreeGallery\src\data\myDescriptor.as:67]
    at mx.controls.treeClasses::DefaultDataDescriptor/hasChildren()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\DefaultDataDescriptor.as:180]
    at mx.controls.treeClasses::HierarchicalCollectionView/calculateLength()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:283]
    at mx.controls.treeClasses::HierarchicalCollectionView/calculateLength()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:259]
    at mx.controls.treeClasses::HierarchicalCollectionView/updateLength()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:420]
    at mx.controls.treeClasses::HierarchicalCollectionView/nestedCollectionChangeHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:745]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.collections::ListCollectionView/dispatchEvent()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:831]
    at mx.collections::ListCollectionView/http://www.adobe.com/2006/flex/mx/internal::reset()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1447]
    at mx.collections::ListCollectionView/listChangeHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1053]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.collections::XMLListAdapter/set source()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\XMLListAdapter.as:162]
    at mx.collections::XMLListCollection/set source()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\XMLListCollection.as:93]
    at data::myDescriptor/getChildren()[C:\_Tree_gallery\TreeGallery\src\data\myDescriptor.as:67]
    at mx.controls.treeClasses::DefaultDataDescriptor/hasChildren()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\DefaultDataDescriptor.as:180]
    at mx.controls.treeClasses::HierarchicalCollectionView/calculateLength()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:283]
    at mx.controls.treeClasses::HierarchicalCollectionView/calculateLength()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:259]
    at mx.controls.treeClasses::HierarchicalCollectionView/updateLength()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:420]
    at mx.controls.treeClasses::HierarchicalCollectionView/nestedCollectionChangeHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\treeClasses\HierarchicalCollectionView.as:745]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.collections::ListCollectionView/dispatchEvent()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:831]
    at mx.collections::ListCollectionView/http://www.adobe.com/2006/flex/mx/internal::reset()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1447]
    at mx.collections::ListCollectionView/listChangeHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1053]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()

  9. But after using this it’s scrollposition becomes 0 (zero) again after these lines somewhere:

    categoryScreen.categoriesTree.invalidateList();
    categoryScreen.categoriesTree.invalidateDisplayList();
    var scrollPosition:Number = categoryScreen.categoriesTree.verticalScrollPosition;
    var openItems:Object = categoryScreen.categoriesTree.openItems;
    categoryScreen.categoriesTree.dataProvider = categoryScreen.categories;
    categoryScreen.categoriesTree.openItems = openItems;
    categoryScreen.categoriesTree.verticalScrollPosition = scrollPosition;

    Is there a way to prevent the problem?

  10. Thanks a lot it helped me…

Leave a comment