0

我有一个用 actionscript 3 编写的 360 度视图。如何使用播放/暂停按钮控制滑块?我能够让代码工作,但我只是想不出一种方法来控制使用播放/暂停按钮的滑块。我将其用于产品查看器。

    private function createSlider():void
    {
        //Create a librarie object in the stage.
        _roteableObject = new LibrarieObject();
        _roteableObject.x = stage.stageWidth / 2 - _roteableObject.width / 2;
        _roteableObject.y = 0;
        _roteableObject.gotoAndStop(1);
        addChild(_roteableObject);

        //Create the slider
        _slider = new Slider();
        _slider.minimum = 1;
        _slider.maximum = _roteableObject.totalFrames;
        addChild(_slider);
        _slider.width = stage.stageWidth - 250;
        _slider.addEventListener(SliderEvent.THUMB_DRAG, sliderChangeHandler);
        _slider.move(stage.stageWidth / 2 - _slider.width / 2 + 90, _roteableObject.y + 25 + _roteableObject.height - 10);
        _slider.addEventListener(MouseEvent.MOUSE_DOWN, stop360);


        //play / stop button
        _play_btn = new play_btn();
        _stop_btn = new stop_btn();
             addChild(_play_btn);
        addChild(_stop_btn);
        _stop_btn.visible = false;
        _play_btn.addEventListener(MouseEvent.MOUSE_UP, play360);
        _stop_btn.addEventListener(MouseEvent.MOUSE_UP, stop360);
    }

    private function sliderChangeHandler(e:Event):void 
    {
        _roteableObject.gotoAndStop(e.target.value);
    }

    private function play360(e:Event):void
    {
        _roteableObject.play();
        _play_btn.visible = false;
        _stop_btn.visible = true;
    }
    private function stop360(e:Event):void
    {
        _roteableObject.stop();
        _play_btn.visible = true;
        _stop_btn.visible = false;
    }
}

}

4

1 回答 1

0

这是一个应该做你正在寻找的修改。当您单击播放时,它会向变量添加一个ENTER_FRAME侦听器。roteableObject在每个新帧上,它将滑块的value属性设置为 的当前帧号roteableObject,并在调用时删除侦听器stop360()

    private function createSlider():void
    {
        //Create a librarie object in the stage.
        _roteableObject = new LibrarieObject();
        _roteableObject.x = stage.stageWidth / 2 - _roteableObject.width / 2;
        _roteableObject.y = 0;
        _roteableObject.gotoAndStop(1);
        addChild(_roteableObject);

        //Create the slider
        _slider = new Slider();
        _slider.minimum = 1;
        _slider.maximum = _roteableObject.totalFrames;
        addChild(_slider);
        _slider.width = stage.stageWidth - 250;
        _slider.addEventListener(SliderEvent.THUMB_DRAG, sliderChangeHandler);
        _slider.move(stage.stageWidth / 2 - _slider.width / 2 + 90, _roteableObject.y + 25 + _roteableObject.height - 10);
        _slider.addEventListener(MouseEvent.MOUSE_DOWN, stop360);


        //play / stop button
        _play_btn = new play_btn();
        _stop_btn = new stop_btn();
        addChild(_play_btn);
        addChild(_stop_btn);
        _stop_btn.visible = false;
        _play_btn.addEventListener(MouseEvent.MOUSE_UP, play360);
        _stop_btn.addEventListener(MouseEvent.MOUSE_UP, stop360);
    }

    private function sliderChangeHandler(e:Event):void 
    {
        _roteableObject.gotoAndStop(e.target.value);
    }

    private function play360(e:Event):void
    {
        //Listen to new frame events
        _roteableObject.addEventListener(Event.ENTER_FRAME, roteableObject_enterFrame);

        _roteableObject.play();
        _play_btn.visible = false;
        _stop_btn.visible = true;
    }

    private function stop360(e:Event):void
    {
        //Stop listening to new frame events
        if (_roteableObject.hasEventListener(Event.ENTER_FRAME)) _roteableObject.removeEventListener(Event.ENTER_FRAME, roteableObject_enterFrame);

        _roteableObject.stop();
        _play_btn.visible = true;
        _stop_btn.visible = false;
    }

    private function roteableObject_enterFrame(evt:Event):void
    {
        //Update slider position with current frame
        _slider.value = _roteableObject.currentFrame;
    }
于 2013-09-25T18:42:29.757 回答