Talk:AS3 example Button

From EduTech Wiki
Jump to: navigation, search

1 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 back to this community with mycode. I would like to change the code in 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)

1.1 Re: Better script -- Daniel K. Schneider 07:51, 20 May 2009 (UTC)

Hi, thanx for your contribution :) Your code is shorter and more like "just a button" code vs. a strange button that walks around. In order to keep Widget's exaplanations and purpose, I suggest (if you agree) that you might just add another chapter before or after hers and explain your code a bit. This way folks would have two slightly different examples with different purposes and could learn from both. It's always nice to have a general principle illustrated by two variations IMHO - Daniel K. Schneider 07:51, 20 May 2009 (UTC)