[AS3]as3下写的声音类文件示例
[AS3]as3下写的声音类文件示例
[AS3]as3下写的声音类文件示例
- package com.gchen{
- import flash.media.Sound;
- import flash.media.SoundChannel;
- import flash.media.SoundTransform;
- import flash.utils.getDefinitionByName;
- import flash.utils.Timer;
- import flash.events.Event;
- import flash.events.TimerEvent;
- public class SubSound extends Sound{
- private var _obj:Object={}
- private var oldPlay:String="";
- private var timer:Timer;
- private var timerChannel:Timer;
- private var _end:int;
- public function SubSound() {
- super();
- timer=new Timer(100);
- timerChannel=new Timer(100,20)
- timer.addEventListener(TimerEvent.TIMER,timerHandle);
- timerChannel.addEventListener(TimerEvent.TIMER,timerChannelHandle);
- }
- public function playSound(name:String,start:int=0,end:int=0,loops:int=0){
- if(name=="") return;
- var channel:SoundChannel=new SoundChannel();
- var _sound:Sound=getSound(name);
- channel=_sound.play(start);
- oldPlay=name;
- if(oldPlay!=""){
- timerChannel.reset();
- timerChannel.start();
- }
- if(end!=0){
- _end=end;
- timer.start();
- }
- _obj[name]=channel;
- }
- public function get obj():Object{
- return _obj;
- }
- private function timerHandle(e:TimerEvent):void{
- if(_obj[oldPlay].position>_end){
- _obj[oldPlay].stop()
- timer.reset()
- }
- }
- private function timerChannelHandle(e:TimerEvent):void{
- for(var i in _obj) {
- if(i!=oldPlay){
- var value:Number = _obj[i].soundTransform.volume
- if(value<0){
- _obj[i].stop();
- }
- setVolume(_obj[i],value-.1)
- }
- }
- }
- public function setVolume(channel:SoundChannel,volume:Number):void {
- var transform:SoundTransform = channel.soundTransform;
- transform.volume = volume;
- channel.soundTransform = transform;
- }
- private function getSound(name:String):*{
- var _c:*=getDefinitionByName(name) as Class
- return new _c();
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...