2

I have a slider that controls a movie clip by dragging it through the frames to animate and this works great when dragging from left to right, But i want the slider to start in the middle and drag through the movie clip from a center point being able to go 350 to the right and 350 to the left.

Is this possible?

Heres my code so far and as you can see it drags 350 to the right through dialSpin_mc.

Is there a way to make the slider start at a certain frame and go backwards and forwards?

  dialSpin_mc.stop();

    slider_mc.knob_mc.buttonMode = true;

    slider_mc.knob_mc.addEventListener(MouseEvent.MOUSE_DOWN, onDragKnob);
    stage.addEventListener(MouseEvent.MOUSE_UP, onReleaseKnob)

    slider_mc.knob_mc.buttonMode = true;

    function onDragKnob(myEvent:Event):void
    {
        slider_mc.knob_mc.startDrag(false, new Rectangle(0,0,350,0));
        slider_mc.knob_mc.addEventListener(Event.ENTER_FRAME, onScrubMovie);
    }

    function onReleaseKnob(myEvent:Event):void
    {
        slider_mc.knob_mc.stopDrag();
slider_mc.knob_mc.removeEventListener(Event.ENTER_FRAME, onScrubMovie);
    }

    function onScrubMovie(myEvent:Event):void {
        var playHead:int=Math.round((slider_mc.knob_mc.x/350*8)+1);
        dialSpin_mc.gotoAndStop(playHead);    
    }  
4

1 回答 1

1

正如评论中所讨论的,这是您如何在不使用startDrag()andstopDrag()函数的情况下对滑块功能进行编码。

这个想法是,当您在滑块上按下鼠标按钮时,ENTER_FRAME会创建一个侦听器。每一帧滑块的 X 位置都会更新以匹配mouseX位置,并确保它只能移动 175 像素,我们还检查滑块的新位置。

确保滑块位置有效后,您可以使用相同的代码设置dialSpin_mc框架。

释放鼠标按钮后,将删除输入帧侦听器。

代码顶部的sliderOrigin声明将需要更改为适合您项目的任何内容(当您将滑块移动到幻灯片区域的中间而不是最左侧时,滑块的 xposition 是什么)。

var sliderOrigin:int = 150; // The x position the slider is in when in the center of the slide bar
slider_mc.x = sliderOrigin;

slider_mc.addEventListener(MouseEvent.MOUSE_DOWN, mDown);
slider_mc.addEventListener(MouseEvent.MOUSE_UP, mUp);

function mDown(e:MouseEvent):void
{
    addEventListener(Event.ENTER_FRAME, UpdateDrag);
}

function mUp(e:MouseEvent):void
{
    removeEventListener(Event.ENTER_FRAME, UpdateDrag);
}

function UpdateDrag(e:Event):void
{
    slider_mc.x = mouseX;

    // Check if the slider is 'out of bounds' and change its position if it is
    if(slider_mc.x < sliderOrigin - 175)
        slider_mc.x = sliderOrigin - 175;
    else if(slider_mc.x > sliderOrigin + 175)
        slider_mc.x = sliderOrigin + 175

    var playHead:int = Math.round((slider_mc.x/350*8)+1);
    dialSpin_mc.gotoAndStop(playHead);
}

根据滑块的起始位置,播放头的范围会发生变化(因此,如果滑块从 x pos 200 开始,范围将在 2 到 10 之间,在 x pos 400 处,范围在 6 到 14 之间 - 通过更改从 +1 偏移到任何必要的值)。

于 2013-04-10T16:05:35.513 回答