x


iPhoneKeyboard.Open cannot handle multiple entries. Is it a bug?

How can a player enter two entries, like a name and a password? The iPhoneKeyboard.Open of one replaces the other! What is the code below missing? Any ideas?

static var inputText : String = "text"; 
static var inputText2 : String = "text2"; 
private var keyboard : iPhoneKeyboard; 
private var keyboard2 : iPhoneKeyboard; 

function OnGUI() { 
if (GUI.Button(Rect(10, 10, 200, 32), inputText)) 
    keyboard = iPhoneKeyboard.Open(inputText); 

if (keyboard) 
    inputText = keyboard.text; 

if (GUI.Button(Rect(10, 50, 200, 32), inputText2)) 
    keyboard2 = iPhoneKeyboard.Open(inputText2); 

if (keyboard2) 
    inputText2 = keyboard2.text; 
} 
more ▼

asked Mar 08 '10 at 04:29 PM

Jason Mills gravatar image

Jason Mills
21 1 1 2

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You can have only one keyboard active at the same time, so before opening a new keyboard check if the current one is done. A way to do it nicely would be something like (code written on the fly and I'm no javascript programmer so could be some small syntax errors in it):

var text1 : string;
var text2 : string;
var isTyping : boolean;

function OnGUI() {
    if (GUI.Button(Rect(10, 10, 200, 32), text1) && !isTyping) {
        StartCoroutine(COInputText1());
    }
    if (GUI.Button(Rect(10, 50, 200, 32), text2) && !isTyping) {
        StartCoroutine(COInputText2());
    }
}

function COInputText1() {
    isTyping = true;
    var keyboard : IphoneKeyboard;
    keyboard = IPhoneKeyboard.Open(text1);
    yield keyboard;
    text1 = keyboard.text;
    isTyping = false;
}

function COInputText2() {
    isTyping = true;
    var keyboard : IphoneKeyboard;
    keyboard = IPhoneKeyboard.Open(text2);
    yield keyboard;
    text2 = keyboard.text;
    isTyping = false;
}
more ▼

answered Mar 09 '10 at 03:43 AM

Jaap Kreijkamp gravatar image

Jaap Kreijkamp
6.5k 20 27 71

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2013
x981
x567
x529
x202

asked: Mar 08 '10 at 04:29 PM

Seen: 1711 times

Last Updated: Jul 13 '10 at 04:03 PM