Link to home
Start Free TrialLog in
Avatar of liltyga
liltyga

asked on

Move items up or down in list box - Part II

Hi,

Thanks to negatyve, I am well underway to my solution, but now the problem is that what is being done in the listbox is not being done in the corresponding array. In attempting to use the splice function to mimic the listbox functions, items are being removed from the array, leaving a blank space behind, and not switching the order of items in the array. Can anyone help?

This is what I have so far:

mx.controls.List.prototype.getScrollingInfo = function(Void):Object
{
      return {len:this.length, row:this.rowCount, sel:this.selectedIndex, pos:this.vPosition};
};
mx.controls.List.prototype.moveItemDown = function(Void)
{
      var info:Object = this.getScrollingInfo();
      if (info.sel == undefined) {
            return;
      }
      var item:Object = this.getItemAt(info.sel);
     //remove item from  myArray
    myArray.splice(lb_someList.selectedIndex,1);
     _root.application.someScreen.dg_someData.dataProvider = myArray;
    //then remove from listbox
      this.removeItemAt(info.sel);
      if (info.sel < info.len - 1) {
        //add item back into array, in new position
        myArray.splice(lb_someList.selectedIndex + 1,0,item);
        _root.application.someScreen.dg_someData.dataProvider = myArray;
        //then add into listbox at its new position
            this.addItemAt(info.sel + 1, item);
            this.clearIdList();
            this.selectedIndex = info.sel + 1;
            if (info.sel >= info.pos + info.row - 1) {
                  this.vPosition = (info.sel + 1) - (info.row - 1);
            } else if (info.sel <= info.pos - 1) {
                  this.vPosition = (info.sel + 1);
            } else {
                  this.vPosition = (info.pos);
            }
      } else {
            this.addItemAt(0, item);
            this.clearIdList();
            this.selectedIndex = this.vPosition = 0;
      }
   
};

Basically, instead of moving item at place 1 in the array to place 2, and the item in place 2 to place 1, it is adding a blank entry in place 1 and appending the previous value to place 2, moving the value of the previous place 2 to place 3.  Any help would be greatly appreciated!
ASKER CERTIFIED SOLUTION
Avatar of negatyve
negatyve

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of liltyga
liltyga

ASKER

yes, they do
Then you shouldn't need to change the external array, as the method change its own dataProvider, thus should update both...
Avatar of liltyga

ASKER

hmmm...ok, then I guess I'm wrong, since this is not updating the array, it is just updating the items in the listbox. What can I do to update two data providers? Should I not have to use the splice function? Also, do you know why blank items are being created in the array when an item is removed?
do you have a fla to show, or could you explain how it is done (so I can try to spot the problem)?
Avatar of liltyga

ASKER

definitely - is there any way I can let you know the location offline; via im or something?
Avatar of liltyga

ASKER

i have posted the data that you can take a look at - you can download it here:

http://66.241.254.57/ee/data.txt - please let me know when you've copied that to an .as file.

thanks!
I'm sorry, have been away, the file is missing now..
Avatar of liltyga

ASKER

no problem! Please try again; you should be able to access it now
Avatar of liltyga

ASKER

hi negatyve,

thanks again for all your help thus far. I finally managed to get things working, and couldn't be happier - now i can finally sleep :)