Replacing DataProviders

I’ve been having problems with replacing a dataProvider on a ComboBox.


a_cb.addEventListener(MouseEvent.MOUSE_DOWN, getCurrentIndex)
            a_cb.textField.textField.addEventListener(Event.CHANGE, getEntry, false, int.MAX_VALUE);    //for typing
            a_cb.textField.addEventListener(ComponentEvent.ENTER, setTypedEntry);                //for pressing enter
            a_cb.addEventListener(Event.CHANGE, getChoice)        
            a_cb.editable = true;

     function getCurrentIndex(m:MouseEvent)
        {
            trace ("        *****************GetCurrentIndex")
            //records selectedIndex when user clicks, and also records current dataProvider of selected ComboBox;
            //trace (m.currentTarget)
            var cb:ComboBox = ComboBox(m.currentTarget);
                                                //for clicking on list
            
            currentIndex = cb.selectedIndex;
            trace ("    Current Index",currentIndex);
            //back up dataProvider
            initDP.removeAll();
            initArray = [];
            for (var i:Number = 0; i < cb.length; i++)
            {
                initDP.addItem(cb.getItemAt(i));
                var normal:String = cb.getItemAt(i).label;
                var trunc:String = processString(cb.getItemAt(i).label)
                initArray.push( {normal:normal, trunc:trunc } )
            }
            
        }
         function getEntry(e:Event)
        {
            e.stopImmediatePropagation();
            trace ("        ********************            getEntry()")
            var i:Number;
            var t:String = TextField(e.currentTarget).text;
            var cb:ComboBox = ComboBox(e.currentTarget.parent.parent);
            var temp:Array = [];
            var tempDP:DataProvider = new DataProvider();
            //t = removeSpaces(t).toUpperCase();
            
            for (i = 0; i < initArray.length; i++)
            {
                var q:String = initArray*.trunc.substr(0,t.length).toUpperCase();    //convert every initArray element into an upperCase string, that is equal in length to the user's input
                if (processString(t) == q)
                {
                    trace ("Found a Match:", initArray*.normal);
                    temp.push(initArray*.normal);
                }
            }
                                                //create temporary DataProvider for CB
            for (i = 0; i < temp.length; i++)
            {
                tempDP.addItem( { data:temp*, label:temp* } );
            }
            //show the temporary DataProvider to the user with the filtered choices
            cb.dataProvider = tempDP;
            cb.rowCount = 17;
            cb.invalidate();
            cb.open();
            cb.text = t;
        }
         function setTypedEntry(e:ComponentEvent)
        {
            trace("            ********************            setTypedEntry()")
            trace (e.currentTarget)
            
            //user pressed enter.   see if we can find what they typed.   if not, restore orig DP, and orig CurrentIndex
        }

         function getChoice(e:Event)
        {
            trace ("        ********************            getChoice()")
            var cb:ComboBox = ComboBox(e.currentTarget);
            trace (cb.selectedItem.label)
        }
        

This is for an Auto-Complete/filtered ComboBox. the user types into the comboBox, and it shows which DataProvider items in the CB match the user’s input. The problem I’m running into now is that once it replaces the current DataProvider with a tempDP ( in getEntry() ), it erases the user’s text. I’m not sure why it’s doing that either.

if I comment out the lines at the end of getEntry() that directly reference the CB, the user’s text is not erased.

Any thoughts?

Also, I’m not sure why, but I get no cursor on this forum when I create a new thread. in order to use backspace or highlight anything I’ve typed in a post I’m making, I have to publish the post, and then edit it. Only then am I able to type normally, like in TextEdit or something. FireFox3, OSX Tiger