Setting textfield focus in ActionScript 3.0

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") { ...

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.

Similar Messages

  • How to set  a  focus to a text field when  button is clicked

    [b]in sun stdio creator  setting  a focus is not possible is it a bug
    if  we use  java script
    <ui: button  onClick="focuss(form1:text1)"/>
    function focuss(text1){
        var text=text1;
        text.focus();
    the code is executed but  it is not  working  why[/b]

    Sorry, I didn't read carefully your question. My answer refered to client side only. You can set the focus programmatically with Body.setFocus(). In the appropriate action method or action listener call
    this.body1.setFocus("form1:textField1");
    or maybe
    this.body1.setFocus(this.textField1.getClientId());
    to avoid errors due to changing client ID or save the client ID of the TextField in a private member and call Body.setFocus() in prerender().

  • Can someone explain how to set the focus to a component

    Hello,
    What is the best way to ensure that a component gets the focus with code. I have tried requestFocus and requestFocusInWindow and none of them seems to do there work. The frame containing the components that should get the focus is displayed, the component is focusable so that is not the problem. What I found out is that if the component is deep in a nesting of panes (where the top pane is in the frame) is that calling requestFocus or requestFocusInWindow does not give the component where this focus is called on the focus but either the pane that contains it, one of the parent panes of this pane or one of the components in these panes, in almost all cases the component requesting the focus does not get the focus at all. I always have to write a work around in defining a focus listener for all these panes that transfer the focus back to the component that requested the focus originally, I can't believe that this is the way to ensure that a component has the focus via code. I have searched for documentation but found nothing on what requestFocus(inWindow) is actually dooing (a lot about focus traversibility but I don't want to control this, just make sure that a component gets the focus).
    Again I'm pretty sure that the toplevel window is activated and that the component that requested the focus is focusable (I had created a derived version of the DefaultFocusManager that showed who has focus). Personally I think (and I'm not alone if you do a search in this forum on focus management) that there is either a big problem in the documentation of focus management or that it is still not possible to even try to set the focus on a component in a easy way.
    Marc

    Hello,
    thanks for your reply, here is some example code that illustrates the problem I have (the actual code is to big to show here, which is the raison why I did not posted it here). The code wil create a frame with a JPanel with a JTextField, a 'New' Jbutton and a 'Delete' Jbutton, a tabbed pane in the center ('New' will create a new JPanel, add it to the tabbed pane and set the focus on it, either by calling RequestFocusInWindow() directly or by calling it via InvokeLater (someone on this forum suggested to use this). I changed also the focusmanager to show the component that has the focus when you type something. To test compile and run the program (either with a call to requesteFocusInWindow directly or indirectly (by changing the comments), on my system I get the following behaviour:
    1. requestFocusInWindow called directly
    Start program en type, the tabbed pane has the focus
    Press New and type something, a button has the focus not the created panel
    Press New again and type something, a button has the focus not the created panel
    2. requestFocusInWindow be called indirectly
    Start program and type, the tabbed pane has the focus
    Press New and type, the created panel has the focus (I thought at one moment that I had found the solution there, but alas ...)
    Press New again and type something, a button has again the focus.
    Note that with my real program it is not always a button that will have the focus, sometimes it is a combobox or a TextField (I tried to get this with the example code (the JTextField) but did not succeed.
    Hopes this clarify the problem a little bid, what I want is when the window is visible to set focus on newly created panes (or in the real program on the panel that is selected via the tabbed pane or via a key combination to shift the focus between the panels) but requestFocusInWindow seems to behave unpredicatable. I can't imagine that what I see is a bug so I must make some assumptions which are not valid but I don't see them, btw listening on the WindowListener is I think not the solution because the frame is already displayed when I want to set the focus and I do not use a modal dialog box.
    The example code follows here
    Marc
    * Main.java
    * Created on December 21, 2004, 8:58 AM
    package testfocus;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    * @author marc
    public class Main
    static int counter;
    /** Creates a new instance of Main */
    public Main()
    * @param args the command line arguments
    public static void main(String[] args)
    JFrame frm=new JFrame();
    JPanel content=new JPanel();
    frm.setContentPane(content);
    final JTabbedPane paneContainer=new JTabbedPane();
    JPanel bar=new JPanel();
    JButton create=new JButton(new AbstractAction("New")
    public void actionPerformed(ActionEvent ev)
    counter++;
    final JPanel pnl=new JPanel();
    pnl.setName("test"+counter);
    paneContainer.add(pnl);
    pnl.setFocusable(true);
    pnl.requestFocusInWindow();
    /* Either use this or the previous line
    SwingUtilities.invokeLater(new Runnable()
    public void run()
    pnl.requestFocusInWindow();
    JButton delete=new JButton(new AbstractAction("Delete")
    public void actionPerformed(ActionEvent ev)
    int i=paneContainer.getComponentCount()-1;
    if (i>=0)
    paneContainer.remove(i);
    JTextField dummy=new JTextField("Test");
    bar.add(dummy);
    bar.add(create);
    bar.add(delete);
    content.setLayout(new BorderLayout());
    content.add(bar,BorderLayout.SOUTH);
    content.add(paneContainer,BorderLayout.CENTER);
    frm.setSize(300,400);
    FocusManager.setCurrentManager(new DefaultFocusManager()
    public void processKeyEvent(Component component,KeyEvent ev)
    System.out.println("Focus owner"+getFocusOwner());
    super.processKeyEvent(component,ev);
    frm.setVisible(true);
    }

  • TextField Focus

    Hello there,
    I am new to AS3 and trying to figure out how to set a focus to a textfield on the stage. I found out that if I use
    stage.focus = tf; then the tf get the focus and it does, when I type letters they go directly to this textfield.
    Problems are,
    I don't have a blinking cursor in the textfield.
    I added event listener to catch up when the user press the  ENTER  key but it catches the ENTER key ONLY after I click the textfield with the mouse and having a blinking cursor in that textfield.
    Any idea ?
    regards,

    Are you seeing this behavior in the testing environment or when you put the flash into an html page?
    In the testing environment you might want to go to the Control menu and select Disable keyboard shortcuts. That will give you a better representation of how things will actually work when they are standing on their own.
    Also there is some kind of issue around setting the focus. The swf object has to have already received a click before it can set the blinking I-beam into an input text field. It is a "security" type of thing. To prevent a malicious swf from looking like some kind of interactive password field and grabbing someone's password or the like.
    Depending upon what you are doing you can have a "Start" button or something to make sure that the user has clicked the flash before flash can be able to set the focus.

  • Textfield-focus within a tabbedpane

    Hi all,
    I have the following focus-problem.
    I have a tabbed-pane with 4-register-cards. First I'm intit the first at last the fourth.
    Now I want that a text-field on the first register-card have the focus. I try it to do it this way:
    public void stateChanged(ChangeEvent event) {
         if (tabbedPane.getSelectedIndex()==3) {
              if (textFieldUser!=null){
                   textFieldUser.setText(" This text-output works well ! ");
                   textFieldUser.requestFocus();
    Now the textfield display the output-text, but the field themselves have no focus?
    If I click on the tab No 2 and go back to No. 1 the field have the focus in the way that I want !?

    Archana1604 wrote:
    You need not use requestFocusInWindow to set the focus for a component. You can simple use requestFocus() inorder to set the focus.Please read the API and don't post bad advice.
    JComponent#requestFocus
    Note that the use of this method is discouraged because its behavior is platform dependent. Instead we recommend the use of requestFocusInWindow(). If you would like more information on focus, see [How to Use the Focus Subsystem|http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html], a section in The Java Tutorial.
    db

  • How can I set the focus to a field on a Portal form?

    Can anyone tell me if it is possible to set the focus to a particular field on a form which was created in Portal and is based on a PL/SQL procedure?
    The form contains a mixture of field types and also takes parameters from another form and displyas them.
    I have managed to set the focus on a form which is defined dirdctly in a PL/SQL procedure, using Javascript, but this doesn't seem to work for a Portal form.

    Hi,
    look at the discussion on May 25:th 2001, subject "How to get the cursor into a specific field", it might give you an idea.
    To give you some hint right now:
    In the "Additional PL/SQL Code" tab, "Before displaying the page", add following code:
    htp.p('<BODY onLoad="document.forms[0].elements[6].focus();">');
    forms[0] if you only have 1 form, and elements[the number of the item you want to be in focus]
    I hope this could help you
    /Sara

  • How to set the focus to a first element in oracle apex 3.2.1  and 3.1.2.00

    Hello ,
    I am using oracle apex 3.2.1 in development env. How to set the focus to a first element of a page.
    thanks/mahesh

    Hi,
    This might help
    http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/bldr_pgs.htm#CJGJDHCI
    Find "Cursor Focus" from page Display Attributes
    Br,Jari

  • How to set the focus on the new added line in ALV list (OO)

    Dear Friends,
    I have an ALV list based on OO(using alv_grid->set_table_for_first_display), when I click the 'new' button to add a new line, the mouse arrow is always pointing to the first line - not the new created line for user to input!!.
    So how to set the focus (mouse arrow) on the new added line in ALV list for user to input it friendly?
    Thanks a lot!!

    Hello,
    To get the selected line row first we have get all the rows in the internal table.
    When u click on the button when it is creating the new line we have to pass the row number to the call method
    CALL METHOD <ref.var. to CL_GUI_ALV_GRID > ->get_selected_rows
       IMPORTING
          ET_INDEX_ROWS  =   <internal table of type LVC_T_ROW > (obsolete)
          ET_ROW_NO      =   <internal table of type LVC_T_ROID > .
    CALL METHOD<ref.var. to CL_GUI_ALV_GRID>->set_selected_rows
       EXPORTING
          IT_ROW_NO  =  <internal table of type LVC_T_ROID>
       or alternatively
       IT_INDEX_ROWS  =  <internal table of type LVC_T_ROW>
          IS_KEEP_OTHER_SELECTIONS  =  <type CHAR01>.
    http://help.sap.com/saphelp_erp2004/helpdata/EN/22/a3f5ecd2fe11d2b467006094192fe3/content.htm

  • How to set the focus to the tabbed pane title?

    Dear Friends,
    I'm using tabbed pane (JTabbedPane) in my application. I have 2 tabbed panes and each contain some text fields and buttons.
    In first tabbed, I have 2 text fields, OK and Cancel buttons. I have to set the focus to the title of the tabbed pane after it lost focus from the Cancel button (focus has to move from Cancel button to tabbed pane title by pressing tab key).
    Could anyone please tell me how to set the focus to the tabbed pane title?
    Thanks in advance,
    Sathish kumar D

    Thanks for your reply.
    Could you please tell me how to set focus for title of the tabbed pane throug FocusTraversalPolicy?
    because usually we set the focus for the component by requestFocusInWindow().
    for example set focust to the button OK,
    btnOk.requestFocusInWindow()likewise could you tell me how to set focus to Title of the tabbed pane?
    Sathish kumar D

  • Setting the focus in HTREE

    Hi guys!
    I have created the tree in the form 6i. it is populated with the employee names. Then attached a horizontal toolbar canvas with the main form and the horizontal tool bar canvas contain a text item and a search button. When I find the name of the emplyee it finds it but how can i set the focus. An early response is appreciated. regards.

    Try FTREE.SET_TREE_SELECTION(tree, node, FTREE.SELECT_ON)

  • Last Q: How to set a focus to a specific text area

    Hi, I've got a seemingly simple question, which has turned out to be another real stumper of a problem.
    I've got a textpane and a textarea on a panel, which gets displayed when the user presses a button. I want the cursor to be set on the textarea as soon as it is loaded. I've tried the following methods with no luck;
    txtArea.requestFocusInWindow();
    How do I set the focus onto the textarea rather than the textpane.
    Thanks

    try this ..
    this is setting the focus to a specific editbox within a Jframe
    ok
    add this to the jbInit method :
    contentPane.addFocusListener(new java.awt.event.FocusAdapter()
    public void focusGained(FocusEvent e)
    contentPane_focusGained(e);
    then add this as a seperate method to your JFrame
    void contentPane_focusGained(FocusEvent e)
    jTextEIN.requestFocus(); // jTextEIN is just the name of the component to be focused
    Boris the fly

  • How I set the Focus in object

    Hello.
    I need set the focus on first object in a JInternalFrame.
    The form JInternalFrame contain a JTabbedPanel and this include object jFormatedTextFields.
    I need when the init form set the focus over first object in the first tab of JTabbedPanel. How I do?.
    Than You

    works OK in this
    (tabbed panes seem to be working OK for focus now, don't know what's changed)
    import javax.swing.*;
    import java.awt.*;
    import  javax.swing.text.*;
    class Testing extends JFrame
      MaskFormatter mf;
      JFormattedTextField ftf;
      public Testing()
        setLocation(300,200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        try{mf = new  MaskFormatter("###.###.##.##");}
        catch(Exception e){e.printStackTrace();}
        ftf = new JFormattedTextField(mf);
        JTabbedPane tp = new JTabbedPane();
        tp.addTab("A",ftf);
        JDesktopPane dp = new JDesktopPane();
        JInternalFrame if1 = new JInternalFrame( "I-F1", true, true, true, true );
        if1.setLocation(50,50);
        if1.getContentPane().add(tp);
        if1.pack();
        if1.setVisible(true);
        dp.add(if1);
        getContentPane().add(dp);
        setSize(400,300);
        setVisible(true);
        ftf.requestFocusInWindow();
      public static void main(String[] args){new Testing();}
    }

  • Metoh refresh_table_display will set the focus to the first cell

    metoh refresh_table_display will set the focus to the first cell,how i can set it back to the position before
    refresh.
    thanks.
    Message was edited by: W C

    Hi,
    The method REFRESH_TABLE_DISPLAY has the parameters, IS_STABLE. Set both ROW / COL parameters of IS_STABLE to 'X'.
    Then when you refresh the display will not shake.
    Regards,
    Ravi
    Note : Please close the thread if answered

  • Set Field Focus After Data Entry Error

    In a form created in Acrobat XI Pro (and distrubuted via Forms Central), I have various form fields (text, date, etc.). When the user performs a data entry error (e.g. incorrect date format based on date mask, etc.), the field focus is lost. The user must mouse-click into the field to set the field focus and re-enter their data. Is there any code that allows the app to return an error and set the focus back on the field returnign the error? Thanks / Todd

    If you converted the PDF to a FormsCentral form then it's a FC issue, not a PDF issue...

  • Set default focus on pushbutton (dynpro not ALV)

    Dear all
    I created a popup showing a table control and 2 buttons (confirm / abort).
    The user simply wants to push the confirm button to proceed by pressing enter but unfortunatly I see no way to set the focus on that element by default.
    Any help is appreciated.
    Thank's in advance and best regards
    Benno

    Use this in PBO:
    * BUT_CONF is the button for the Confirm
    SET CURSOR FIELD 'BUT_CONF'
    Regards,
    Naimesh Patel

Maybe you are looking for