views:

24

answers:

4

When i tried using a textfield as a button , it seems it is not having the buttonMode property.

So can anyone tell me, how can i programatically create a text button using Action script in a flash project. It should be a simple text, which is clickable.

A: 

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

NH884
A: 

I don't really understand your question! If its a static text, then you can put a LinkButton or if its 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
}
Biroka
is link button control available with flash normally?I know it is there in flex.
Wind Chimez
+1  A: 

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;
}
George Profenza
+2  A: 

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

Amarghosh
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.
Wind Chimez
`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.
Amarghosh