package com.flashconnections.ui.component.mediaPlayer { import flash.display.SimpleButton; import flash.display.DisplayObject; import flash.display.Shape; import flash.display.Sprite; import flash.text.TextFormat; import flash.text.TextFormatAlign; import flash.text.TextField; import flash.filters.DropShadowFilter; public class actionscript_video_com_flashconnections_ui_component_mediaPlayer_MediaPlayerButton extends SimpleButton { private static var BUTTON_WIDTH:uint = 100; private static var BUTTON_HEIGHT:uint = 30; private var _label:String; public function get Label ():String { return _label; } public function set Label (val:String):void { _label = val; upState = createState(0xAAAAAA,false); overState = createState(0xCCCCCC,false); downState = createState(0x666666,true); hitTestState = createState(0x000000,false); } public function actionscript_video_com_flashconnections_ui_component_mediaPlayer_MediaPlayerButton(label:String) { Label = label; } private function createState(color:uint,isDownState:Boolean):Sprite { var result:Sprite = new Sprite(); var background:Shape = createButtonBg(color); background.filters = [new DropShadowFilter(4,45,0,.5)]; result.addChild(background); var textField:TextField = createTextField(isDownState); result.addChild(textField); return result; } // Create a rounded rectangle with a specific fill color private function createButtonBg(color:uint):Shape { var result:Shape = new Shape(); result.graphics.lineStyle(2,0x000000); result.graphics.beginFill(color); result.graphics.drawRoundRect(0,0,BUTTON_WIDTH,BUTTON_HEIGHT,25); result.graphics.endFill(); return result; } //Create the text field to display the text of the button private function createTextField(isDownState:Boolean):TextField { var result:TextField = new TextField(); result.text = _label; result.width = BUTTON_WIDTH; result.height = BUTTON_HEIGHT; // Center the text horizontally var format:TextFormat = new TextFormat(); format.align = TextFormatAlign.CENTER format.color = 0xFFFFFF; format.font = 'Arial'; format.bold = true; result.setTextFormat(format); // Center the text vertically result.y = ((BUTTON_HEIGHT-result.textHeight)/2)-2; // The down state places the text down and to the right // further than the other states if (isDownState) { result.x += 1; result.y += 1; } return result; } } }