Horizontal Slider and List synch

As I stated in a previous post, I am working on a little project for work that dealt with including arrays inside of arrays.  Part of this also had me putting lists inside of lists.  The layout of one of the display has an Accordion navigation control with a HorizontalList, that also contained an accordion with it’s own HorizontalList.  I am using the horizontal list to scroll through main items with sub-items below.  On top of this, I am creating the HorizontalList, the HSlider and the Accordion controls all dynamically.

The first part of setting up the slider and list, is to make sure the HorizontalList has only 1 columnCount (number of columns displayed), else you see all of your items.  The second part is to set the start and end of the slider.  At first I used 0 as the start, but since I am showing the initial record, 1 should be the minimum value.  I set the maximum value to the length of the data set for the list.   I had found some code that used a counter to determine the position of the slider and the list.


private function prevClick(evt:Event):void{
var tmpHozList:HorizontalList = new HorizontalList();
tmpHozList = evt.target.data[0][0];
var tmpSlider:HSlider = new HSlider;
tmpSlider = evt.target.data[0][1];
//move Horizontal List
var pos:int = tmpHozList.horizontalScrollPosition - 1;
var min:int = 0;
var curvalue:int = Math.max(min, pos);
tmpHozList.horizontalScrollPosition = curvalue;

//move Slider
tmpSlider.value = curvalue;
}

private function nextClick(evt:Event):void{
var tmpHozList:HorizontalList = new HorizontalList();
tmpHozList = evt.target.data[0][0];
var tmpSlider:HSlider = new HSlider;
tmpSlider = evt.target.data[0][1];

//move Horizontal List
var pos:int = tmpHozList.horizontalScrollPosition + 1;
var min:int = 0;
var curvalue:int = Math.max(min, pos);
tmpHozList.horizontalScrollPosition = curvalue;

//move Slider
tmpSlider.value = curvalue;
}

The counter would get the current position and then add or subtract (depending on the button pushed) from the count and then determine max (Math.max) value between the count and the minimum and return that value to step the slider.  Well, this wasn’t working correctly.  I was trying to figure out if Math.min and some other method of determining the min and max values of the slider, when it hit me to just increment and decrement the value.  I use increment all the time in loops, so why wouldn’t it work to move the slider and the list position.


private function prevClick(evt:Event):void{
var tmpHozList:HorizontalList = new HorizontalList();
tmpHozList = evt.target.data[0][0];
var tmpSlider:HSlider = new HSlider;
tmpSlider = evt.target.data[0][1];
if(tmpHozList.horizontalScrollPosition > 0){
//move Horizontal List
tmpHozList.horizontalScrollPosition--;
//move Slider
tmpSlider.value--;
}
}

private function nextClick(evt:Event):void{
var tmpHozList:HorizontalList = new HorizontalList();
tmpHozList = evt.target.data[0][0];
var tmpSlider:HSlider = new HSlider;
tmpSlider = evt.target.data[0][1];

//move Horizontal List
tmpHozList.horizontalScrollPosition++;
//move Slider
tmpSlider.value++;
}

Well, it did work, except for one small issue.  For some reason, increase the count didn’t cause any issues.  Possibly the max amount it can increment on the HorizontalList works great, but the minimum value does not.  Regardless, decrementing the values would lead to the  list position going below 0 and causing an error. Which means, that for the previous button, I had to put a check in to make sure the current value wasn’t less than the minimum value, which was 1.  Anything over 0 was fine.  Simple and less code.  Now I just have to go through and update the other slider list combos.

About DeanLogic
Dean has been playing around with programming ever since his family got an IBM PC back in the early 80's. Things have changed since BASICA and Dean has dabbled in HTML, JavaScript, Action Script, Flex, Flash, PHP, C#, C++, J2ME and SQL. On this site Dean likes to share his adventures in coding. And since programming isn't enough of a time killer, Dean has also picked up the hobby of short film creation.

About DeanLogic

Dean has been playing around with programming ever since his family got an IBM PC back in the early 80's. Things have changed since BASICA and Dean has dabbled in HTML, JavaScript, Action Script, Flex, Flash, PHP, C#, C++, J2ME and SQL. On this site Dean likes to share his adventures in coding. And since programming isn't enough of a time killer, Dean has also picked up the hobby of short film creation.

Leave a Reply

Your email address will not be published. Required fields are marked *

*