ActionScript 3 AS3中的按钮模板类

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3中的按钮模板类相关的知识,希望对你有一定的参考价值。

/*
	
	Author: Alvin Crespo
	Date: 3/1/2010
	
	TemplateButton is a template class for buttons.

*/
package acrespo.classes.templates{
	
	//display
	import flash.display.MovieClip;
	
	//events
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class TemplateButton extends MovieClip{
		
		private var cButtonArea:MovieClip;
		
		public function Button(){ } //Constructor
		
		protected function setClickArea(pButtonArea:MovieClip):void{ initiateClickArea(pButtonArea); }
		
		private function initiateClickArea(pButtonArea:MovieClip):void{
			cButtonArea = pButtonArea;
			cButtonArea.buttonMode = true;
			cButtonArea.addEventListener(MouseEvent.MOUSE_DOWN, buttonDown);
			cButtonArea.addEventListener(MouseEvent.MOUSE_UP, buttonUp);
			cButtonArea.addEventListener(MouseEvent.MOUSE_OVER, buttonOver);
			cButtonArea.addEventListener(MouseEvent.MOUSE_OUT, buttonOut);		
		}
		
		private function buttonDown(e:MouseEvent):void {
			stage.addEventListener(MouseEvent.MOUSE_UP, buttonUp);
			gotoAndStop('down');
		}

		private function buttonUp(e:MouseEvent):void {
			stage.removeEventListener(MouseEvent.MOUSE_UP, buttonUp);
			if (e.currentTarget != cButtonArea) {//onreleaseoutside
				gotoAndStop('normal');
			} else {//onrelease
				buttonUpAction();
			}
		}
		
		protected function buttonUpAction():void{ }
		
		private function buttonOver(e:MouseEvent):void {
			if (e.buttonDown) {//ondragover

			} else {//onrollover
			
			}			 
			gotoAndStop('over');
		}	
		
		private function buttonOut(e:MouseEvent):void {
			//The user is dragging something from the target object
			if (e.buttonDown) {//ondragout
				gotoAndStop('down');
			} else {//onrollout
				gotoAndStop('normal');
			}
		}
		
	}//end of class
}//end of package


/*
	
The Following is how you would extend that class

*/
package acrespo.classes.buttons{
	
	//classes
	import acrespo.classes.templates.TemplateButton;
	import acrespo.classes.MainDocument;
	
	public class UploadFileButton extends TemplateButton{
		
		public function UploadFileButton():void{ 
			setClickArea(buttonarea); //function of parent class TemplateButton
		}
		
		override protected function buttonUpAction():void{
			MainDocument(parent)._FileManager.uploadFiles();
		}//end of buttonUpAction
		
	}//end of class
}//end of package

以上是关于ActionScript 3 AS3中的按钮模板类的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 AS3横幅模板

ActionScript 3 AS3 FlashDevelop新事件模板

ActionScript 3 AS3 FlashDevelop字体库模板

ActionScript 3 AS3按钮链接

ActionScript 3 AS3新文档类

ActionScript 3 AS3 NetConnectShare类