首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SoundChannel、removeEventHandler、AS3

SoundChannel、removeEventHandler、AS3
EN

Stack Overflow用户
提问于 2010-04-06 05:39:00
回答 2查看 430关注 0票数 0

有没有更好的方式使用AS3声道?这是有效的,但我讨厌当我点击播放按钮两次,它开始加倍。请给我建议。

代码语言:javascript
复制
var mySound:Sound = new Sound();
playButton.addEventListener (MouseEvent.CLICK, myPlayButtonHandler);
var myChannel:SoundChannel = new SoundChannel();
        function myPlayButtonHandler (e:MouseEvent):void {

            myChannel = mySound.play();
            }
stopButton.addEventListener(MouseEvent.CLICK, onClickStop);
        function onClickStop(e:MouseEvent):void{
            myChannel.stop();
            }

/*-----------------------------------------------------------------*/
//global sound buttons, add instance of 'killswitch' and 'onswitch' to stage
killswitch.addEventListener(MouseEvent.CLICK, clipKillSwitch); 
        function clipKillSwitch(e:MouseEvent):void{ 
var transform1:SoundTransform=new SoundTransform();
transform1.volume=0;
flash.media.SoundMixer.soundTransform=transform1;
            }       
onswitch.addEventListener(MouseEvent.CLICK, clipOnSwitch); 
        function clipOnSwitch(e:MouseEvent):void{ 
var transform1_:SoundTransform=new SoundTransform();        
transform1_.volume=1;
flash.media.SoundMixer.soundTransform=transform1_;      
            }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-04-06 05:47:07

只需在声音持续时间内使用removeEventListener()分离myPlayButtonHandler即可。

票数 1
EN

Stack Overflow用户

发布于 2010-04-06 09:22:22

代码语言:javascript
复制
var mySound:Sound = new Sound();
playButton.addEventListener (MouseEvent.CLICK, myPlayButtonHandler);
var myChannel:SoundChannel = new SoundChannel();
        function myPlayButtonHandler (e:MouseEvent):void {

            myChannel = mySound.play();
            removeEventListener(MouseEvent.CLICK, myPlayButtonHandler);
            }
stopButton.addEventListener(MouseEvent.CLICK, onClickStop);
        function onClickStop(e:MouseEvent):void{
            myChannel.stop();
            removeEventListener(MouseEvent.CLICK, myPlayButtonHandler);

            }

/*-----------------------------------------------------------------*/
//global sound buttons, add instance of 'killswitch' and 'onswitch' to stage
killswitch.addEventListener(MouseEvent.CLICK, clipKillSwitch); 
        function clipKillSwitch(e:MouseEvent):void{ 
var transform1:SoundTransform=new SoundTransform();
transform1.volume=0;
flash.media.SoundMixer.soundTransform=transform1;
            }       
onswitch.addEventListener(MouseEvent.CLICK, clipOnSwitch); 
        function clipOnSwitch(e:MouseEvent):void{ 
var transform1_:SoundTransform=new SoundTransform();        
transform1_.volume=1;
flash.media.SoundMixer.soundTransform=transform1_;      
            }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2581350

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档