Hello,

the text length is 0, becaus at this time, there is no linebrake in the textfield.
The Key-Listener is faster than the textfield.
Try this:

_root.createTextField("txt", 1, 0, 0, 100, 100);
_root.txt.type = "input";
_root.txt.multiline = true;
_root.txt.wordWrap = true;

_root.clearText = function(id) {
   clearInterval(_root.clearTextIntervalId);
_root.txt.text = "";
};

_root.keyListener = new Object();
_root.keyListener.onKeyDown = function() {
   if (Key.getCode() == Key.ENTER) {
       _root.clearTextIntervalId = setInterval(_root.clearText, 10);
   }
};

Key.addListener(_root.keyListener);


Janosch




Danny Kodicek schrieb:

God knows why this is such a hassle:

I have a chat app that sends messages when the user hits enter. The
input field is multiline (and needs to be, for the sake of elegance).

Hitting enter inserts a line break in the text regardless of what i do
right now. The method reads something like this:

function clearText() {
        chat_input.text = "";
        trace(chat_input.text.length);
}
kl = {};
Key.addListener(kl);
kl.onKeyDown = function() {
        if (Key.isDown(Key.ENTER)) {
                clearText();
        }
};

After clearText, The input field has 2 blank lines and a text length of
0. I'm hugely confused here, and kind of freaked out.

If it's got a text length of 0 maybe it doesn't actually have two blank
lines, it's just not reset its height to where it was before clearing the
text. Try storing its _width and _height and resetting those as part of your
clearText function.

Danny
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com



_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to