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

Here's a modification that should do what you're looking for. It adds an ENTER_FRAME listener to the roteableObject variable when you click to play. On each new frame it sets the slider's value property to the current frame number of roteableObject, and the listener is removed when stop360() is called.

    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 に答える