Log in

View Full Version : AS3 Text Capture



Hu4ley
04-21-2008, 10:11 AM
Hi Guys,

Hopefully someone can help?

I have an input text box which captures user input and displays it into a dynamic textbox in another movieclip. It works but I have a slight problem.

It doesn't seem to capture the last character.

If i input, "hello", it displays "hell" and not the "o", unless i key another charachter in or press space bar, then it updates it.

Here is the code....

////////////////////////////////////////////////////////////////////////

myTextBox.text = myText;

function CaptureUserInput()
{
captureText();
}

function captureText():void
{
myTextBox.text = myText;
myTextBox.addEventListener(TextEvent.TEXT_INPUT, textInputCapture);
}


function textInputCapture(event:TextEvent):void
{
var str:String = myTextBox.text;
createOutputBox(str);
//trace(root.myText.myOutputBox.text.length);
}

function createOutputBox(str:String):void
{
root.myText.myOutputBox.text = str;
}


captureText();

////////////////////////////////////////////////////////////////////////

Any ideas on how to update the text box so all characters are displayed when entered?

Thanks for yout time!

Hurley

Hu4ley
04-21-2008, 01:14 PM
fixed it but adding a listener to the keyboard and on key up running a function to update the text box.

Easy peasy lemon squeezy

Thanks

Hurley

/////////////////////////////////////////////////////////////////////////////////////

stage.addEventListener(KeyboardEvent.KEY_UP, key_pressed);

myTextBox.text = myText;

function CaptureUserInput()
{
captureText();
}

function captureText():void
{
myTextBox.text = myText;
myTextBox.addEventListener(TextEvent.TEXT_INPUT, textInputCapture);
}

function textInputCapture(event:TextEvent):void
{
var str:String = myTextBox.text;
createOutputBox(str);
//trace(root.myText.myOutputBox.text.length);
}

function createOutputBox(str:String):void
{
root.myText.myOutputBox.text = str;
}

function key_pressed(event:KeyboardEvent):void {

var str:String = myTextBox.text;
createOutputBox(str);

}

captureText();