Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

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!
0
liltyga
Asked:
liltyga
  • 6
  • 4
1 Solution
 
negatyveCommented:
do both dg_someData and lb_someList use the same dataProvider?
0
 
liltygaAuthor Commented:
yes, they do
0
 
negatyveCommented:
Then you shouldn't need to change the external array, as the method change its own dataProvider, thus should update both...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
liltygaAuthor Commented:
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?
0
 
negatyveCommented:
do you have a fla to show, or could you explain how it is done (so I can try to spot the problem)?
0
 
liltygaAuthor Commented:
definitely - is there any way I can let you know the location offline; via im or something?
0
 
liltygaAuthor Commented:
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!
0
 
negatyveCommented:
I'm sorry, have been away, the file is missing now..
0
 
liltygaAuthor Commented:
no problem! Please try again; you should be able to access it now
0
 
liltygaAuthor Commented:
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 :)
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now