我正在制作闪光灯付款人。 我已经完成了音量部分,我还想添加两个功能。 一种是当用户点击“添加按钮”时,它会增加当前音量并改变音量显示颜色。 另一种是当用户点击“减号”按钮时,它会减小当前音量并改变音量显示颜色。
如何编写这两个函数? 我已经尝试过循环,但我是如此新的程序,所以它完全搞砸......
我当前的动作脚本代码是
import flash.net.URLRequest;
import flash.media.Sound;
import flash.events.Event;
import flash.media.SoundChannel;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.media.SoundTransform;
var audiofile:URLRequest=new URLRequest("mvl_player_test.mp3");
var song:Sound=new Sound();
var songcontro:SoundChannel;
var resumetime:Number = 0;
song.addEventListener(Event.COMPLETE, songLoaded);
song.addEventListener(ProgressEvent.PROGRESS, trackLoad);
song.load(audiofile);
function songLoaded(evt:Event):void{//play songs
play_btn.addEventListener(MouseEvent.CLICK, clickedplay);
pause_btn.addEventListener(MouseEvent.CLICK, clickedpause);
volume_1.addEventListener(MouseEvent.CLICK, clickedVol_1);
volume_2.addEventListener(MouseEvent.CLICK, clickedVol_2);
volume_3.addEventListener(MouseEvent.CLICK, clickedVol_3);
volume_4.addEventListener(MouseEvent.CLICK, clickedVol_4);
volume_5.addEventListener(MouseEvent.CLICK, clickedVol_5);
volume_6.addEventListener(MouseEvent.CLICK, clickedVol_6);
volume_7.addEventListener(MouseEvent.CLICK, clickedVol_7);
}
function clickedplay(evt:MouseEvent):void{
play_btn.visible = false;
pause_btn.visible = true;
songcontro=song.play(resumetime);
addEventListener(Event.ENTER_FRAME, trackPlayback);
}
function clickedpause(evt:MouseEvent):void{
play_btn.visible = true;
pause_btn.visible = false;
resumetime = songcontro.position;
songcontro.stop();
removeEventListener(Event.ENTER_FRAME, trackPlayback);
}
function trackLoad(evt:ProgressEvent):void
{
load_progress.scaleX = evt.bytesLoaded / evt.bytesTotal;
}
function trackPlayback(evt:Event):void
{
var perPlayed:Number = songcontro.position / song.length;
played_progress.scaleX = perPlayed * (song_row.width) + song_row.scaleX;
}
这是代码参考音量显示区域
function clickedVol_1(evt:MouseEvent):void
{
var volControl:SoundTransform = songcontro.soundTransform;
volControl.volume = 0.1;
songcontro.soundTransform = volControl;
volume_1.visible = false;
volume_1_2.visible = true;
volume_2_2.visible = false;
volume_3_2.visible = false;
volume_4_2.visible = false;
volume_5_2.visible = false;
volume_6_2.visible = false;
volume_7_2.visible = false;
}
function clickedVol_2(evt:MouseEvent):void
{
var volControl:SoundTransform = songcontro.soundTransform;
volControl.volume = 0.3;
songcontro.soundTransform = volControl;
volume_1.visible = false;
volume_2.visible = false;
volume_1_2.visible = true;
volume_2_2.visible = true;
volume_3_2.visible = false;
volume_4_2.visible = false;
volume_5_2.visible = false;
volume_6_2.visible = false;
volume_7_2.visible = false;
}
function clickedVol_3(evt:MouseEvent):void
{
var volControl:SoundTransform = songcontro.soundTransform;
volControl.volume = 0.4;
songcontro.soundTransform = volControl;
volume_1.visible = false;
volume_2.visible = false;
volume_3.visible = false;
volume_1_2.visible = true;
volume_2_2.visible = true;
volume_3_2.visible = true;
volume_4_2.visible = false;
volume_5_2.visible = false;
volume_6_2.visible = false;
volume_7_2.visible = false;
}
function clickedVol_4(evt:MouseEvent):void
{
var volControl:SoundTransform = songcontro.soundTransform;
volControl.volume = 0.5;
songcontro.soundTransform = volControl;
volume_1.visible = false;
volume_2.visible = false;
volume_3.visible = false;
volume_4.visible = false;
volume_1_2.visible = true;
volume_2_2.visible = true;
volume_3_2.visible = true;
volume_4_2.visible = true;
volume_5_2.visible = false;
volume_6_2.visible = false;
volume_7_2.visible = false;
}
function clickedVol_5(evt:MouseEvent):void
{
var volControl:SoundTransform = songcontro.soundTransform;
volControl.volume = 0.6;
songcontro.soundTransform = volControl;
volume_1.visible = false;
volume_2.visible = false;
volume_3.visible = false;
volume_4.visible = false;
volume_5.visible = false;
volume_1_2.visible = true;
volume_2_2.visible = true;
volume_3_2.visible = true;
volume_4_2.visible = true;
volume_5_2.visible = true;
volume_6_2.visible = false;
volume_7_2.visible = false;
}
function clickedVol_6(evt:MouseEvent):void
{
var volControl:SoundTransform = songcontro.soundTransform;
volControl.volume = 0.7;
songcontro.soundTransform = volControl;
volume_1.visible = false;
volume_2.visible = false;
volume_3.visible = false;
volume_4.visible = false;
volume_5.visible = false;
volume_6.visible = false;
volume_1_2.visible = true;
volume_2_2.visible = true;
volume_3_2.visible = true;
volume_4_2.visible = true;
volume_5_2.visible = true;
volume_6_2.visible = true;
volume_7_2.visible = false;
}
function clickedVol_7(evt:MouseEvent):void
{
var volControl:SoundTransform = songcontro.soundTransform;
volControl.volume = 1;
songcontro.soundTransform = volControl;
volume_1.visible = false;
volume_2.visible = false;
volume_3.visible = false;
volume_4.visible = false;
volume_5.visible = false;
volume_6.visible = false;
volume_7.visible = false;
volume_1_2.visible = true;
volume_2_2.visible = true;
volume_3_2.visible = true;
volume_4_2.visible = true;
volume_5_2.visible = true;
volume_6_2.visible = true;
volume_7_2.visible = true;
}
感谢您的回答
答案 0 :(得分:1)
我认为你的问题在于你有几个音量按钮。我会有一个酒吧和两个按钮,加号和减号。当您单击plusButton
时,运行一个函数setVolume(volume)
,将新卷设置为变量,确保它在0和1之间。在函数结束时,您可以根据函数更新条形图形体积百分比。我不喜欢你有那么多按钮的idéa。制作一个包含多个框架的按钮。每个框架都会亮起一个新的音量按钮。单击整个剪辑时,您可以计算mousePositionX
的百分比和volumeBar
的内容来获取新卷。在updateBArGraphics函数中,您只需将百分比与您拥有的帧数进行比较,然后使用goToAndStop(volumeFrame)
。
这是我脑子里写的,所以会有错误:
private function setVolume(newVolume : Number) : void
{
if(newVolume > 1)
newVolume = 1;
if(newVolume < 0)
newVolume = 0;
volControl.volume = newVolume;
songcontrol.soundTransform = volControl;
updateVolumeBarGraphics();
}
private function onVolumeBarClickHandler(event : MouseEvent) : void
{
// calculate where on the bar you clicked using MouseX and bar.width
var calculatedPercentage : Number =
// set new volume
setVolume(caculatedPercentage);
}
private function onVolumeMinusClickHandler(event : MouseEvent) : void
{
setVolume(volControl.volume - 0.2);
}
private function onVolumeMinusClickHandler(event : MouseEvent) : void
{
setVolume(volControl.volume + 0.2);
}
private function updateVolumeBarGraphics(newVolume : Number) : void
{
var volumeFrame : int = Math.floor(newVolume * volumeBar.totalFrames) + 1;
volumeBar.gotoAndStop(volumeFrame);
}
类似的东西。