/*
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