cfsoundexample.as

来自「flash强大事件机制扩展类」· AS 代码 · 共 75 行

AS
75
字号
package 
{
	//----------------------------------------
	import flash.net.URLRequest;
	import flash.utils.Timer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	//----------------------------------------
	import AS3.media.CFSound;
	//----------------------------------------
	public class CFSoundExample extends Sprite
	{
		//----------------------------------------
		private var ppx:Number;
		//----------------------------------------
		private var song:CFSound;
		private var base:contentMC;
		private var songTimer:Timer;
		//----------------------------------------
		public function CFSoundExample()
		{
			//----------------------------------------
			this.song = new CFSound(new URLRequest("h:\\mymusic\\秋天不回来 (王强).mp3"));
			this.song.play();
			this.song.addEventListener(Event.SOUND_COMPLETE, this.soundCompleteHandler);
			//
			this.base = new contentMC();
			this.base.x = (stage.stageWidth - this.base.width) / 2;
			this.base.y = (stage.stageHeight - this.base.height) /2;
			this.addChild(base);
			this.ppx = this.base.pp.x;
			//
			this.songTimer = new Timer(1000);
			this.songTimer.addEventListener(TimerEvent.TIMER, this.timerHandler);
			this.songTimer.start();
			//
			this.base.play_btn.addEventListener(MouseEvent.CLICK, this.playHandler);
			this.base.pause_btn.addEventListener(MouseEvent.CLICK, this.pauseHandler);
			this.base.stop_btn.addEventListener(MouseEvent.CLICK, this.stopHandler);
			//
			this.base.ttText.text = this.song.totalTime;
			this.song.setClipTotalTime(this.base.ttClip.c1, this.base.ttClip.c2, this.base.ttClip.s1, this.base.ttClip.s2);
			//----------------------------------------
		}
		//----------------------------------------
		private function timerHandler(evt:TimerEvent):void
		{
			this.base.ptText.text = this.song.getPlayTime();
			this.base.ptTextReduce.text = this.song.getPlayTime(true);
			this.song.setClipPlayTime(this.base.ptClip.c1, this.base.ptClip.c2, this.base.ptClip.s1, this.base.ptClip.s2);
			this.song.setClipPlayTime(this.base.ptClipReduce.c1, this.base.ptClipReduce.c2, this.base.ptClipReduce.s1, this.base.ptClipReduce.s2, true);
			this.base.pp.x = this.ppx + this.song.getPlayPercentage(this.base.ppb.width - 2 - this.base.pp.width);
		}
		private function soundCompleteHandler(evt:Event):void
		{
			this.songTimer.stop();
		}
		private function playHandler(evt:Event):void
		{
			this.song.play();
		}
		private function pauseHandler(evt:Event):void
		{
			this.song.pause();
		}
		private function stopHandler(evt:Event):void
		{
			this.song.stop();
		}
		//----------------------------------------
	}
	//----------------------------------------
}

⌨️ 快捷键说明

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