0
votes

I am trying to create a dynamic scrolling list in Flash AS3. When I create a list, I set it to be an initial length. Later, I add more objects to the list which is outside of the original size of the list. I want to be able to scroll down the list and see all the objects.

My scrollbar just moves the list's y position. However, every object that is drawn outside the original list size is not shown when I run the program and scroll. How can I fix this?

I have a list object which has the function below when I need to add content to the list. When I initialize the list, I give it an initial height and width which I use to create a mask.

public function AddPlayers(pPlayers:Array, pScrollBar:ScrollBar):void
{
        var player:Player;

        trace("happened again");
        for (var i:int = 0; i < pPlayers.length; i++)
        {               
            player = pPlayers[i];                               
            this.addChild(player);
            player.x = 0;
            player.y = player.height * i;
        }

        pScrollBar.InitializeScrollBar(this);       
}

The InitializeScrollBar function updates the properties of the scrollbar based on the size of the content added. It's mainly changing the size of the scroll face depending on the size of the list content.

public function InitializeScrollBar(pList:List)
{
        this.list = pList;

        // Size and place scroll track
        scrollTrack.height = scrollHeight - 2 * scrollUp.height;
        scrollTrack.y = scrollUp.height;            
        addChild(scrollTrack);          

        // Place scroll face
        scrollFace.y = scrollUp.height;
        scrollFace.height = scrollTrack.height * (scrollHeight / list.height);          
        addChild(scrollFace);

        // Place scroll buttons
        addChild(scrollUp);
        scrollDown.y = scrollDown.height + scrollTrack.y + scrollTrack.height;
        addChild(scrollDown);
        scrollDown.scaleY = -1;


        scrollFace.addEventListener(MouseEvent.MOUSE_DOWN, MoveScrollFace);

        scrollDown.addEventListener(MouseEvent.CLICK, MoveDown)
        scrollUp.addEventListener(MouseEvent.CLICK, MoveUp)
}

I also have an Update function in the scrollbar which uses an ENTER FRAME event when the scrollface is dragged.

private function Update(evt:Event)
{
        trace(mouseY);
        scrollFace.y = mouseY;

        if (scrollFace.y <= scrollTrack.y)
        {
            scrollFace.y = scrollTrack.y;
        }
        else if (scrollFace.y + scrollFace.height >= scrollTrack.y + scrollTrack.height)
        {
            scrollFace.y = scrollTrack.y + scrollTrack.height - scrollFace.height;
        }

        var scrollChange:Number = (list.height - scrollHeight)/(scrollTrack.height - scrollFace.height);
        list.y = -1 * scrollChange * (scrollFace.y - scrollUp.height);          
        list.y = list.y + list.y % 25;

}   
1
Do you have some code that you can share?Corey
You scrollbar code will probably have set some properties that it uses to calculate the scroll distance, rather than reading them from your list constantly. They will need to be updated when your list changes, but without seeing the code it's impossible to say more.shanethehat

1 Answers

0
votes

If you use standard UIScrollbar component it has a build in function scrollBar.update(); You should use this function after changing content size.