有人可以帮我解决我的代码吗? 我试图用5个按钮制作一个简单的收音机,每个按钮播放一个无线电流。 我的问题是,当我点击按钮上的第6次时,它不起作用。
以下是它的工作原理:
点击btn1 - >流来了
点击btn2 - >流来了
点击btn3 - >流来了
点击btn4 - >流来了
点击btn5 - >流来了 点击btn1(再次) - >现在它不起作用。
没关系女巫按钮是第6个,流不会第6次播放。
import flash.media.Sound;
theVoice_btn.addEventListener(MouseEvent.CLICK, theVoice);
Radio1Trd_btn.addEventListener(MouseEvent.CLICK, Radio1Trd);
RadioRock_btn.addEventListener(MouseEvent.CLICK, RadioRock);
P5Trd_btn.addEventListener(MouseEvent.CLICK, P5Trd);
Topp1000_btn.addEventListener(MouseEvent.CLICK, topp1000);
var fl_SC:SoundChannel;
var det_spilles:Boolean = false; //this var keep track if its something playing on the radio
var s:Sound;
function theVoice(evt:MouseEvent):void
{
if(det_spilles)
{
fl_SC.stop()
s = new Sound(new URLRequest("http://radio1.stream.mp3"));
fl_SC = s.play();
}
else
{
s = new Sound(new URLRequest("http://radio1.stream.mp3"));
fl_SC = s.play();
det_spilles=true;
}
}
function Radio1Trd(evt:MouseEvent):void
{
if(det_spilles)
{
fl_SC.stop()
s = new Sound(new URLRequest("http://radio2.stream.mp3"));
fl_SC = s.play();
}
else
{
s = new Sound(new URLRequest("http://radio2.stream.mp3"));
fl_SC=s.play()
det_spilles=true;
}
}
function RadioRock(evt:MouseEvent):void
{
if(det_spilles)
{
fl_SC.stop()
s = new Sound(new URLRequest("http://radio3.stream.mp3"));
fl_SC = s.play();
}
else
{
s = new Sound(new URLRequest("radio3.stream.mp3"));
fl_SC=s.play();
det_spilles=true;
}
}
function P5Trd(evt:MouseEvent):void
{
if(det_spilles)
{
fl_SC.stop()
s = new Sound(new URLRequest("radio4.stream.mp3"));
fl_SC = s.play();
}
else
{
s = new Sound(new URLRequest("http://radio4.stream.mp3"));
fl_SC=s.play();
det_spilles=false;
}
}
function topp1000(evt:MouseEvent):void
{
if(det_spilles)
{
fl_SC.stop()
s = new Sound(new URLRequest("radio5.stream.mp3"));
fl_SC = s.play();
}
else
{
s = new Sound(new URLRequest("http://radio5.stream.mp3"));
fl_SC=s.play();
det_spilles=true;
}
}
更新:
现在我只有一个按钮和以下代码:
我删除了所有其他按钮,我只用一个按钮就有一小段代码。我尝试使用private var s:Sound = new Sound()
,但收到以下错误1013: The private attribute may be used only on class property definitions.
,因此我删除了private
部分,现在我的代码如下所示:
import flash.net.URLRequest;
import flash.media.Sound;
theVoice_btn.addEventListener(MouseEvent.CLICK, theVoice);
var fl_SC:SoundChannel;
var s:Sound = new Sound();
function theVoice(evt:MouseEvent):void
{
if(fl_SC)
{
fl_SC.stop()
s.load(new URLRequest ("http://stream.sbsradio.no:8000/thevoiceoslo.mp3"));
fl_SC = s.play();
}
else
{
s.load(new URLRequest("http://stream.sbsradio.no:8000/thevoiceoslo.mp3"));
fl_SC = s.play();
}
}
现在当我再次点击同一个按钮时出现以下错误:Error: Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.
at flash.media::Sound/_load()
at flash.media::Sound/load()
at NettRadio_fla::MainTimeline/theVoice()
更新#2
为什么我只能点击按钮4次才有效但不是第5次?!?!?!? 这是我现在的代码:
import flash.net.URLRequest;
import flash.media.Sound;
theVoice_btn.addEventListener(MouseEvent.CLICK, theVoice);
var fl_SC:SoundChannel;
var s:Sound = new Sound();
function theVoice(evt:MouseEvent):void
{
if(fl_SC)
{
fl_SC.stop()
s = new Sound (new URLRequest ("http://stream.sbsradio.no:8000/thevoiceoslo.mp3"));
fl_SC = s.play();
}
else
{
s= new Sound (new URLRequest("http://stream.sbsradio.no:8000/thevoiceoslo.mp3"));
fl_SC = s.play();
}
}