Actionscript 3 困惑于为什么音量控制在ActionScript 3中不起作用
我正在为我的在线脚本课程开发一个视频播放器,我的视频播放、播放和静音按钮都在正确的悬停状态下工作。他们的位置正确,随时可以出发。现在我必须创建我的时间滑块和音量滑块,这就是困难所在。我已经创建了一个名为VolumeBar的ActionScript3文件,我不知道为什么它不工作。在我的头脑中,它应该起作用,但我认为我错过了一些东西 我的符号是BTN_滑块、BTN_卷栏和BTN_卷栏滑块。这些教程都没有帮助,因为它们都在框架中使用了“动作”函数,而我没有这样做 主要 卷杆Actionscript 3 困惑于为什么音量控制在ActionScript 3中不起作用,actionscript-3,flash,Actionscript 3,Flash,我正在为我的在线脚本课程开发一个视频播放器,我的视频播放、播放和静音按钮都在正确的悬停状态下工作。他们的位置正确,随时可以出发。现在我必须创建我的时间滑块和音量滑块,这就是困难所在。我已经创建了一个名为VolumeBar的ActionScript3文件,我不知道为什么它不工作。在我的头脑中,它应该起作用,但我认为我错过了一些东西 我的符号是BTN_滑块、BTN_卷栏和BTN_卷栏滑块。这些教程都没有帮助,因为它们都在框架中使用了“动作”函数,而我没有这样做 主要 卷杆 import flash.
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();
}
}
我现在想知道的是如何让它出现在屏幕上,并且基本上是可移动的。一旦我做到了,我知道我可以自己得到剩下的。谢谢堆栈溢出器 您是否忘了将
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 );
}
}
并按如下方式更改主类:
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时更改卷。
我希望这将帮助您:)滑块在拖动时是否移动?我认为这些计算是错误的:var trackX:int=sliderVolume.x;var boundWidth=轨迹宽度-knobWidth;变量boundsRect:Rectangle=新矩形(trackX,0,boundWidth,0);这太棒了!非常感谢你!一切都好用!我有一些定位问题与我的滑块,但这完全工作!开始越来越多地理解ActionScript 3!
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
}