/* Open a new FLash file (ActionScript 3.0). Select TimeLine --> Top Layer --> Frame 1 Select Window --> Actions (F9) Copy and paste this snippet Observe the stage */ // this cool snippet creates a dynamic button with // text we'll later change programmatically. var bgRed:Shape = new Shape() bgRed.graphics.beginFill( 0xFF0000 ); bgRed.graphics.drawRect( 0, 0, 200, 30 ); bgRed.graphics.endFill(); var bgBlack:Sprite = new Sprite(); bgBlack.graphics.beginFill( 0x000000 ); bgBlack.graphics.drawRect( 0, 0, 200, 30 ); bgBlack.graphics.endFill(); var tf:TextFormat = new TextFormat(); tf.color = 0xFFFFFF; tf.font = "Verdana"; tf.size = 17; tf.align = "center"; var txt:TextField = new TextField(); txt.text = "Snipplr Rocks!"; txt.x = 0; txt.y = 0; txt.width = bgRed.width; txt.height = bgRed.height; txt.setTextFormat( tf ); var mc:MovieClip = new MovieClip(); mc.addChild( bgRed ); mc.addChild( txt ); var btn:SimpleButton = new SimpleButton(); btn.upState = mc; btn.overState = bgBlack; btn.downState = btn.upState; btn.hitTestState = btn.upState; btn.x = stage.stageWidth / 2 - btn.width; btn.y = stage.stageHeight / 2 - btn.height; btn.height; addChild( btn ); addChild( btn ); // http://snipplr.com/view/8980/as3-creating-a-simplebutton-with-dynamic-text/ /* So, let's do a bit of troubleshooting. Does it properly center? Harder to tell with the height, but not too hard with width. How do we fix that? */