0

我是动作脚本和 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 就是这个原因。我不知道我该如何解决。请清除任何人,谢谢提前

4

1 回答 1

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;
    }
于 2013-07-26T06:33:25.293 回答