我正在为我的在线脚本课程开发一个视频播放器,我正在播放我的视频,我的播放和我的静音按钮都正常处理正确的悬停状态和所有内容。它们正确定位并准备就绪。现在我必须创建我的Time Slider和我的Volume Slider,这就是困难所在。我创建了一个名为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();
}
}
VolumeBar都
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();
}
}
我现在想知道的是如何在屏幕上显示它并且基本上可以移动。一旦我做到了,我知道我可以自己完成其余的工作。谢谢Stack Overflowers!
答案 0 :(得分:0)
您是否忘记将sliderVolume
和sliderControl
添加到显示列表中?
我想你可以这样做:
VolumeBar.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上进行音量更改。
我希望这会对你有所帮助:)。