Setting the focus problem - stadium is null?

I'm trying to programmatically set the development of a textinput, however the debugger throws me this error:

Cannot access a property or method of a null object reference.

I'm trying to set the focus with this line

stage.focus = input

For reference, here's a bit of the code

package views
{
    import flash.display.GradientType;
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.events.MouseEvent;
    import flash.events.TouchEvent;
    import flash.geom.Matrix;
    import flash.text.TextFormat;
    import flash.text.TextFormatAlign;

    import qnx.input.IMFConnection;
    import qnx.ui.buttons.LabelButton;
    import qnx.ui.core.UIComponent;
    import qnx.ui.display.Image;
    import qnx.ui.text.Label;
    import qnx.ui.text.TextInput;

    public class RenamePopupContainer extends UIComponent
    {
        private var input:TextInput;
        private var file:String;

        public function RenamePopupContainer(_file:String)
        {
            super();
            file = _file;
            setSize(1024, 600);
            setPosition(0, 0);
            createChildren();

            IMFConnection.imfConnection.showInput();
            stage.focus = input;
        }

        private function createChildren():void
        {
            var labelFormat:TextFormat = new TextFormat();
            labelFormat.color = 0xFFFFFF;
            labelFormat.size = 28;
            labelFormat.align = TextFormatAlign.CENTER;

            var mat:Matrix = new Matrix();
            mat.createGradientBox(400, 1);

            var line1:Shape = new Shape();
            line1.x = 312;
            line1.y = 92;
            line1.graphics.beginGradientFill(GradientType.LINEAR, [0xeeeeee, 0xeeeeee, 0xeeeeee], [0, 1, 0], [0, 127, 255], mat);
            line1.graphics.drawRect(0, 0, 400, 1);
            line1.graphics.endFill();
            addChild(line1);

            var label:Label = new Label();
            label.text = "Rename to?";
            label.setSize(450, 40);
            label.setPosition(287, 43);
            label.format = labelFormat;
            addChild(label);

            input = new TextInput();
            input.setSize(380, 40);
            input.setPosition(322, 120);
            input.text = file;
            addChild(input);

            var line2:Shape = new Shape();
            line2.x = 312;
            line2.y = 190;
            line2.graphics.beginGradientFill(GradientType.LINEAR, [0xeeeeee, 0xeeeeee, 0xeeeeee], [0, 1, 0], [0, 127, 255], mat);
            line2.graphics.drawRect(0, 0, 400, 1);
            line2.graphics.endFill();
            addChild(line2);

            var btnOk:LabelButton = new LabelButton();
            btnOk.setSize(120, 40);
            btnOk.setPosition(384, 210);
            btnOk.label = "Ok";
            btnOk.addEventListener(MouseEvent.CLICK, ok);
            addChild(btnOk);

            var btnCancel:LabelButton = new LabelButton();
            btnCancel.setSize(120, 40);
            btnCancel.setPosition(519, 210);
            btnCancel.label = "Cancel";
            btnCancel.addEventListener(MouseEvent.CLICK, cancel);
            addChild(btnCancel);
        }
    }
}

This is a fairly common problem: placement of a DisplayObject property has the value NULL until it has been added to the display list.  There are a few solutions, but the easiest for you would be, if this object never will be added to the display list once.

// in place of your existing stage.focus line
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

...

private function onAddedToStage(e:Event):void {
    removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    stage.focus = input;
}

Tags: BlackBerry Developers

