Slider slide limit
- June 15, 2009
- 1 reply
- 538 views
Hello,
I wonder if you can help me. I would like to know if there is a way to limit the slider thumb once it gets to a certain value.
Let me explain, I have four slider components all with ranges of 0 - 100, representing percentage values. As well as their
independent values, they all represent part of a whole. By dragging the sliders and changing the values, the whole value
is affected accordingly.
The idea is that when the whole value reaches 0 it is full - there is 0% left, and none of the sliders can then be increased
unless one of them is then decreased to put some positive value back into the whole, at which point they would all become
active again.
At the moment I can't find a way to limit the value of the sliders and they send the whole value negative. I hope I've explained
this ok, I post the code the swf and the fla so you can see what is going on.
import fl.controls.Slider;
import fl.events.SliderEvent;
import fl.controls.NumericStepper;
import fl.controls.Label;
aSlider.addEventListener(SliderEvent.CHANGE, slideA);
bSlider.addEventListener(SliderEvent.CHANGE, slideB);
cSlider.addEventListener(SliderEvent.CHANGE, slideC);
dSlider.addEventListener(SliderEvent.CHANGE, slideD);
aStepper.addEventListener(Event.CHANGE, stepA);
bStepper.addEventListener(Event.CHANGE, stepB);
cStepper.addEventListener(Event.CHANGE, stepC);
dStepper.addEventListener(Event.CHANGE, stepD);
aSlider.liveDragging = true;
bSlider.liveDragging = true;
cSlider.liveDragging = true;
dSlider.liveDragging = true;
var totA = 0;
var totB = 0;
var totC = 0;
var totD = 0;
var totP = 100;
function slideA(event:SliderEvent):void {
aLabel.text = event.value + " percent";
aStepper.value = event.target.value;
totA = event.value;
remaining();
}
function slideB(event:SliderEvent):void {
bLabel.text = event.value + " percent";
bStepper.value = event.target.value;
totB = event.value;
remaining();
}
function slideC(event:SliderEvent):void {
cLabel.text = event.value + " percent";
cStepper.value = event.target.value;
totC = event.value;
remaining();
}
function slideD(event:SliderEvent):void {
dLabel.text = event.value + " percent";
dStepper.value = event.target.value;
totD = event.value;
remaining();
}
function stepA(event:Event) :void {
aLabel.text = event.target.value + " percent";
aSlider.value = event.target.value;
totA = event.target.value;
remaining();
}
function stepB(event:Event) :void {
bLabel.text = event.target.value + " percent";
bSlider.value = event.target.value;
totB = event.target.value;
remaining();
}
function stepC(event:Event) :void {
cLabel.text = event.target.value + " percent";
cSlider.value = event.target.value;
totC = event.target.value;
remaining();
}
function stepD(event:Event) :void {
dLabel.text = event.target.value + " percent";
dSlider.value = event.target.value;
totD = event.target.value;
remaining();
}
function remaining():void {
totP = totA + totB + totC + totD;
totP = 100 - totP;
eLabel.text = totP + " percent remaining";
/*
if (totP <= 0) {
aSlider.value = totA;
}
*/
}
Thanks in advance for your help on this ![]()
Mark