问题
When I tried using a textfield as a button, it seems it is not having the buttonMode property.
How can I programatically create a text button using ActionScript in a Flash project. It should be a simple text, which is clickable.
回答1:
You can add the TextField to a Sprite and use it as the button. buttonMode is the property of Sprite class.
If you really want to use just a TextField, you can assign an anchor tag <a href="event:something">label</a> to its htmlText or listen to mouseOver and mouseOut events and show a custom hand cursor after hiding the default mouse pointer using Mouse.hide()
回答2:
You can use a TextField, set the text format as you wish, set selectable to false, etc. If you want the hand cursor, just nest the textfield into a sprite, and set mouseChildren to false.
e.g.
var textButton:Sprite = getTextButton('Push Me!');
addChild(textButton);
textButton.addEventListener(MouseEvent.CLICK, function(event:MouseEvent){trace('click')});
function getTextButton(label:String):Sprite{
var txt:TextField = new TextField();
txt.defaultTextFormat = new TextFormat('Verdana',10,0x000000);
txt.text = label;
txt.autoSize = TextFieldAutoSize.LEFT;
txt.background = txt.border = true;
txt.selectable = false;
var btn:Sprite = new Sprite();
btn.mouseChildren = false;
btn.addChild(txt);
btn.buttonMode = true;
return btn;
}
回答3:
What if you use a button object and style it in the way of a clickable text.
回答4:
I don't really understand your question! If it's a static text, then you can put a LinkButton or if it's a place where user can input text, then add an event listener for the textfield:
myTextField.addEventListener(MouseEvent.CLICK,clickListener);
function clickListener(e:Event):void
{
// if a user clicks the textfield this function will be called
}
来源:https://stackoverflow.com/questions/3084362/how-to-create-a-textbutton-in-flash-using-actionscript-3