Hi all,
Recently made the transition from flash/as2 to flex/as3 have to say I’m loving it! Thought i’d experiment a bit and test the water making a simple live chat application already run into my first snag.
private function keyPressed(e:KeyboardEvent):void
{
switch(e.keyCode)
{
case 13:
sendText();
break;
}
}
private function sendText():void
{
if(inputText.text == "")
{
trace("text field is blank");
}else{
textDisplay.appendText(inputText.text + "
");
inputText.text = "";
stage.focus = inputText;
}
}
This is called using:
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
The problem I’m experiencing is when you first hit enter and add the text to the display box is registers the enter and adds it aswell.
textDisplay.appendText(inputText.text + "
");
This is the main offender. I’m just wondering how I would find the last character and ignore everything else after that? Kind of similar to the php explode.
Heres a picture to better demonstrate:
Ta Sigs