Talk:AS3 example Button: Difference between revisions
Jump to navigation
Jump to search
(Better script -- ~~~~) |
|||
Line 2: | Line 2: | ||
I especially ccreated an account for this. | 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 | 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 this page with this one, but I thought I'd check for approval first. | 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! :-) | So, here it is, please vote or approve! :-) | ||
<source lang=actionscript> | <source lang=actionscript> |
Revision as of 20:36, 19 May 2009
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)