/ Published in: ActionScript 3
I wanted to include a dynamic TextField within SimpleButton and found that the process was different compared to how MovieClip works.
Expand |
Embed | Plain Text
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; addChild( btn );
Comments
Subscribe to comments
You need to login to post a comment.

When I attach an Event listener to this and a function it doesn't want to behave as a button and won't work. This is what I have tried testing with:
bgRed.addEventListener(MouseEvent.CLICK, onClicked1); function onClicked1(event):void {var url:String = "http://yahoo.com"; var request:URLRequest = new URLRequest(url); navigateToURL(request, '_blank');}
bgBlack.addEventListener(MouseEvent.CLICK, onClicked2); function onClicked3(event):void {var url:String = "http://yahoo.com"; var request:URLRequest = new URLRequest(url); navigateToURL(request, '_blank');}