Я делаю флеш-плательщик.Я уже закончил часть объема, и я также хочу добавить две функции.Во-первых, когда пользователь нажимает кнопку «Добавить», он увеличивает текущую громкость и меняет цвет отображения громкости.Другой - когда пользователь нажимает кнопку «минус», он уменьшает текущую громкость и меняет цвет дисплея громкости.
Как мне написать эти две функции?Меня пробовали за цикл, но я настолько новичок в программировании, что он полностью запутался ...
Мой текущий код ActionScript -
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;
}
Спасибо за любой ответ