kuza55 / minimalcomps

Automatically exported from code.google.com/p/minimalcomps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bad selectedIndex and selectedItem returned on List component

GoogleCodeExporter opened this issue · comments

What steps will reproduce the problem?

import com.bit101.components.List;

var l:List = new List(this, 5, 5, [2, 3, 4, 5, 6, 7, 8, 9, 10] );

l.addEventListener(Event.SELECT, onSelectHandler );

function onSelectHandler(pEvt:Event):void
{
    trace("item = ", l.selectedItem, " / index = ", l.selectedIndex );
}

Scroll the list and select an item, you always have the last visible itemforn 
the first 5 visible items.

What is the expected output? What do you see instead?

the trace output is fine for the 5 visible item, but if you scroll the trace 
output is wrong.

What version of the product are you using? On what operating system?

minimalcomps_0_9_6.swc

Please provide any additional information below.

Original issue reported on code.google.com by frederic...@gmail.com on 18 Nov 2010 at 8:58

Attachments:

In order to have the correct index, you just need to add the offset (scrollbar 
value) when register the selectedIndex.

Here's the correct version of the onSelectMethod in the List Class :


protected function onSelect(event:Event):void
        {
            if(! (event.target is ListItem)) return;


            var offset:int = _scrollbar.value;

            for(var i:int = 0; i < _itemHolder.numChildren; i++)
            {
                if (_itemHolder.getChildAt(i) == event.target)
                {
                    _selectedIndex = offset + i;
                }
                ListItem(_itemHolder.getChildAt(i)).selected = false;
            }
            ListItem(event.target).selected = true;
            dispatchEvent(new Event(Event.SELECT));
        }

Original comment by frederic...@gmail.com on 19 Nov 2010 at 8:28

Good one. thanks.

Original comment by bit...@gmail.com on 20 Nov 2010 at 3:28

  • Changed state: Fixed