simple textflow maxchar ??
Hi guys,
I thought I would experiment with textLayout. I don't think I want to delve as deep as flash.text.engine.
Before I get onto more complicated component design I thought it would be simple enough take a TextFlow Instance and build restrictiveness into it until it performed exactly like a textfield. That is, a text flow with a limit of one line, "enter" key loss of focus, and a maxchar parameter and a password parameter.
I though maxchar would be easy ... apparently not - or I am misunderstanding a fundamental aspect of textLayout or I'm constantly overlooking something stupid in my code.
When I compile the code against the latest 437 build (as adopted from the nov08 API which also didn't work) I get :
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at flashx.textLayout.edit::ElementRange$/createElementRange()
at flashx.textLayout.operations::InsertTextOperation/doOperation()
at flashx.textLayout.edit::EditManager/doInternal()
at flashx.textLayout.edit::EditManager/doOperation()
at flashx.textLayout.edit::EditManager/flushPendingOperations()
at flashx.textLayout.edit::SelectionManager/enterFrameHandler()
package {
import flash.display.MovieClip;
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.elements.ParagraphElement;
import flashx.textLayout.elements.SpanElement;
import flashx.textLayout.edit.EditManager;
import flashx.textLayout.formats.TextLayoutFormat;
//import flashx.textLayout.operations.FlowOperation;
import flashx.textLayout.events.CompositionCompletionEvent;
public class testVellum extends MovieClip {
private var tfw : Number;
private var tfh : Number;
private var inText : String;
//private var password : Boolean;
//stylers
private var fontSize : int;
private var color : uint;
private var kern : Number;
private var kernLeft : Number;
private var kernRight : Number;
private var fontF : String;
private var cFormat : TextLayoutFormat;
private var tf : TextFlow;
private var pe : ParagraphElement;
private var se : SpanElement;
private var tfem : EditManager;
private var seForced : String;
private var maxLength : int;
public function testVellum():void{
//set the defaults
color = 0x272727;
fontSize = 18;
inText = "testerText";
kern = 0;
kernLeft = 0;
kernRight = 0;
fontF = "Arial, Helvetica, _sans";
gonow();
}
public function gonow():void{
cFormat = new TextLayoutFormat();
tf = new TextFlow();
pe = new ParagraphElement();
se = new SpanElement();
tfem = new EditManager();
tf.interactionManager = tfem;
cFormat.fontSize = fontSize;
cFormat.fontFamily = fontF;
se.text = inText;
se.format = cFormat;
pe.addChild(se);
tf.addChild(pe);
tf.flowComposer.addController(new ContainerController(this, tfw, tfh));
tf.flowComposer.updateAllControllers();
tf.addEventListener(CompositionCompletionEvent.COMPOSITION_COMPLETE, compHandler);
}
private function compHandler(e : CompositionCompletionEvent):void{
if(se.textLength > maxLength){
seForced = se.text.substr(0, maxLength);
se.replaceText(0, se.text.length, seForced);
}
}
}
}
