# Can textfields be used as buttons?

**URL:** <https://forum.kirupa.com/t/can-textfields-be-used-as-buttons/248411>\
**Category:** Uncategorized\
**Created:** [January 8, 2008, 12:34am UTC](https://forum.kirupa.com/t/can-textfields-be-used-as-buttons/248411 "2008-01-08T00:34:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pixel\_streamer](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@pixel\_streamer](https://forum.kirupa.com/u/pixel_streamer)\
**Post date:** [January 8, 2008, 12:34am UTC](https://forum.kirupa.com/t/can-textfields-be-used-as-buttons/248411/1 "2008-01-08T00:34:31Z")

</div>

I’m trying to code a simple menu using textfields as buttons. As is, the code below traces with the onSetFocus event, but I can’t get the textfields to respond to regular “button” events like onRelease. Is this expected? Can someone tell me what I’m missing?

Thanks for any help.  
-pixel\_streamer

import flash.display.BitmapData;  
import flash.geom.Rectangle;  
import flash.geom.Matrix;  
import flash.geom.ColorTransform;

var txtFormat:TextFormat = new TextFormat();  
var children:Array = null;  
this.createEmptyMovieClip(“bg”, this.getNextHighestDepth());  
this.createEmptyMovieClip(“contents”, this.getNextHighestDepth());  
//MovieClip bg;  
// Create a new XML object.  
var menuXml:XML = new XML();  
// Set the ignoreWhite property to true (default value is false).  
menuXml.ignoreWhite = true;  
// After loading is complete, trace the XML object.  
menuXml.onLoad = function(success) {  
children = menuXml.firstChild.childNodes;  
//var txtFormat:TextFormat = new TextFormat();  
txtFormat.color = 0xFFFFFF;  
[//txtFormat.bold=true](https://txtFormat.bold=true);  
txtFormat.align = “center”;  
txtFormat.size = 12;  
txtFormat.font = “Artist\_Choice”;  
for (var i = 0; i \< children.length; i++) {  
var indLabel:String = String(children\*.attributes.label);  
var btnlabel:String = String(“choices” + i);  
contents.createTextField(String(“choices” + i), contents.getNextHighestDepth(), Number((93 \* i) + 10), 8, 80, 20);  
contents[btnlabel].embedFonts = true;  
contents[btnlabel].multiline = true;  
contents[btnlabel].wordWrap = true;  
contents[btnlabel].autoSize = “right”;  
//contents[btnlabel].selectable = false;  
contents[btnlabel].antiAliasType = “advanced”;  
contents[btnlabel].gridFitType = “pixel”;  
contents[btnlabel].border = true;  
contents[btnlabel].background = true;  
contents[btnlabel].backgroundColor = 0x2F8033;  
// the text below should work well for just about any vector text. (thickness -50, sharpness 150, antialiastype adv)  
// the text below should work well for hamiltons bitmapped text. (thickness -55, sharpness 200, antialiastype adv, bold should be active in the library)  
//thickness is from -200 to 200  
contents[btnlabel].thickness = -50;  
//sharpness is from -400 to 400  
contents[btnlabel].sharpness = 150;  
contents[btnlabel].type = “dynamic”;  
contents[btnlabel].text = indLabel;  
contents[btnlabel].setTextFormat(txtFormat);  
/_contents[btnlabel].onRelease = function():Void {  
trace("CLICKED ON : " + this);  
};_/  
contents[btnlabel].onSetFocus = function():Void {  
trace("CLICKED ON : " + this);  
};  
}  
};  
// Load the XML object.  
menuXml.load(“menu.xml”);
