// Class ButtonPictureBox created by Alon Farchy. // Creates a square button with a bitmap in it. package code.buttons { import flash.display.MovieClip; import flash.display.Bitmap; import flash.display.BitmapData; import flash.events.MouseEvent; import flash.text.TextField; import flash.text.TextFormat; //Note: Uses library graphic PictureBoxSkin to build border around bitmap. public class ButtonPictureBox extends ButtonClass { //vars private var btnPicture:Bitmap = new Bitmap(); private var btnLabel:String = ""; //const. btnName = text under button. picture = supplied bitmap. public function ButtonPictureBox(btnName:String,picture:BitmapData):void { btnLabel = btnName; btnPicture.bitmapData = picture; drawBtn(drawSkin()); } //Draw it! protected function drawSkin():MovieClip { //Create MovieClip var btnSkinTemp:MovieClip = new MovieClip(); //Draw Graphics var frame:PictureBoxSkin = new PictureBoxSkin; frame.stop(); frame.x = frame.width/2; frame.y = frame.height/2; //Add Picture btnPicture.x = -frame.pictureArea.width/2; btnPicture.y = -frame.pictureArea.height/2; btnPicture.width = frame.pictureArea.width; btnPicture.height = frame.pictureArea.height; btnPicture.mask = frame.pictureArea; frame.addChild(btnPicture); //Create TextFormat var btnLabelFormat:TextFormat = new TextFormat(); with(btnLabelFormat) { font = "Arial"; bold = true; color = 0x000000; size = 12; } //Create TextField var btnLabelField:TextField = new TextField(); btnLabelField.defaultTextFormat = btnLabelFormat; btnLabelField.selectable = false; btnLabelField.embedFonts = true; btnLabelField.text = btnLabel; btnLabelField.width = btnLabelField.textWidth+10; btnLabelField.height = btnLabelField.textHeight; btnLabelField.y = frame.height+10; btnLabelField.mouseEnabled = false; changeArea = frame; //Add Children btnSkinTemp.addChild(frame); btnSkinTemp.addChild(btnLabelField); //Fix Size scaleX = 1; scaleY = 1; //Return Skin return btnSkinTemp; } //Override Button Commands to make button grow and shrink. override protected function mouseClickHandler(event:MouseEvent) { changeArea.gotoAndStop("over"); changeArea.scaleX = 1.10; changeArea.scaleY = 1.10; } override protected function mouseOverHandler(event:MouseEvent) { changeArea.gotoAndStop("over"); changeArea.scaleX = 1.10; changeArea.scaleY = 1.10; } override protected function mouseDownHandler(event:MouseEvent) { changeArea.gotoAndStop("down"); changeArea.scaleX = 1; changeArea.scaleY = 1; } override protected function mouseOutHandler(event:MouseEvent) { changeArea.gotoAndStop("up"); changeArea.scaleX = 1; changeArea.scaleY = 1; } } }