⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cfsound.as

📁 flash强大事件机制扩展类
💻 AS
字号:
//----------------------------------------
/*
@Description:  继承自Sound类.
增加的方法,属性和事件:
----------------------------------------
//方法:
public stop():void     					停止声音.
public pause():void					暂停声音.
public getPlayTimer(isReduce:Boolean):String		获取当前播放的时间,格式为"00:00".isReduce 是否减少.默认为增加.
public getLoadPercentage(p:Number):Number		获取加载百分比.p(百分比) 属性值默认为 100.
public getPlayPercentage(p:Number):Number		获取播放百分比.p(百分比) 属性值默认为 100.

public setClipTotalTime(c1:MovieClip, c2:MovieClip, s1:MovieClip, s2:MovieClip):void
用影片剪辑显示声音的总时间.参数: c1,c2,s1,s2 相当于 "00:00". 
这些影片都有10帧.第一帧要停止影片播放.帧的内容是 0-9.就是第一帧显示0,第二帧显示1...到10.

public setClipPlayTime(c1:MovieClip, c2:MovieClip, s1:MovieClip, s2:MovieClip, isReduce:Boolean):void
当前播放的时间,同上. isReduce 同 getPlayTimer .

//属性:
public totalTime:Number  [只读]		声音的总时间,格式为"00:00".
public isPlaying:Boolean [只读]		声音是否正在播放.
public pan:Number			确定声音在左右声道(扬声器)中是如何播放的.有效值为 -1 到 1.
public volume:Number			音量.有效值为 0 到 1.

//事件
soundComplete 		声音播放完成时调用.
----------------------------------------
@usage:   
@example: 
//
请查看 Example/AS3/media/CFSound/CFSoundExample.fla 示例文档.
//
@author:  ChooseFlash
@date:  2007-07-07
*/
//----------------------------------------
package AS3.media
{
	//----------------------------------------
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;
	import flash.media.SoundLoaderContext;
	//----------------------------------------
	public class CFSound extends Sound
	{
		//----------------------------------------
		private var _recordTime:Number = 0;
		private var _isPlaying:Boolean;
		//----------------------------------------
		private var channel:SoundChannel;
		//----------------------------------------
		public function CFSound(stream:URLRequest = null, context:SoundLoaderContext = null)
		{
			super(stream, context);
			this._isPlaying = false;
		}
		//----------------------------------------
		public override function load(stream:URLRequest, context:SoundLoaderContext = null):void 
		{
			super.load(stream, context);
			this._isPlaying = false;
		}
		public override function play(startTime:Number = 0, loops:int = 0, sndTransform:SoundTransform = null):SoundChannel
		{
			if (!this._isPlaying) {
				if (startTime != 0) {
					this._recordTime = startTime;
				}
				this._isPlaying = true;
				this.channel = super.play(this._recordTime, loops, sndTransform);
				this.channel.addEventListener(Event.SOUND_COMPLETE, this.soundCompleteHandler);
			}
			return this.channel;
		}
		public function pause():void
		{
			this._recordTime = this.channel.position;
			this.stopSound();
		}
		public function stop():void
		{
			this._recordTime = 0;
			this.stopSound();
		}
		public function getPlayTime(isReduce:Boolean = false):String
		{
			if (isReduce) {
				return this.getSoundTime(this.length - this.channel.position);
			} else {
				return this.getSoundTime(this.channel.position);
			}
		}
		public function getLoadPercentage(p:Number = 100):Number
		{
			return Math.floor(this.bytesLoaded / this.bytesTotal * p);
		}
		public function getPlayPercentage(p:Number = 100):Number
		{
			return Math.floor(this.channel.position / this.length * p);
		}
		public function setClipTotalTime(c1:Object, c2:Object, s1:Object, s2:Object):void
		{
			this.setClipTime(this.length, c1, c2, s1, s2);
		}
		public function setClipPlayTime(c1:Object, c2:Object, s1:Object, s2:Object, isReduce:Boolean = false):void
		{
			if(isReduce){
				this.setClipTime(this.length - this.channel.position, c1, c2, s1, s2);
			}else{
				this.setClipTime(this.channel.position, c1, c2, s1, s2);
			}
		}
		//----------------------------------------
		private function getSoundTime(time:Number):String
		{
			var cent:Number = Math.floor(time / 1000 / 60);
			var second:Number = Math.floor(time / 1000 % 60);
			if (cent < 10) {
				if (second < 10) {
					return ("0" + cent + ":0" + second);
				} else {
					return ("0" + cent + ":" + second);
				}
			} else {
				if (second < 10) {
					return cent + ":0" + second;
				} else {
					return cent + ":" + second;
				}
			}
		}
		private function setClipTime(time:Number, c1:Object, c2:Object, s1:Object, s2:Object):void
		{
			var cent:Number = Math.floor(time / 1000 / 60);
			var second:Number = Math.floor(time / 1000 % 60);
			c1.gotoAndStop(Math.floor(cent / 10) + 1);
			c2.gotoAndStop(cent % 10 + 1);
			s1.gotoAndStop(Math.floor(second / 10) + 1);
			s2.gotoAndStop(second % 10 + 1);
		}
		private function stopSound():void
		{
			this._isPlaying = false;
			this.channel.stop();
		}
		private function soundCompleteHandler(evt:Event):void
		{
			this.dispatchEvent(new Event(Event.SOUND_COMPLETE));
		}
		//----------------------------------------
		public function get totalTime():String
		{
			return this.getSoundTime(this.length);
		}
		public function get isPlaying():Boolean
		{
			return this._isPlaying;
		}
		public function get pan():Number
		{
			return this.channel.soundTransform.pan;
		}
		public function set pan(p:Number):void
		{
			var stf:SoundTransform = this.channel.soundTransform;
			stf.pan = p;
			this.channel.soundTransform = stf;
		}
		public function get volume():Number
		{
			return this.channel.soundTransform.volume;
		}
		public function set volume(v:Number):void
		{
			var stf:SoundTransform = this.channel.soundTransform;
			stf.volume = v;
			this.channel.soundTransform = stf;
		}
		//----------------------------------------
	}
	//----------------------------------------
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -