2

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.

4 Answers 4

3

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()

Sign up to request clarification or add additional context in comments.

2 Comments

I think this will do. And we need to disable it going to the link upon clicking the link text mentioned in <a> tag also.. right?. Hope that can be handled in event listener.
event: syntax will cause a TextEvent.LINK event to be fired when you click, with something stored in the text property of event. You can handle the event or just ignore it - it shouldn't be a problem.
3

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;
}

Comments

0

What if you use a button object and style it in the way of a clickable text.

Comments

0

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
}

1 Comment

is link button control available with flash normally? I know it is there in flex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.