package { // adapted from Bill Sanders, ActionScript 3.0 Programming, O Reilly Short Cuts, 2007, p 42. import flash.display.SimpleButton; public class MyButton extends SimpleButton { public function MyButton(txt:String,upColor:uint,downColor:uint,overColor:uint){ upState = new BtnState(upColor,txt); downState = new BtnState(downColor,txt); overState = new BtnState(overColor,txt); hitTestState = upState; useHandCursor = true; } public function setText(txt:String){ (upState as BtnState).setText(txt); (downState as BtnState).setText(txt); (overState as BtnState).setText(txt); } } } // classe interne qui ne doit pas faire partie du package... import flash.display.Sprite; import flash.display.Shape; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; // exemple adapté de Bill Sanders, ActionScript 3.0 Programming, O Reilly Short Cuts, 2007, p 42. class BtnState extends Sprite { var btnLabel:TextField; var bkGround:Shape; var color:uint; public function BtnState(color:uint, btnLabelText:String):void { this.color=color; btnLabel = new TextField(); btnLabel.autoSize=TextFieldAutoSize.LEFT; // formatage du texte btnLabel.defaultTextFormat=new TextFormat("Verdana",30); // fond du bouton bkGround=new Shape(); setText(btnLabelText); addChild(bkGround); addChild(btnLabel); } public function setText(txt:String):void{ btnLabel.text=txt; with (bkGround.graphics){ clear() beginFill(color); lineStyle(2,0x000000); drawRoundRect(-5,0,btnLabel.textWidth+15,btnLabel.textHeight+10,10); } } }