March 27, 2013 - No Comments!

Wordwrap between Textfields AS3

On a project we're currently working on I was required to animate character input using sprite sheets to handle the animation of the characters. This was done by using textfields hidden to the user and animating their input. One of the features required was wordwrap so here is a simple way to create the appearance of wordwrapping between 2 separate fields...


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

var input1:TextField;
var input2:TextField;
input1.maxChars = 10;

input1.addEventListener(Event.CHANGE, onChange);

function onChange(event:Event):void
{
if(input1.text.length == input1.maxChars)
{
var arr:Array = input1.text.split(" ");
var string:String = "";
for (var i:int = 0; i < arr.length - 1; i++) { string = string + arr[i]; if(i != arr.length - 1) string = string + " "; } input1.text = string; input2.text = arr[arr.length - 1]; stage.focus = input2; input2.setSelection(input2.text.length,input2.text.length) } }

Published by: nick in AS3, Code Sample, Flash

Leave a Reply