player.as

来自「Flash AS3 位图处理类」· AS 代码 · 共 76 行

AS
76
字号
package {
	import flash.display.*;
	import flash.events.*;
	public class Player extends Sprite {
		public var currentFrame:int = 1;
		public var totalFrames:int = 0;
		private var rate:int = 2;
		private var timer:int = 0;
		private var playflag:Boolean = true;
		private var mc:Array = new Array();
		
		public function Player():void
		{
			addEventListener(Event.ENTER_FRAME, enterframe);
		}
		
		public function addFrameChild(bitmap:Bitmap):void
		{
			mc.push(bitmap);
			mc[totalFrames].visible=false;
			addChild(mc[totalFrames]);
			totalFrames++;
		}
		
		private function enterframe(e:Event):void
		{
			timer++;
			if(timer==rate)
			{
				timer=0;
			}
			else
			{
				return;
			}
			if(!totalFrames)return;
			var i:int;
			for(i=0;i<totalFrames;i++)
			{
				mc[i].visible=false;
			}
			mc[currentFrame-1].visible=true;
			if(!playflag)return;
			if(currentFrame==totalFrames)
			{
				currentFrame = 1;
			}
			else
			{
				currentFrame++;
			}
		}
		
		public function play():void
		{
			playflag = true;
		}
		
		public function stop():void
		{
			playflag = false;
		}
		
		public function gotoAndPlay(f:int):void
		{
			playflag = true;
			currentFrame=f;
		}
		
		public function gotoAndStop(f:int):void
		{
			playflag = false;
			currentFrame=f;
		}
	}
}

⌨️ 快捷键说明

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