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

setting textfield focus in ActionScript 3.0

New Here ,
Jul 30, 2009 Jul 30, 2009

I am using an event handler to listen for MOUSE_UP on stage_mc to let the user create text and images on the screen. I have buttons above the stage that set a variable, then the variable determines which action occurs with the mouse event.

I would like the user to be able to enter text, and can create an input text field on the stage, but the user then has to click inside the text field to begin typing. Because of the event handler, this 2nd MOUSE_UP repositions the text field, although it IS successful in setting the focus.

Ideally, I would like for the user to be able to create the input text field by clicking on the stage and then begin typing without having to click a 2nd time. It seems simple enough, but I still don't understand OOP enough to decipher the help pages available within the program.

Does anyone have any suggestions? Here is my code (some of the included variable are set in previous lines):

//Setting up the Text Field parameters

    var outputText:TextField = new TextField();
    var textFormat:TextFormat = new TextFormat();


// Enabling the input tools

function startDraw(event:MouseEvent):void {
    if (currentTool.name == "lineTool_mc") {
            newLine.graphics.moveTo(event.localX, event.localY);
            stage_mc.addEventListener(MouseEvent.MOUSE_MOVE, drawLine);  


    } else if (currentTool.name == "textTool_mc") {          
        textFormat.color = 0x336699;
        textFormat.size = 48;
        textFormat.font = "Times";
        outputText.defaultTextFormat = textFormat;
        outputText.selectable = true;
        outputText.x = event.localX;
        outputText.y = event.localY;
        outputText.background = false;
        outputText.border = true;
        outputText.autoSize = TextFieldAutoSize.LEFT;
        outputText.type = TextFieldType.INPUT;
        designContainer.addChild(outputText);
       
    } else if (currentTool.name == "brushTool_mc") { ...

TOPICS
ActionScript
1.3K
Translate
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 30, 2009 Jul 30, 2009

on mouseup or click, if the mouse is down, you can use:

stage.focus=outputText;

if the mouse isn't down, you can don't need a listener to trigger the above.

Translate
Community Expert ,
Jul 30, 2009 Jul 30, 2009

on mouseup or click, if the mouse is down, you can use:

stage.focus=outputText;

if the mouse isn't down, you can don't need a listener to trigger the above.

Translate
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
New Here ,
Jul 30, 2009 Jul 30, 2009

That was too easy. I just don't get it yet. Maybe after a year of these stupid questions OOP will start to make sense to me.

Thanks again.

Translate
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 30, 2009 Jul 30, 2009
LATEST

you're welcome.

Translate
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