How to detect when a TextArea is full: Paging

Well again, this is for archive and maybe it’ll save someone some time😉 This is a screenshot of a test with the code below. It has 2 different TextArea components with differing fonts and font sizes that page the text perfectly between the 2 controls.

if you’ve ever tried to do paging or find out how many lines were being occupied in a TextArea’s TextField, this is one way to accomplish the task that seems to work every time. It’s pretty straight forward in that you just need to get to the TextField object that the TextArea uses. Simply test maxScrollV after calling validateNow on the TextArea and bam, you’re in business.


package
{
import flash.events.Event;
import flash.text.TextField;

import mx.controls.TextArea;
import mx.core.WindowedApplication;
import mx.core.mx_internal;
import mx.events.AIREvent;
//use namespace mx_internal;

public class BasicApplicationTestBase extends WindowedApplication
{
public var t0:TextArea;
public var t1:TextArea;
public var txt:String = “Well, it’s not secret that Papervision3D has taken the Flash world by storm, surprise and to the next era of Flash design and development. It’s become a regular word in the arsenal of any Flash designer and developer around the community and we’re really excited about being apart of that! One of the cool things about having an impact like this is the attention Adobe started to give the 3D API’s that were emerging.”;
public var words:Array = [];

public function BasicApplicationTestBase()
{
super();
addEventListener(AIREvent.WINDOW_COMPLETE, handleComplete, false, 0, true);
}

protected function handleComplete(e:Event):void
{
// split up the string at the spaces
words = txt.split(” “);
}

public function doIt(e:Event=null):void
{
// set the target textArea
var target:TextArea = t0;
// clear the current text
target.text = “”;
// set the target textArea’s textfield
var textField:TextField = t0.mx_internal::getTextField() as TextField;

for( var i:int=0; i 1 )
{
// set back to original before changing the target
target.text = originalText;
// set new target TextArea control
target = t1;
// set the word we’re on to the new target, or else we loose it
target.text = words[i] + ” “;
// set new TextField object
textField = t1.mx_internal::getTextField() as TextField;
}
}
}
}
}

    • Olli
    • October 2nd, 2008

    How do I copy the code without line numbers ?
    thanks

  1. There is a “plain text” button at the top of the code – doesn’t look like a button, but just click the text and you’ll see it switch to plain text for you to copy

  2. awesome! thankyou!

    I’m almost ashamed to admit it now but for a long time I have been doing much dodgey business with 3 text fields, different y positions + some masking to get column flow in flash.

    • David
    • December 18th, 2008

    Hi,
    I’ve cut and paste the code from above, but it doesn’t compile. Can you send me the text version of this code. I don’t see the plain text button referred to in the previous reply.

    Thanks,
    David

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s