Copy link to clipboard
Copied
Hi all,
I've been battling with input TextFields on iOS for a few days now. Maybe someone here will have some insight!
This happens using AIR4.0 and AIR 3.9 (haven't tested older) on iOS7 (iPhone 5) and iOS5.1 (iPad 1) (haven't tested others).
I create an input TextField and place it on the stage, then set focus to it like this (some setup code ommitted for visibility):
_inputTextField = new TextField();
_inputTextField.type = TextFieldType.INPUT;
addChild(_inputTextField);
_inputTextField.addEventListener( FocusEvent.FOCUS_OUT, loseFocus );
_inputTextField.addEventListener( KeyboardEvent.KEY_DOWN, keyDown );
_inputTextField.addEventListener( Event.CHANGE, inputChanged );
stage.focus = _inputTextField;
_inputTextField.setSelection( _inputTextField.text.length, _inputTextField.text.length ); // Place cursor at end
_inputTextField.requestSoftKeyboard();
Here is what happens on iOS:
1) If there is text in the textfield, this code works perfectly.
3) If the text field is empty, the problem below occurs (I think it is because setSelection is unable to set a selection)
2) If I leave out the setSelection line, even with text in the field, the problem below also occurs
4) If there IS text, and I manually hit backspace to delete it all so that the text field is empty, there is no problem
The problem:
When the problem occurs, here are the symptoms:
1) The text field is the correct size/position, but the font is very tiny and is a serif font
2) The KEY_DOWN event only fires for ENTER (not for other keys)
3) The CHANGE event only fires intermittently. Seems to be when the OS suggests spell-check alternatives etc
4) on FOCUS_OUT, reading from _inputTextField.text gives an empty string even if there is text in there
When there is no problem, textfield size, position, font style etc is fine. All key events and change events fire, and reading from textfield.text gives the correct string.
Any help appreciated!
Peter
Solution:
An empty input TextField (textField.type = TextFieldType.INPUT) will cause problems on iOS unless you set embedFonts to false. The problems are vast: no events fired; text formatting incorrect; unable to read text from field. If the input TextField has text in it, then embedFonts seems to work ok, but safest to always set it false on iOS. I have a compiler flag for iOS for cross-platform development that sets embedFonts to false and font to Helvetica on iOS for input text fields.
Seco
...Copy link to clipboard
Copied
Hi all,
Halfway to solving it! As is usually the case, it has something to do with the 'code ommitted for visibility' ![]()
I was setting 'embedFonts = true' on the input TextField. If I leave this out, it is mostly working.
Here is what I see now when I set embedFonts to false:
1) The first time the textfield is used, the font is still tiny and has the wrong color, but the events fire and textField.text has the correct value when focus is lost
2) This continues to happen until the textfield has a value when it receives focus. At this point the font size and color are correct
3) Once the textfield has had a value in it at least one time, the font/color will be correct (no more problem) even if it is empty again later
I may have to resort to some weird hack, like: populating the textfield, setting a value, setting focus, removing focus, removing the value, and setting focus again ![]()
Cheers,
Peter
Copy link to clipboard
Copied
Solution:
An empty input TextField (textField.type = TextFieldType.INPUT) will cause problems on iOS unless you set embedFonts to false. The problems are vast: no events fired; text formatting incorrect; unable to read text from field. If the input TextField has text in it, then embedFonts seems to work ok, but safest to always set it false on iOS. I have a compiler flag for iOS for cross-platform development that sets embedFonts to false and font to Helvetica on iOS for input text fields.
Secondly, I had forgotten to set defaultTextFormat on the TextField at the same time as setting setTextField. That is why the first time the text was small, and the second time it was ok. Setting defaultTextField ensures that all new text typed has the correct formatting.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more