zoukankan      html  css  js  c++  java
  • Sounds工具类 库中有六种音乐

    package demo.sound
    {
    	import flash.media.*;
    	import flash.events.Event;
    	import flash.utils.*;
    	
    	public class SoundMgr
    	{
    		//背景音乐
    		public static var bgSound:Sound=new BgSound();
    		public static var bgSoundChannel:SoundChannel = new SoundChannel;
    		private static var bgSoundTransform:SoundTransform = new SoundTransform;
    		//mouse is walking
    		private static var mouseWalk:Sound=new MouseWalk();
    		private static var mouseWalkSoundChannel:SoundChannel = new SoundChannel;
    		private static var mouseWalkSoundTransform:SoundTransform = new SoundTransform;
    		//cat wakes up
    		private static var catWakeUp:Sound=new CatWakeUp();
    		private static var catWakeUpSoundChannel:SoundChannel = new SoundChannel;
    		private static var catWakeUpSoundTransform:SoundTransform = new SoundTransform;
    		//food is picked up
    		private static var pickUp:Sound=new PickUp();
    		private static var pickUpSoundChannel:SoundChannel = new SoundChannel;
    		private static var pickUpSoundTransform:SoundTransform = new SoundTransform;
    		//a chili pepper is eaten
    		private static var chiliEate:Sound=new ChiliEate();
    		private static var chiliEateSoundChannel:SoundChannel = new SoundChannel;
    		private static var chiliEateSoundTransform:SoundTransform = new SoundTransform;
    		//cat is looking around
    		private static var lookAround:Sound=new LookAround();
    		private static var lookAroundSoundChannel:SoundChannel = new SoundChannel;
    		private static var lookAroundSoundTransform:SoundTransform = new SoundTransform;
    
    		public function SoundMgr():void
    		{
    			/*
    			判断声音是否播放完
    			if(sound.length == soundChannel.position)
    			{ 
       				trace("song complete")
    			}
    			*/
    		}
    		
    		//--------------------------------------------
    		//背景音乐
    		public static function playBgSound():void
    		{
    			bgSoundChannel = bgSound.play();
    			bgSoundTransform.volume=10;
    			bgSoundChannel.soundTransform=bgSoundTransform;
    		}
    		//背景音乐停止
    		public static function stopBgSound():void
    		{
    			bgSoundChannel.stop();
    		}
    		//背景音乐播放完成
    		public static function bgSoundComplete():void
    		{
    			if(bgSound.length == bgSoundChannel.position)
    			{
    				SoundMgr.playBgSound();
    			}
    		}
    		
    		//--------------------------------------------
    		//mouse is walking
    		public static function playMouseWalkSound():void
    		{
    			mouseWalkSoundChannel = mouseWalk.play(500);
    			mouseWalkSoundTransform.volume=1;
    			mouseWalkSoundChannel.soundTransform=mouseWalkSoundTransform;
    			//输出音乐长度
    			//trace(mouseWalk.length);
    			//走路音乐播放完成
    			//mouseWalk.addEventListener(Event.SOUND_COMPLETE,mouseWalkSoundComplete)
    		}
    		//停止走路音乐
    		public static function stopMouseWalkSound():void
    		{
    			mouseWalkSoundChannel.stop();
    		}
    		//走路音乐播放完成
    		public static function mouseWalkSoundComplete():void
    		{
    			if(mouseWalk.length == mouseWalkSoundChannel.position)
    			{
    				SoundMgr.playMouseWalkSound();
    			}
    		}
    		//走路音乐播放完成
    		/*private static function mouseWalkSoundComplete(e:Event):void
    		{
    			trace("走路音乐播放完毕!!!");
    		}*/
    		
    		//--------------------------------------------
    		//cat wakes up
    		public static function playCatWakeUpSound():void
    		{
    			catWakeUpSoundChannel = catWakeUp.play();
    			catWakeUpSoundTransform.volume=1;
    			catWakeUpSoundChannel.soundTransform=catWakeUpSoundTransform;
    		}
    		//food is picked up
    		public static function playPickUpSound():void
    		{
    			//从500毫秒开始播放
    			pickUpSoundChannel = pickUp.play(500);
    			pickUpSoundTransform.volume=1;
    			pickUpSoundChannel.soundTransform=pickUpSoundTransform;
    			//1500毫秒之后停止播放food is picked up
    			setTimeout(stopPickUpSound,1000);
    		}
    		//一秒钟之后停止播放food is picked up
    		public static function stopPickUpSound():void
    		{
    			pickUpSoundChannel.stop();
    		}
    		
    		//--------------------------------------------
    		//a chili pepper is eaten
    		public static function playChiliEateSound():void
    		{
    			chiliEateSoundChannel = chiliEate.play();
    			chiliEateSoundTransform.volume=0.2;
    			chiliEateSoundChannel.soundTransform=chiliEateSoundTransform;
    		}
    		//停止a chili pepper is eaten
    		public static function stopChiliEateSound():void
    		{
    			chiliEateSoundChannel.stop();
    		}
    		//a chili pepper is eaten音乐播放完成
    		public static function chiliEateSoundComplete():void
    		{
    			if(chiliEate.length == chiliEateSoundChannel.position)
    			{
    				SoundMgr.playChiliEateSound();
    			}
    		}
    		
    		//--------------------------------------------
    		//cat is looking around
    		public static function playLookAroundSound():void
    		{
    			lookAroundSoundChannel = lookAround.play(1000);
    			lookAroundSoundTransform.volume=0.2;
    			lookAroundSoundChannel.soundTransform=lookAroundSoundTransform;
    		}
    		//停止cat is looking around
    		public static function stopLookAroundSound():void
    		{
    			lookAroundSoundChannel.stop();
    		}
    		//cat is looking around音乐播放完成
    		public static function lookAroundSoundComplete():void
    		{
    			if(lookAround.length == lookAroundSoundChannel.position)
    			{
    				SoundMgr.playLookAroundSound();
    			}
    		}
    		
    		public static function stopAllSound():void
    		{
    			SoundMixer.stopAll();
    			/*stopBgSound();
    			stopMouseWalkSound();
    			stopPickUpSound();
    			stopChiliEateSound();
    			stopChiliEateSound();
    			stopLookAroundSound();*/
    		}
    	}
    }
    
  • 相关阅读:
    练习 字符串存入字典 数组的降序 倒序 字符串目录存不存在 数组中文排序
    随机 随机获得100个50-100的数字字符串,存到数组并输出
    练习 字符串10题
    把一个字符串反输出abc123.xyz789输出987zyx.321cba
    把NSString *string=@"2013 年 05 月 05 日";以2013-05-05输出
    dephi cef3获取Post数据
    Delphi下 多显示器,将窗体显示于第二个显示器
    Delphi下POS机
    SQLConnection 连接 SQLite
    cxGrid主视图取得从视图
  • 原文地址:https://www.cnblogs.com/602147629/p/1956179.html
Copyright © 2011-2022 走看看