0

我正在为我的在线脚本课程开发视频播放器,我的视频播放、播放和静音按钮都在正确的悬停状态和所有内容下工作。它们已正确定位并准备就绪。现在我必须创建我的时间滑块和我的音量滑块,这就是困难所在。我创建了一个名为 VolumeBar 的 ActionScript 3 文件,但我不知道它为什么不起作用。在我看来,它应该可以工作,但我认为我遗漏了一些东西。

我的符号是 BTN_Slider、BTN_VolumeBar 和 BTN_VolumeBarSlider。这些教程都没有帮助,因为它们都在我没有做的框架内使用“动作”功能

主要的

import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.media.SoundTransform;

public class Main extends Sprite
{
    static public var splash:SplashScreen;
    private var theXMLFile:String = "VideoList.xml";
    private var theVideoList:VideoList;
    private var videoChoice:int = 0;
    private var sndTransform:SoundTransform;
    private var lastVolume:int = 1;
    private var btn_Mute:BTN_Mute;
    private var btn_Play:BTN_Play;
    private var btn_Volume:VolumeBar;
    static public var screenState:int = 0;
    static public var nextState:int = 1;

    public function Main()
    {
        theVideoList = new VideoList(theXMLFile);
        btn_Mute = new BTN_Mute(581.3, 457.5);
        btn_Play = new BTN_Play(42, 457.5);
        btn_Volume = new VolumeBar(624.3, 457.5);
        btn_Mute.addEventListener(MouseEvent.CLICK, clickedMute);
        addEventListener(Event.ENTER_FRAME, update);
    }

    private function update(e:Event):void
    {
        switch(screenState)
        {
            case 0 :
                break;
            case 1 :
                videoChoice = 0;
                nextState = 2;
                displayScreen();
                trace("TEST");
                addChild(btn_Volume);
                addChild(btn_Mute);
                addChild(btn_Play);
                break;
            case 2 :
                videoChoice = 1;
                nextState = 3;
                changeScreen();
                break;
        }
        screenState = 0;
    }

    public function displayScreen():void
    {
        splash = new SplashScreen(theVideoList.videoXML.theVideo[videoChoice].fileLoc.text());
        addChild(splash);
    }

    public function changeScreen():void
    {
        var toShow:String = theVideoList.videoXML.theVideo[videoChoice].fileLoc.text();
        splash.connectVideo(toShow);
    }

    private function muteVolume(vol:Number):void
    {
        sndTransform = new SoundTransform(vol);
        splash.vidStream.soundTransform = sndTransform;
    }

    private function clickedMute(mb:MouseEvent):void
    {
        if(btn_Mute.isMuted == true)
        {
            muteVolume(lastVolume = 1);
            btn_Mute.isMuted = false;
        }
        else if(btn_Mute.isMuted == false)
        {
            muteVolume(lastVolume = 0);
            btn_Mute.isMuted = true;
        }
    }

    static public function togglePlay():void
    {
        splash.vidStream.togglePause();
    }
}

音量条

import flash.display.*;
import flash.events.*;
import flash.geom.Rectangle;

public class VolumeBar extends MovieClip
{
    var sliderControl = new BTN_Slider();
    var sliderVolume = new BTN_VolumeBar();
    var knobWidth:int = sliderControl.width;
    var trackWidth:int = sliderVolume.width;
    var trackX:int = sliderVolume.x;
    var boundWidth = trackWidth - knobWidth;
    var boundsRect:Rectangle = new Rectangle(trackX, 0, boundWidth, 0);

    public function VolumeBar(theX:int, theY:int)
    {
        this.x = theX;
        this.y = theY;

        sliderControl.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
        sliderControl.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
        sliderControl.addEventListener(MouseEvent.MOUSE_OUT, stopDragging);
    }

    private function startDragging(mb:MouseEvent):void
    {
        sliderControl.startDrag(false, boundsRect);
    }

    private function stopDragging(mb:MouseEvent):void
    {
        sliderControl.stopDrag();
    }
}

我现在想知道的是如何将它放在屏幕上并且基本上可以移动。一旦我做到了,我知道我可以自己搞定剩下的。感谢堆栈溢出者!

4

1 回答 1

0



您不会忘记将sliderVolumeand添加sliderControl到显示列表中吗?
我认为你可以这样做:

音量条.as:

import flash.display.*;
import flash.events.*;
import flash.geom.Rectangle;

public class VolumeBar extends MovieClip
{
    var sliderControl = new BTN_Slider();
    var sliderVolume = new BTN_VolumeBar();
    var knobWidth:int = sliderControl.width;
    var trackWidth:int = sliderVolume.width;
    var trackX:int = sliderVolume.x;
    var boundWidth = trackWidth - knobWidth;
    var boundsRect:Rectangle = new Rectangle(trackX, 0, boundWidth, 0);

    /** a function to call when volume change **/ 
    private var _volumeChanged:Function;

    public function VolumeBar(theX:int, theY:int, volumeChanged:Function)
    {
        this.x = theX;
        this.y = theY;

                    // add the volume bar to the display list
        addChild( sliderVolume );
                    // add the slider to the display list
        addChild( sliderControl );
        // keep reference to the update function 
        _volumeChanged = volumeChanged;

        sliderControl.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
        sliderControl.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
        sliderControl.addEventListener(MouseEvent.MOUSE_OUT, stopDragging);
    }

    private function startDragging(mb:MouseEvent):void
    {
        sliderControl.startDrag(false, boundsRect);
        stage.addEventListener( MouseEvent.MOUSE_MOVE, _onMouseMove );
    }

    private function stopDragging(mb:MouseEvent):void
    {
        sliderControl.stopDrag();
        stage.removeEventListener( MouseEvent.MOUSE_MOVE );
    }

    private function onMouseMove(e:MouseEvent):void
    {
        // calculate the volume for the current cursor position
        var value:Number = (trackWidth - sliderControl.x) / boundWidth;
        _volumeChanged( value );
    }
}

并将您的 Main 类更改如下:

public function Main()
{
    theVideoList = new VideoList(theXMLFile);
    btn_Mute = new BTN_Mute(581.3, 457.5);
    btn_Play = new BTN_Play(42, 457.5);

    // add the callback function to the VolumeBar constructor
    btn_Volume = new VolumeBar(624.3, 457.5, _onVolumeChanged);
    btn_Mute.addEventListener(MouseEvent.CLICK, clickedMute);
    addEventListener(Event.ENTER_FRAME, update);
}

/** handle volume changing **/
private function _onVolumeChanged( value:Number ):void
{
    // change your volume here
}

当然你可以使用事件来做到这一点,但我更喜欢回调,如果你愿意,你可以在停止拖动时改变音量而不是 mouseMove。

我希望这能帮到您 :)

于 2013-11-11T09:41:10.623 回答