package be.nascom.flash10_tests.widgets{ import flash.display.SimpleButton; import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFormat; public class graphic_player_10_cube_be_nascom_flash10_tests_widgets_CubeSideMaterial extends SimpleButton{ protected var _side_width:Number; protected var _side_height:Number; protected var _half_width:int; protected var _half_height:int; protected var _use_set_color:Boolean; protected var _up_color:uint; protected var _over_color:uint; protected var _down_color:uint; public function graphic_player_10_cube_be_nascom_flash10_tests_widgets_CubeSideMaterial(w:uint,h:uint,side_id:uint,use_set_color:Boolean=false,up_color:uint=0xFFFFFF,over_color:uint=0xBBBBFF,down_color:uint=0x7777FF){ super(); _side_width=w; _side_height=h; _half_width=Math.round(-w/2); _half_height=Math.round(-h/2); _use_set_color=use_set_color; _up_color=up_color; _over_color=over_color; _down_color=down_color; render(w,h,side_id); trace("graphic_player_10_cube_be_nascom_flash10_tests_widgets_CubeSideMaterial(w:"+w+",h:"+h+", side_id:"+side_id+")"); } public function render(w:uint,h:uint,side_id:uint):void{ this.upState=createMaterialState(w,h,_use_set_color ? _up_color : Math.random()*0xFFFFFF,String(side_id)); this.overState=createMaterialState(w,h,_use_set_color ? _over_color : Math.random()*0xFFFFFF,String(side_id)); this.downState=createMaterialState(w,h,_use_set_color ? _down_color : Math.random()*0xFFFFFF,String(side_id)); this.hitTestState=createMaterialState(w,h,0xFFFFFF,String(side_id)); this.useHandCursor=true; } public function createMaterialState(w:uint,h:uint,color:uint,material_label:String):Sprite{ var s:Sprite=new Sprite(); s.graphics.beginFill(color,1); s.graphics.drawRect(_half_width,_half_height,w,h); s.graphics.endFill(); var tf:TextField=new TextField(); tf.selectable=false; var tform:TextFormat=new TextFormat(); tform.size=Math.round(_side_width/4); tform.font="Verdana"; tform.bold=true; tf.text=String(material_label); tf.setTextFormat(tform); s.addChild(tf); return s; } } }