Search code examples
apache-flexmobilescrollitemrenderer

Scroll inside an item renderer result in an empty item


I'm developing a mobile app. I have a view with an horizontal list, each item has a long description so I would need a vertical scroll for that independent information. I'm trying to add an scroll as a Child of an itemRenderer. And I dont get it. Anyone knows what I'm doing bad? I have a class with inheritance of ItemRenderer (I tried BaseRenderer from AsFusion too, that it seems to have more performance for mobile apps, with the same result). And here is the part of the scroll from my code:

    override protected function createChildren():void
    {
        super.createChildren();
        scroller = new VScrollBar();
        scroller.percentHeight = 100;
        scroller.setStyle('right', 0);
        scrollGroup = new Group();
        scrollGroup.percentHeight = 100;
        scrollGroup.percentWidth = 100;
        super.addElement(scroller);
        super.addElement(scrollGroup);

        scroller.viewport = scrollGroup;
    }

I also tried

    override protected function createChildren():void
    {
        super.createChildren();
        scroller = new Scroller();
        scroller.percentHeight = 100;
        scroller.percentWidth = 100;
        scrollGroup = new Group();
        scrollGroup.percentHeight = 100;
        scrollGroup.percentWidth = 100;
        super.addElement(scroller);
        super.addElement(scrollGroup);

        scroller.viewport = scrollGroup;
    }

And the result is the same. An empty item in the list. I can change page (pagesnapping of the list horizontal scroll) and the next item is also empty. If I delete addElement(scroller) I can see the items perfectly, but without the vertical scroll that I really need. So the problem is in the scroller. Any idea what I'm doing so bad?? Please? I need the solution in actionscript, I have more itemrenderers done and I will make inheritance, and the performance for the mobile is better in actionscript. Thank you in advance.


Solution

  • I solved, with the guidance of Grigorash Vasilij I noticed that the content of the scroller was not showing because in the group the content size was 0 and private visible variable was false. So the percent sizes of the scroller was not working, I updated it in the method updateDisplayList.

        override protected function updateDisplayList( unscaledWidth:Number, unscaledHeight:Number ):void
        {                       
            super.updateDisplayList( unscaledWidth, unscaledHeight );
    
            scroller.width = unscaledWidth;
            scroller.height = unscaledHeight;
            ...
        }
    

    After that, the scroller was horizontal, then the horizontal scroll wasn't work, I wanted a verticalScroll if needed in the item Renderer, so after the constructor of Scroller I set the horizontalPolicy of the scroll equal to off. The result is the next:

        override protected function createChildren():void
        {
            super.createChildren();
            scroller = new Scroller();
            scroller.percentHeight = 100;
            scroller.percentWidth = 100;
            scroller.setStyle("horizontalScrollPolicy", "off");
            scrollGroup = new Group();
            scrollGroup.percentHeight = 100;
            scrollGroup.percentWidth = 100;
            addChild(scrollGroup);
            scroller.viewport = scrollGroup;
            addChild(scroller);
    
        }
    

    My class is inheriting of BaseRenderer from Asfusion If you inherit of itemrenderer use addElement instead of addChild.