Talk:AS3 example Button

The educational technology and digital learning wiki
Revision as of 21:35, 19 May 2009 by R U Bn (talk | contribs) (Better script -- ~~~~)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Better script -- R U Bn 19:35, 19 May 2009 (UTC)

I especially ccreated an account for this. Thanks to this example I had the inspiration for an even better button and I would like to give bakck with this code. I would like to change this page with this one, but I thought I'd check for approval first. So, here it is, please vote or approve!  :-)

package my {
	
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
		public dynamic class TextButton extends Sprite {
			
			public var label:TextField = new TextField();
			
			public function TextButton(t, pad=0.1, col=0xD4D4D4, alph=0.5) {
				super();
				buttonMode=true;
				label.htmlText = t;
				label.mouseEnabled = false;
				label.autoSize = TextFieldAutoSize.LEFT;
				label.x = label.width*pad;
				label.y = label.height*pad;
				graphics.clear();
				graphics.beginFill(col, alph); // grey color
				graphics.drawRect(0, 0, label.width*(pad*2+1), label.height*(pad*2+1));
				graphics.endFill();
				addChild(label);
			}
		
	}
}

P.S. label.autoSize = TextFieldAutoSize.LEFT; --> this is needed to have a sensable width and height of the textfield (for the auto-hitarea!) R U Bn 19:35, 19 May 2009 (UTC)