• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Place a dynamically created text field where clicked

Explorer ,
Jul 11, 2013 Jul 11, 2013

Copy link to clipboard

Copied

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

TOPICS
ActionScript

Views

609

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 11, 2013 Jul 11, 2013

if board has the mouse listener, you should use e.localX and e.localY.

i don't see where you're assigning text or htmlText

you probably want to enable the multiline property of your textfield.

and, you probably want to do something to handle multiple clicks so you have some way to control the created textfields.

Votes

Translate

Translate
Community Expert ,
Jul 11, 2013 Jul 11, 2013

Copy link to clipboard

Copied

if board has the mouse listener, you should use e.localX and e.localY.

i don't see where you're assigning text or htmlText

you probably want to enable the multiline property of your textfield.

and, you probably want to do something to handle multiple clicks so you have some way to control the created textfields.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 12, 2013 Jul 12, 2013

Copy link to clipboard

Copied

Hello kglad,

I used e.localX and e.localY and it solved the strange clicking issue.

I added the multiline property, though for the intended use, it's more or less just dressing.

I have not handled mutiple text field creations because of the intended use. The purpose of the drawing feature is to anoint images under the whiteboard. Typically, the user would type a few words and then draw a line to whatever they are focused on. But, you can never guess just where something will go when it leaves your hands. I do have a reset all button that completely resets the page (I am using class navigation, so is easy to do). I know from testing, the page can get really filled up with visible and invisible (erased) text fields. Not sure even how I could control dynamically created text fields.

I did not assign text because the text field is empty; the user can type in whatever they want to. Is there value to assign empty text to the field, i.e. " " ?

Thanks much, Jon

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2013 Jul 12, 2013

Copy link to clipboard

Copied

LATEST

there's no value to assigning "" to your textfield's text property if that's going to be replaced by user input.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines