Splitting text across multiple textfields

Hey!
Working with textfields in AS3 and have some musings. I´ve two textfields where I splitting a text across.
[AS]
myText1_txt.type = “input”;
myText1_txt.htmlText = “Looong text goes here…”;

myText2_txt.type = “input”;
myText2_txt.htmlText = myText1_txt.htmlText;

for (var i:int = 0; i < myText1_txt.bottomScrollV; i++)
{
myText2_txt.htmlText += “<br>”;
}

myText2_txt.scrollV = myText1_txt.bottomScrollV + 1;
[/AS]
This works fine. It counts the lines in the left textfield (visible lines) and then scrolls the right field. Now I want to add input functionality so that you can type into myText1_txt textfield (left field) and it will automatically flow over to myText2_txt - the right textfield. Any suggestions?!

Perhaps add a keylistener… every time user presses key it grabs key…

mytextF2.text += myTextF1.charAt(myTextF1.length);

Something like that maybe?

Updated version number 2 =). Now it flows over when input text and you can´t scroll using mouse or mousewheel. But there are two major problems:

  1. When pressing enter key you must hit enter twice before it updates textfield two and it don´t react as it should when hitting backspace key.
  2. When setting textfield 1 = textfield 2 or the opposite it misses the last character written.

Any solutions?!
[AS]
import flash.events.TextEvent;
var myLongText:String = “Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque congue pede in dui. Etiam nec nisl a ipsum hendrerit accumsan. Maecenas aliquet ante lobortis dolor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus turpis. Morbi porta aliquet nisi. Donec eu ante id lorem pharetra vulputate. Donec ultricies lectus et lorem. Aenean velit purus, fringilla a, consequat eu, convallis at, nisi. Praesent risus nibh, eleifend vitae, interdum a, blandit eu, mauris. Suspendisse diam diam, viverra non, convallis in, eleifend quis, erat. Praesent ante. Nullam elementum massa vitae pede. In dui urna, sollicitudin eu, pharetra sit amet, pulvinar vitae, dui. Sed dignissim ligula ac urna.”;

// TextField 1 - Left
myText1.selectable = true;
myText1.type = “input”;
myText1.mouseWheelEnabled = false;
myText1.htmlText = myLongText;

// TextField 2 - Right
myText2.selectable = true;
myText2.type = “input”;
myText2.mouseWheelEnabled = false;
myText2.htmlText = myLongText;

// Start - distribute text among the textfields
for (var i = 0; i < myText1.bottomScrollV; i++)
{
myText2.htmlText += “<br>”;
}

myText2.scrollV = myText1.bottomScrollV + 1;

/**

  • Handles text input and distribute text among the textfields
    */
    // Left textfield check
    function textInputHandler(event:TextEvent):void
    {
    myText2.htmlText = myText1.htmlText;

    for (var i = 0; i < myText1.bottomScrollV; i++)
    {
    myText2.htmlText += “<br>”;
    }

    myText2.scrollV = myText1.bottomScrollV + 1;
    }
    myText1.addEventListener(TextEvent.TEXT_INPUT, textInputHandler);

// Right textfield check
function textInputHandler2(event:TextEvent):void
{
myText1.htmlText = myText2.htmlText;
myText1.scrollV = 0;
}
myText2.addEventListener(TextEvent.TEXT_INPUT, textInputHandler2);

/**

  • Prevent scrolling when selecting text
    /
    function onScroll1(event:
    )
    {
    myText2.scrollV = myText1.bottomScrollV + 1;
    }
    myText2.addEventListener(Event.SCROLL, onScroll1);

function onScroll2(event:*)
{
myText1.scrollV = 0;
}
myText1.addEventListener(Event.SCROLL, onScroll2);

/**

  • Export Button
    */
    function buttonClickHandler(event:MouseEvent):void
    {
    var Left:String = “”;
    for (var i:int = 0; i < myText1.bottomScrollV; i++)
    {
    Left += myText1.getLineText(i);
    }

    var Right:String = “”;
    for (var j:int = myText1.bottomScrollV; j < myText2.bottomScrollV; j++)
    {
    Right += myText2.getLineText(j);
    }
    }
    export_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
    [/AS]

flash.events.Event.CHANGE

Dispatched after a control’s value is modified. Contrast this with the textInput event, which is dispatched before the value is modified. Unlike the W3C DOM Event Model version of the change event, which dispatches the event only after the control loses focus, the ActionScript 3.0 version of the change event is dispatched any time the control changes. For example, if a user types text into a text field, a change event is dispatched after every keystroke.

That saved my day :bounce:. Thanx! And this is the improved code:
[AS]
import flash.events.*;

var myLongText:String = “Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque congue pede in dui. Etiam nec nisl a ipsum hendrerit accumsan. Maecenas aliquet ante lobortis dolor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus turpis. Morbi porta aliquet nisi. Donec eu ante id lorem pharetra vulputate. Donec ultricies lectus et lorem. Aenean velit purus, fringilla a, consequat eu, convallis at, nisi. Praesent risus nibh, eleifend vitae, interdum a, blandit eu, mauris. Suspendisse diam diam, viverra non, convallis in, eleifend quis, erat. Praesent ante. Nullam elementum massa vitae pede. In dui urna, sollicitudin eu, pharetra sit amet, pulvinar vitae, dui. Sed dignissim ligula ac urna.”;

// TextField 1 - Left
myText1.selectable = true;
myText1.type = “input”;
myText1.mouseWheelEnabled = false;
myText1.wordWrap = true;
myText1.text = myLongText;

// TextField 2 - Right
myText2.selectable = true;
myText2.type = “input”;
myText2.mouseWheelEnabled = false;
myText2.wordWrap = true;
myText2.text = myLongText;

//
// Init - Divide out text over the two text fields
//
var Right:String = “”;
for (var j:int = myText1.text.lastIndexOf( myText1.getLineText( myText1.bottomScrollV )); j < myText1.text.length; j++)
{
Right += myText1.text.charAt(j);
}
myText2.text = Right;

//
// Left textfield check
//
function textInputHandler(event:Event):void
{
var startValue:int = myText1.text.lastIndexOf( myText1.getLineText( myText1.bottomScrollV ));
var UpdatedRightContent:String = “”;

for (var j:int = startValue; j &lt; myText1.text.length; j++) 
{
     UpdatedRightContent += myText1.text.charAt(j);
}

myText2.text = UpdatedRightContent;

}
myText1.addEventListener(Event.CHANGE, textInputHandler);

//
// Prevent mouse select scroll in left text field
//
function onScroll2(event:*)
{
myText1.scrollV = 0;
}
myText1.addEventListener(Event.SCROLL, onScroll2);

//
// Export Button
//
function buttonClickHandler(event:MouseEvent):void
{
var Left:String = “”;
for (var i:int = 0; i < myText1.bottomScrollV; i++)
{
Left += myText1.getLineText(i);
}

var Right:String = myText2.text;

trace("Left TextField --&gt;

" + Left + "
")
trace("Right TextField –>
" + Right)
}
export_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
[/AS]