package
{
	import mx.controls.Button;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.AntiAliasType;
	import flash.text.TextFormat;
	import flash.display.BitmapData;
	import flash.display.Bitmap;
	import mx.core.UITextField;
	import mx.events.FlexEvent;
	import flash.events.MouseEvent;

	public class RotationButton extends Button
	{
		public function RotationButton()
		{
			super();
			this.addEventListener( FlexEvent.CREATION_COMPLETE, onInit );
		}
		
		private function onInit( event:FlexEvent ):void
		{
			this.label = super.label;
		}
		
		override public function set label(value:String):void
		{
			super.label = value;
			setRotationLabel();
		}
		
		override public function set rotation(value:Number):void
		{
			super.rotation = value;
			setRotationLabel();
		}
		
		private function setRotationLabel():void
		{
			var tf:UITextField = super.textField;
			if( null == tf ) return;

			var bmp:Bitmap;	
			bmp = Bitmap( this.getChildByName( "bitmapLabel" ) );
			if( null != bmp) 
			{
				bmp.bitmapData.dispose();
				this.removeChild( bmp );
			}			
			var bmpData:BitmapData = new BitmapData( tf.width, tf.height, true, 0x00CCCCCC );
			bmpData.draw( tf );
			
			bmp = new Bitmap( bmpData, "auto", false );
			bmp.smoothing = true;
			bmp.name = "bitmapLabel";
			bmp.x = this.width/2 - tf.width/2;
			bmp.y = this.height/2 - tf.height/2;
			this.addChild( bmp );
		}
	}
}