?
Solved

Move items up or down in list box

Posted on 2005-05-05
7
Medium Priority
?
236 Views
Last Modified: 2008-02-01
Hello,

I have an application that inserts data into a list box. The results are retrieved in an array, and want to be able to add arrow buttons that will allow the data in the array to be rearranged (moved up or down into a desired order). Can anyone give me advice as to the best way to do this?
0
Comment
Question by:liltyga
  • 4
  • 3
7 Comments
 
LVL 27

Accepted Solution

by:
negatyve earned 2000 total points
ID: 13937831
Personally, I use these with the ListBox component (v. 1 components):

// =========================================
FListBoxClass.prototype.getInfo = function()
{
      var len = this.getLength();
      var row = this.getRowCount();
      var ind = this.getSelectedIndices();
      var pos = this.getScrollPosition();
      return {len:len, row:row, ind:ind, pos:pos};
};
FListBoxClass.prototype.moveItemDown = function()
{
      var info = this.getInfo();
      if(info.ind.length == 1){
            var num = Number(info.ind[0]), temp = this.getItemAt(num);
            this.removeItemAt(num);
            if(num < info.len - 1){
                  this.addItemAt(num + 1, temp.label, temp.data);
                  this.setSelectedIndex(num + 1);
                  if(num >= info.pos + info.row - 1){
                        this.setScrollPosition((num + 1) - (info.row - 1));
                  } else if(num <= info.pos - 1){
                        this.setScrollPosition(num + 1);
                  } else {
                        this.setScrollPosition(info.pos);
                  }
            }else{
                  this.addItemAt(0, temp.label, temp.data);
                  this.setSelectedIndex(0);
                  this.setScrollPosition(0);
            }
      }
};
FListBoxClass.prototype.moveItemUp = function()
{
      var info = this.getInfo();
      if(info.ind.length == 1){
            var num = Number(info.ind[0]), temp = this.getItemAt(num);
            this.removeItemAt(num);
            if(num > 0){
                  this.addItemAt(num - 1, temp.label, temp.data);
                  this.setSelectedIndex(num - 1);
                  if(num - 1 <= info.pos)      {
                        this.setScrollPosition(num - 1);
                  } else if(num >= info.pos + info.row){
                        this.setScrollPosition(num - info.row);
                  } else {
                        this.setScrollPosition(info.pos);
                  }
            }else{
                  this.addItem(temp.label, temp.data);
                  this.setSelectedIndex(info.len - 1);
                  this.setScrollPosition(info.len - info.row);
            }
      }
};

And these for List component (v. 2 components):

// =========================================
mx.controls.List.prototype.moveItemDown = function(Void):Void
{
      var info:Object = this.getScrollingInfo();
      if(info.sel == undefined)return;
      var item:Object = this.getItemAt(info.sel);
      this.removeItemAt(info.sel);
      if(info.sel < info.len - 1){
            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;
      }
};
mx.controls.List.prototype.moveItemUp = function(Void):Void
{
      var info:Object = this.getScrollingInfo();
      if(info.sel == undefined)return;
      var item:Object = this.getItemAt(info.sel);
      this.removeItemAt(info.sel);
      if(info.sel > 0){
            this.addItemAt(info.sel - 1, item);
            this.clearIdList();
            this.selectedIndex = info.sel - 1;
            if(info.sel - 1 <= info.pos)                  {      this.vPosition = info.sel - 1;            }
            else if(info.sel >= info.pos + info.row)      {      this.vPosition = info.sel - info.row;      }
            else                                          {      this.vPosition = info.pos;                  }
      }else{
            this.addItemAt(info.len - 1, item);
            this.clearIdList();
            this.selectedIndex = info.len - 1;
            this.vPosition = info.len - info.row;
      }

};
// clears ID
mx.controls.List.prototype.clearIdList = function(Void):Void
{
      var d:Array = this.dataProvider;
      for(var i:Number = 0; i < d.length; i++)delete(d[i].__ID__);
};
0
 

Author Comment

by:liltyga
ID: 13941857
Thanks Negatyve,

Unfortunatley, I'm not as seasoned as you, and although I tried integrating this, I am a bit confused as to how to implement this. Right now, I am retrieving data to the list box dynamically from the database. Can you clarify how I can grab the data from, lets say, lb_someData and moving that content with buttons btn_moveUp and btn_moveDown?
0
 
LVL 27

Expert Comment

by:negatyve
ID: 13941890
1. what component version are you using? v1 (flash mx) or v2 (flash mx 2004)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:liltyga
ID: 13941902
v2 - 2004 pro
0
 

Author Comment

by:liltyga
ID: 13942394
You are awesome! Thanks so much!!
0
 

Author Comment

by:liltyga
ID: 13957625
hi again negatyve, I have a quick question to append to this - let me know if you want me to create another post for this - how can i best use the splice function to duplicate the removal/addition when moving items up or down, so that the adjusted data can be reflected in an array that I need to pass data with?

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question