Similar Questions

  • How to set the focus on the field?

    This is my screen:

    image //add by function (thread)

    RichText //add by function (thread)

    button_next //add by function (thread)

    button_back //add directly on-screen

    I already manage the display as above

    but my problem is the firsttime I get my screen is my focusable on button_back.

    I want to set the focus on image when I get the screen.

    no idea what I need to do?

    they are all put under the focus name, I just don't want to when I go to the screen, focus on button_back

    your back button is added directly to the screen

    and the rest are added by the threads,

    so son take some time to complete that work and until then the button "return" is added

    all your work, once you can do--

    image. SetFocus();

    and you will get the focus on the desired position

  • How to set the focus after initialization?

    Problem: I have a problem affecting a new text field to the development after its initialization.

    Background: I've created a form with a table that creates a new line after leaving the last cell/textfield in the last line if necessary. Once I get the label off the last field, emphasis is more completely - that is to say, tab does not reach any other part of the form.

    Tests: I tried to set the focus on the first field of the new line to the help text (rowNum is a variable for the newly created line)

    xfa.host.setFocus (".form1 form [0] of xfa [0] [0].") #subform [0]. Subform2 [0]. Table 1 [0]. Row1 [rowNum]. TextField1 [0] ");"

    and

    this.parent.parent.Row1 [rowNum]. TextField1.setFocus ();

    I also tried to set the focus to the last field that I had left with just

    xfa.host.setFocus ("this");

    Also, I tried to use of the generator of the action to restore the focus to the textfield object newly created when it is initialized.

    [edit] I forgot to say that the attempt to set the focus to the last field that I had left just actually worked. [/ Edit]

    Post edited by: jasotastic81

    Looks like you used the variable a literal string... must concatenate the value of the variable in the expression of SOM:

    xfa.host.setFocus (".form1 form [0] of xfa [0] [0].") #subform [0]. Subform2 [0]. Le1 tab [0]. Row1 ["+ rowNum + '"]. TextField1 [0] ");"

    Note the name of two + around the variable to its value with the rest of the chain.

    Let us know if that helps.

    -Scott

  • Set the focus to the text box of the embedded NumericStepper control

    I have an application that requires I use NumericStepper edit control as ItemEditor of a DataGrid column.

    I have two problems that I can't seem to overcome, one being the result of the solution to another:

    (1) I need to instantiate the component NumericStepper during execution, because I don't ' know advance what columns it will require.  More important still, I need to specify default attributes (styles, min, max, width, etc.).  I can't understand how to specify these attributes other than in a .mxml file.  To handle this, I have crreated a component 'wrapper' that's an HBox with a NumericStepper inside her, and I can specify my attributes on the tag NumericStepper.

    (2) now that I did #1 above, although, when I click a DataGrid cell that uses this component editing, the editor comes back but the text box is NOT centered, which means that the user must click a second time if he wants to type a number.  It's very irritating, but I do not know how to manage the focus such as when my HBox-with-embedded-NumericStepper' control rises, it concentrates and its selected data, NumericStepper, just as the 'base' is.

    So, my questions are:

    (1) can I somehow assign property values to a standard when executing NumericStepper, so that I can avoid using my built-in custom control HBox?

    (2) how can I manage the focus so that when my control HBox is in place, the text box is selected and fucused?

    That sounds confusing, but I have a small program to demonstrate this.  The "QtyBad" column uses my own NumericStepper HBos-based and not to be put in the correct focus when activated.  The "QtyGood" column has demonstrated APPROPRIATE behavior, as exposed by the native NumericStepper component, but I can't specify additional attributes / s on this subject.

    Here are all of the program - called "DGNumStepperDemo" - here:

    DGNumStepperDemo.mxml

    <? XML version = "1.0" encoding = "utf-8"? >
    " < = xmlns:mx mx:Application ' http://www.Adobe.com/2006/MXML "layout ="absolute"creationComplete =" onInitialize () "> "
    < mx:Script source = "DGNumStepperDemo.as" / >
    < mx:DataGrid id = "dg1" editable = "true" top = "20" left = "20" width = "350" height = "124" >
    < / mx:DataGrid >
    < / mx:Application >

    DGNumStepperDemo.as


    ActionScript file
    Import mx.collections.ArrayCollection;
    Import mx.controls.DataGrid;
    Import mx.controls.dataGridClasses.DataGridColumn;
    //---------------------------------------------------------------------------------------- -------
    [bindable]
    private var gridData:ArrayCollection = new ArrayCollection([{Qty:0},{Qty:5},{Qty:10}]);

    private function onInitialize (): void
    {
    CDL of the var: Array = new Array();
    var dgc:DataGridColumn;

    DGC = new DataGridColumn ("QtyBad");
    dgc.dataField = "Qty";
    DGC. Width = 75;
    dgc.itemEditor = new ClassFactory (EditorDGNumericStepper);
    dgc.editorDataField = "value";
    cols.push (DGC);

    DGC = new DataGridColumn ("QtyGood");
    dgc.dataField = "Qty";
    DGC. Width = 75;
    dgc.itemEditor = new ClassFactory (mx.controls.NumericStepper);

    dgc.editorDataField = "value";
    cols.push (DGC);

    DG1. Columns = cols;
    DG1. DataProvider = gridData;
    }

    EditorDGNumericStepper.mxml

    <? XML version = "1.0" encoding = "utf-8"? >
    " < = xmlns:mx mx:HBox ' http://www.Adobe.com/2006/MXML ""4"verticalAlign ="middle"paddingRight ="4"paddingLeft = verticalScrollPolicy ="off"horizontalScrollPolicy ="off"> "
    < mx:Script >
    <! [CDATA]
    public function get value(): number {return itemQuantity.value ;}
    []] >
    < / mx:Script >
    < mx:NumericStepper id = "itemQuantity" value = "{data.". Qty}"minimum maximum ="0"="100"/ >
    < / mx:HBox >

    If anyone who bothers to run it, you can see what I mean about the focus problem in the QtyGood and QtyBad columns.

    Any help is appreciated!

    Quick response to the #2 is to change the EditorDGNumericStepper.mxml to the following:

    
    http://www.adobe.com/2006/mxml"
               verticalAlign="middle" paddingRight="4" paddingLeft="4"
               verticalScrollPolicy="off" horizontalScrollPolicy="off"
               creationComplete="focusManager.setFocus(itemQuantity)">
         
              
         
         
    
    

    The only thing I did was put the NumericStepper to 100% width so it fills the column like the standard NumericStepper and it looks a bit better and I added a creation complete event handler that sets the focus to the NumericStepper.  I tested it and it will be emphasis each time on it like a standard stepper.  There may be a more "preferred" way, but it's simple and effective.

    On the #1 question, you want to change the properties, styles, etc. of a NumericStepper standard once it has been added to the data grid?

  • How to avoid the focus problem when browsing via browser back button

    Hello

    I am facing a problem in setting focus on the buttons.
    Please see application: http://apex.oracle.com/pls/otn/f?p=47869:2

    login details:
    Workspace: vsanthanam
    user: vijay
    PSWD: apex_demo

    In this application, I have 2 pages.
    #2 has the "submit" button
    Page no. 3 contains the Cancel button

    The two buttons are basic HTML and can be accessed using access key ALT + s and ALT + c.

    The problem is:
    When I go back to the previous page (pgid #2) of the application using back button of the browser pgid IE #3.
    due to the onFocus event located in the button "submit", control returns to pgid #3.

    Is there a possible way to set the focus to other elements. so that whenever IE brower back button, application would stay in
    page #2.


    I took approaches:
    -------------------------
    If we use onclick, onfocus instead and then the problem remains because we have onfocus = "this.click (); in equipping the Accesskey.
    Another way is onKeyup event. If we use onKeyup, we can avoid this browser back problem, but disappears from the access keys functions.

    Pointers on this would be a great help.

    Thank you very much
    -Vijay

    PLEASE NOTE: I have created intentionally two buttons on each page. It is necessary to have HTML buttons with the key features of access,
    otherwise application gives a few flaws in HTML accesskey.

    Hi Vijay,

    Crikey, aren't annoying browsers! It took a while to get out, but I've updated your SUBMIT1 button attributes:

    class="t20Button" AccessKey="s" tabindex="-1" onclick="javascript:this.blur();doSubmit('SUBMIT1');" onfocus="javascript:this.blur();doSubmit('SUBMIT1');"
    

    Note that I removed the spare semicolons you after each attribute - these are only required in javascript code.

    The important point to note are the statements of "this.blur" () - this tells the browser to move away from the current item to the next. On your page, only for this purpose, I have added a text element of Temp - I am assuming that your actual page will have at least one other element on the page that will accept the focus? Everything gets focus of the call "this.blur ()", should be the element with focus when the Back button is used.

    Andy

  • Satellite C660 - how to set the focus of the webcam?

    Hello

    Just bought this laptop, the built-in webcam looks very blurry when I use Skype. Does anyone know how to set the focus to the subject?

    See you soon
    Jules

    Hello

    to be honest, I have no idea on your model of lap... Try to update driver webcamd and play with Skype video settings.

  • Setting the focus to a specific index

    Let's say I'm a manager of vertical field with 5 buttons fields. Is it possible to move the focus to a specific field click?

    For example, clicking on the 2nd button will move the focus to the 4th button. Possible?

    Yes, you can set the focus...

    Try this...

    ' Public Sub fieldChanged (field field, int context)
    {
    If (MyButtonField instanceof Field)
    {
    If (Field == VFM.getField (1))
    {
    (VFM.getField (0)) .setFocus () (ButtonField);
    }
    }
    }

    This will focus on the ground in the 1st row on the click event of the button 2nd...

    Similarly, you can write changeListner event for all fields.

  • How to set the focus to textfield

    Hello everyone.

    Need advice on how to set the focus to textfield. I tried t use setfocus, however does not

    Thank you!

    textField.requestFocus ();

  • Setting the focus to textfield - cannot type

    I'm trying to use a MouseEvent.CLICK event to set the focus to a TLFTextField and let the user type:

    var textField:TLFTextField = menuField.getTextField ();

    textField.stage.focus = textField;

    textField.setSelection (0,0);

    However, when this code executes, the cursor appears in the textfield, but the user cannot type. What can I do to fix this? A more detailed description below:

    I am applying that has many fields, that the user must fill. The fields are generated dynamically and not always the same number, so I made a movieclip called now and wrote a class so he could manage the feature.

    Now has two areas of text, which are TLFTextFields to the inside of the container MovieClips. The first region, lblFieldName, is the label of the field (for example "name:"). The second is the editable text area lblFieldValue the TLFTextFields are inside containers because I found if I tried to put the lblFieldNametext of now 's manufacturer, it would reset immediately (TextFields are apparently not intitialized until the manufacturer of their parent is over...)

    The size and position of lblFieldValue is defined dynamically depending on the size of lblFieldName. The text in lblFieldValue begins in white until the user enters something. Unfortunately, regardless of the width of the textfield, if the text is empty the user select the textfield by clicking the left edge of it, which is completely unrealistic. My solution has been to add a mouse CLICK event to the set now and try to set the focus to the lblFieldValue TextField. But once again, when the previous code is running it places the cursor but does not allow the user to type. I don't know that I'm missing something simple. Any suggestions?

    Problematic are tlf textfields.  unless you have a good reason to use them, you must use classic text.

  • How to set the focus

    Hai

    Say like page of connection in onload, the cursor should focus in the box, how to set the focus?

    Second, even connect click on the connection through properties of the keyboard button, if I click enter on the keyboard it should connect

    How to have the keyboard properties in flex?

    Can someone help me

    Thanks in advance :-)

    for logging by using the... button you can add eventlistenrer to the area of particular text... example...

    ti.addEventListener (KeyboardEvent.KEY_DOWN, EnterKeyEvent);

    private function EnterKeyEvent (event: KeyboardEvent): void
    {
    if(Event.keycode == 13)
    {
    do something
    }
    }

  • Set the focus on a Datagrid cell

    I have a soft, and after you have created a new line I want to set the focus to a specific cell, so that the user can enter a string.
    I found websites that have methods that worked in the flex Beta 2, but do not work now:
    /////////////////
    The following method is for Flex 2 Beta 1:

    var __focusedCell:Object = new Object();
    __focusedCell.ItemIndex = 1;
    __focusedCell.ColumnIndex = 2;
    dg.setFocusedCell (__focusedCell, true);

    The following method is for Flex 2 Beta 2:

    var __focusedCell:Object = new Object();
    __focusedCell.RowIndex = 1;
    __focusedCell.ColumnIndex = 2;
    dg.setEditedItemPosition (__focusedCell);

    If the above code would choose the 2nd row cell
    http://www.vaishalimistry.com/2005/12/15/set-focus-on-a-cell-in-DataGrid-in-Flex-20/
    ///////////////////////

    Anyone know how to make it work in the final software?

    I worked all day and I get it still 5 minutes after I post here

    grid.editedItemPosition = {columnIndex:1, rowIndex:0};

    It's in the docs under Info for the method call later.
    http://livedocs.Macromedia.com/Flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=L iveDocs_Parts & file = 00001438.html

  • set the focus to the text fields named incrementally

    I created the many (hundreds) of the fields of text through actionscript. I gradually name them and place them on the stage and then subsequently access to set focus.
    I use create a textfield object:
    var txtbox:TextField = new TextField();

    and then use a name incremented to the text field to identify it later:

    var txtname:String = txtn + txtcnt; txtcnt is a number incremented variable. txtn is a string variable.
    txtBox. Name = txtname;

    I add an eventlistener on stage. The event listener works very well and has a companion function.
    I can identify the text field I want access once the move is running through his name.
    Then I use this .name property to set the focus:

    internship. Focus = "txt88";

    Again, "txt88" is the .name of the text field.

    What I am doing wrong?

    ypeError: Error #1034: Type coercion failed: cannot convert "txt88" in flash.display.InteractiveObject.
    to MethodInfo-(200)


    Also, I tried to use the variable incremented during this step, but get a msg of error affecting the variable this way textfield name.
    var txtname:TextField = new TextField();

    Awesome!
    Who did it! I appreciate your help. It is a major obstacle and I went through the help files and books without success. (If it works fine in the AS2 version!)
    Anyway, you are a lifesaver. Thank you.

  • Set the Focus after validation error message

    I have the text element.
    It s have a validation. -> The order of the day is a valid date...

    In the section - Error Message:

    < script type = "text/javascript" >
    Alert ('Invalid Date')

    document.getElementById("P5000_DATA_CAD_INI").focus ();
    html_GetElement ('P5000_DATA_CAD_INI'). Focus();
    < /script >

    My question is how do I set the focus after the validation error message?

    I put document.getElementById("P5000_DATA_CAD_INI").focus ();
    html_GetElement ('P5000_DATA_CAD_INI'). Focus();
    but the two isn´t of work...
    Why?

    Thank you

    Hello

    You must load the jQuery library in the HTML page header.
    I gave the example of how do

    Then place my example of validation error text

    BR, Jari

  • set the focus on the LOV selection list

    I can set the focus to the text fields... but can't seem to fix it to a list of selection LOV...

    Yes it is possible

    in your page > header HTML > add this

    
    

    In the page > BODY > add this

    onLoad= "set_focus();"
    

    Hope this helps,

    Sam
    Please reward the right answers by marking correct or helpful!

  • How to set the focus to an af:table on the loading of the page?

    Hello

    In my page jspx, I want to be able to set the focus to an af:table. I have several tables in this page. All my paintings are based on display of read-only objects.
    I want to guide the user by highlighting a line in the af: table.

    Any ideas? Solutions?

    Thank you
    Jagadish.

    Published by: jaggu_otn on October 23, 2009 06:29

    Published by: jaggu_otn on October 23, 2009 06:33

    Try this, ITI, speaks of "Setting the focus to a particular field..."

    http://technology.amis.nl/blog/2771/adf-11g-rich-faces-focus-on-field-after-button-press-or-ppr-including-javascript-in-ppr-response-and-clientlisteners-client-side-programming-in-adf-faces-rich-client-components-part-2

Maybe you are looking for

  • Can I delete a profile folder if it is empty?

    After update of FF 36.0.4, I did a regular maintenance; cleared the cache, history and cookies. Went to restart FF later and unfortunately it does not open. I followed the instructions to support FF to locate my profile folder, trashed the prefs.js f

  • What W8 for download and where?

    Hello I made two mistakes:1. I tried to install ubuntu alongside w8 on my P870-328. After several tries, I took the wrong way and my HARD drive has been formatted.2 more large one: I don't save any disk recovery (no DVD or USB flash not available and

  • Error installing FSX on windows 7

    I have windows 7 and when I try to load FSX gold edition I get an error reading "dll gameuxinstallerhelper Setup error will end now. what I am doing wrong?

  • Compaq 15s 104tx: unable to locate the drivers 15s 104tx

    Hey guys! Cannot find drivers: Help, please!

  • How to highlight the bitmapfield when worn?

    Hello I am trying to create an image menu based on my application. The idea is to display different image to the user icons. The user can scroll on these images, and then click an icon by clicking on it. I started by posting simple bitmaps using bitm