Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Contributor
fedyfausto
Posts: 24
Registered: ‎10-17-2013
My Device: Z10

TextInput TEMP solution

Hello toall guys, like some people have some problems after 10.2.1 update with ALL textinput field (native, flash, ecc ecc). This beacuse in runtime AIR on new OS are some problems with UNFOCUS event and textfield content (if you set the textinput content with some text and click the app don't crash, but if it's empty the app crash).

 

So for the moment the orrible solution is this:

 

PREVENT the default focus on Textfield and manage that manually (set not touchble the textinput and check the Touch on it)

 

when Touch and on Fouc-Out check the content of the textfield input:

 

 

//FOCUS OUT

textfield.addEventListener(FOCUS_OUT, function():void
{
     if (textfield.text == "")
          textfield.text = " ";
     else if(textfield.text != " ")
          textfield.text = textfield.text.replace(" ", "");
});

 

//TOUCH IT

 

textfield.addEventListener(TOUCH, function(evnt):void
{
       var t:Touch = (evnt as TouchEvent).getTouch(textfield);
       if (textfield.text == "")
           textfield.text = " ";
       else if(textfield.text != " ")
           textfield.text = textfield.text.replace(" ", "");

      if (t && t.phase == TouchPhase.BEGAN)
      {
            stage.needsSoftKeyboard = true;
            if (stage.requestSoftKeyboard())
            {
                textfield.setFocus(new Point(1, 0));
                textfield.hideFocus();

            }

     }
});

 

 

 

 

Contributor
bkirvin
Posts: 48
Registered: ‎09-08-2013
My Device: Z10

Re: TextInput TEMP solution

[ Edited ]

You figured it out!

 

I solved it this way:


public function enterplayername(thisname):void

{
inputField = new TextField();
inputField.defaultTextFormat = instformat;
inputField.text = thisname;
inputField.type = TextFieldType.INPUT;
inputField.addEventListener(FocusEvent.FOCUS_IN, blackinputtxt);
inputField.addEventListener(KeyboardEvent.KEY_DOWN, checkenter);
inputField.border = true;
inputField.width = stagex(200);
inputField.height = stagey(35);
inputField.background = true;
inputField.x = stagex(140);
inputField.y = stagey(75);

inputField.maxChars = 11;
inputField.restrict = "A-Za-z0-9";
addChild(inputField);
studs.push(inputField);

var button:MovieClip = new cancelbtn();
button.x = stagex(240);
button.y = stagey(140);
scaleme(button);
addChild(button);
studs.push(button);

}

 

public function blackinputtxt(e:Event):void

{

inputField.removeEventListener(FocusEvent.FOCUS_IN, blackinputtxt);
inputField.text = " ";
inputField.defaultTextFormat = format;

}

 


public function checkenter(e:KeyboardEvent):void

{

if(inputField.text == " ")

{
inputField.text = "";
}


if(e.charCode == 13)

{
stage.focus = null;
inputField.removeEventListener(KeyboardEvent.KEY_DOWN, checkenter);
setplayername();
}

}

 

You have to set inputField.text = ""; before the user enters the text or the SharedObject name (assuming you are accepting a SharedObject name in the input text field) will begin with a space and fail on creation. set inputField.text = " "; in the FOCUS_IN function to keep the soft keyboard from crashing and remove instructional text, then test for inputField.text == " " in the KEY_DOWN function and reset to inputField.text = "";

 

working like a charm! :Clap: