0

问题是使用 AS 3.0 对 2 个滑块进行编码,当第一个滑块增加一个 uint 时,另一个滑块减少相同的 uint,反之亦然。

4

2 回答 2

0

所以这里是Flash Slider 类的文档。

以下是我将如何去做:

// Add the sliders to the stage, lets call them `slider1` & `slider2`.
// Store each value of the slider
var slider1Position:Number = slider1.value;
var slider2Position:Number = slider2.value;
// Set liveDragging to true so the CHANGE event is fired continuously
slider1.liveDragging = true;
slider2.liveDragging = true;
// Add event listeners to listen for when they are moved. 
slider1.addEventListener(SliderEvent.CHANGE, onSlider1Changing);
slider2.addEventListener(SliderEvent.CHANGE, onSlider2Changing);

function onSlider1Changing(e:SliderEvent):void {
    var difference:Number = e.value - slider1Position;
    // update the position of the other slider
    slider2.value += difference;
}

function onSlider2Changing(e:SliderEvent):void {
    var difference:Number = e.value - slider2Position;
    // update the position of the other slider
    slider1.value += difference;
}

试试看。我希望手动设置值不会触发 CHANGE 事件...

于 2013-10-22T09:00:35.250 回答
0

很抱歉,它没有用。我以这种方式进行(slider1)和(slider2)之间的交互作为奴隶。

var slider1Position:Number = slider1.value;
var slider2Position:Number = slider2.value;
slider2.value = 100; // max value for the sliders is 100 as an example.

slider1.addEventListener(SliderEvent.CHANGE, onSlider1Changing);

function onSlider1Changing(e:SliderEvent):void {
slider1Position = e.value;
slider2.value = 100 - slider1Position;
}

整个代码中缺少的是slider2被视为激活器而slider1被视为从属的另一种方式。

我希望真的不要打扰我的问题。

于 2013-10-23T14:50:56.750 回答