Place a dynamically created text field where clicked
I have a simple drawing program. I want to add a text field wherever the user clicks on the whiteboard. Here is the code
function writeText(e:MouseEvent):void
{
var textfield = new TextField();
board.addChild(textfield);
textfield.x = mouseX;
textfield.y = mouseY;
textfield.defaultTextFormat = textformat;
textfield.setTextFormat(textformat);
textfield.embedFonts = true;
textfield.antiAliasType = AntiAliasType.ADVANCED;
textfield.type = TextFieldType.INPUT;
textfield.autoSize = TextFieldAutoSize.LEFT;
textfield.selectable =false;
textfield.width = 300;
textfield.wordWrap = true;
textfield.textColor = activeColor;
board.focus = textfield;
}
textfield.x = mouseX and textfield.y = mouseY do place a texfield on the screen. But, have to click in two spots to make it work; basically at a x and y location with the y location being lower and to the right of the the x location; clicking any other way has unpredictable results. What am I missing? Thanks, Jon