我是动作脚本和flash的新手,我正在创建在线广播播放器。在这里,我面临着简单的问题。我想要在我悬停图像时更改按钮图像,无论是播放还是停止按钮。我为每个按钮创建了符号并创建了实例名称。我分别放了第一个播放按钮和下一个播放按钮和停止按钮和停留按钮。我在一层完成了这一切。这里是我的悬停动作脚本
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.events.Event;
/****stop-control:***/
btnstop.addEventListener(MouseEvent.MOUSE_OUT,StopOut);
btnstopo.addEventListener(MouseEvent.MOUSE_OVER,StopOver);
function StopOver(evt:MouseEvent):void
{
btnstopo.visible=false;
btnstop.visible=true;
}
function StopOut(evt:MouseEvent):void
{
btnstop.visible=false;
btnstopo.visible=true;
}
/*****Play control:****/
playbtn.addEventListener(MouseEvent.MOUSE_OUT,PlayOut);
btnplayo.addEventListener(MouseEvent.MOUSE_OVER,PlayOver);
function PlayOver(evt:MouseEvent):void
{
btnplayo.visible=false;
playbtn.visible=true;
}
function PlayOut(evt:MouseEvent):void
{
playbtn.visible=false;
btnplayo.visible=true;
}
var soundfile:URLRequest = new URLRequest('http://live32.radio.com:80/;stream1.mp3');
var channel:SoundChannel = new SoundChannel();
var sTransform:SoundTransform = new SoundTransform();
var isplay=1;
var myMusic:Sound = new Sound();
myMusic.load(soundfile);
channel=myMusic.play();
playbtn.addEventListener(MouseEvent.CLICK,PlayRadio);
btnstop.addEventListener(MouseEvent.CLICK,StopRadio);
function PlayRadio(evt:Event):void
{
if(isplay==0)
{
isplay=1;
/*var myMusic:Sound = new Sound();
myMusic.load(soundfile);
channel=myMusic.play(); */
SoundMixer.soundTransform = new SoundTransform(1);
btnstop.visible=true;
playbtn.visible=false;
}
}
function StopRadio(evt:Event):void
{
if(isplay==1)
{
SoundMixer.soundTransform = new SoundTransform(0);
isplay=0;
btnstop.visible=false;
playbtn.visible=true;
}
}
这里我的问题是,当我点击停止按钮它工作正常。但停止后我需要显示播放按钮。但根据我的代码,它会在停止后再次显示停止按钮。我知道它显示停止按钮的原因。 MOUSE_OUT就是这个原因。我不知道如何解决这个问题。请清除任何人,谢谢提前
答案 0 :(得分:0)
removeEventlistner
。
这里如果我点击停止按钮删除停止EventLIstner并添加Play EventLIstner。像对面的播放按钮这里的示例代码
function PlayRadio(evt:Event):void
{
if(isplay==0)
{
isplay=1;
/*var myMusic:Sound = new Sound();
myMusic.load(soundfile);
channel=myMusic.play(); */
btnplay.removeEventListener(MouseEvent.MOUSE_OUT,PlayOut);
btnplayo.removeEventListener(MouseEvent.MOUSE_OVER,PlayOver);
btnstop.addEventListener(MouseEvent.MOUSE_OUT,StopOut);
btnstopo.addEventListener(MouseEvent.MOUSE_OVER,StopOver);
SoundMixer.soundTransform = new SoundTransform(1);
btnstop.visible=true;
btnplay.visible=false;
}
}
function StopRadio(evt:Event):void
{
if(isplay==1)
{
btnstop.removeEventListener(MouseEvent.MOUSE_OUT,StopOut);
btnstopo.removeEventListener(MouseEvent.MOUSE_OVER,StopOver);
btnplay.addEventListener(MouseEvent.MOUSE_OUT,PlayOut);
btnplayo.addEventListener(MouseEvent.MOUSE_OVER,PlayOver);
SoundMixer.soundTransform = new SoundTransform(0);
isplay=0;
btnstop.visible=false;
btnplay.visible=true;
}