Hi all
I’m currently creating an app which allows users to select blocks of text from a List and dynamically create a TextField on the stage.
I’m calculating the height of the TextField and positioning the next TextField beneath.
I’m also recording the total heights of the TextFields so that I know when the total height exceeds the available height, at which point I move the x position and reset to y position to zero.
When the next TextField will exceed the available height I want to split it into two, so I’m calculating the remaining height, making the TextField.height into the remaining height.
My problem arrives when I try to get the position of the last visible line.
If I have the TextFieldAutoSize as LEFT, then I can dynamically generate the heights of the TextFields.
For the final TextField in the column I need to set TextFieldAutoSize to NONE so I can change the height of the TextField. i.e. I don’t want it to autosize.
However, bottomScrollV returns the total number of lines, not the last visible line.
I’m at a loss. I can create the required behaviour in a separate doc but when I copy the code into the loop it fails.
Here is the code.
public function buildTextFields() {
// 3 columns (I'm calling them TextBlocks)
// so the first is 0;
var currentTextBlock=0;
// textStrings is an array that contains all the strings
var amountOfTextFieldsToBuild=textStrings.length;
// textBlocks is an array which contains objects with
// information regarding the x,y,width,height of the
// textBlock on the page
var currentXpos:Number=textBlocks[0].x * 2;
var currentYpos:Number=textBlocks[0].y * 2;
var currentWidth:Number=textBlocks[0].width;
// currentHeight is the current height of all the textfields
// on the page, so it starts at 0
var currentHeight:Number=0;
// format of the textfields
var format:TextFormat=new TextFormat("Times New Roman",9,0x000000,false,false,false,"","",TextFormatAlign.LEFT,0,0,0,1);
// loop through the textStrings array to create the textFields
for (var i:Number=0; i < amountOfTextFieldsToBuild; i++) {
// create text field
var txtFld:TextField = new TextField;
txtFld.defaultTextFormat=format;
txtFld.name='txtFld'+i;
txtFld.multiline = false;
txtFld.wordWrap = true;
// i'm just using the border for testing
// easier to see the x, y, width, height
txtFld.border = true;
txtFld.text=textStrings*;
txtFld.width=currentWidth;
// needed to autosize
txtFld.autoSize=TextFieldAutoSize.LEFT;
txtFld.x=currentXpos;
txtFld.y=currentYpos;
// add text field to array
// need this for later
//textFields.push(txtFld);
// determine the height of the available textBlock
var heightOfCurrentTextBlock = textBlocks[currentTextBlock].height;
// calculate the height of all the text fields if the textfield was added to the page
var projectedHeight = currentHeight + txtFld.height;
// if there is available height to place the textfield
if (projectedHeight < heightOfCurrentTextBlock) {
// add to page
addChild(txtFld);
// amend the ypos and update the current height of all the textfields
currentYpos=currentYpos + txtFld.height;
currentHeight=currentHeight + txtFld.height;
} else {
// we need to split up the text field into two (or more) to accomodate the text
var remainingHeight = heightOfCurrentTextBlock - currentHeight;
// need to make NONE so that we can control the height
txtFld.autoSize=TextFieldAutoSize.NONE;
// set the height
txtFld.height=remainingHeight;
// add to page
addChild(txtFld);
////////////
// when added to the page
// the bottomScrollV property of
// the text field is incorrect
// It is always the same as
// the numLines propert
///////////
// change the positions
// hard coded for now.
currentXpos=textBlocks[1].x * 2;
currentYpos=textBlocks[1].y * 2;
currentHeight = 0;
}
}
}
This one works in its own document
var tempTxtFld:TextField = new TextField;
var format:TextFormat=new TextFormat("Times New Roman",9,0x000000,false,false,false,"","",TextFormatAlign.LEFT,0,0,0,1);
tempTxtFld.defaultTextFormat=format;
tempTxtFld.name='tempTxtFld';
tempTxtFld.multiline = true;
tempTxtFld.wordWrap = true;
tempTxtFld.text="Ffds fds fsdfsd fdsfdsfsdd sddsd dsddfsd dsf sdfsd fsdf sdfsd fsdf sdf sd fds fdsf dsf dsf ff fsd fsdf sdf sdf. Ffds fds fsdfsd fdsfdsfsdd sddsd dsddfsd dsf sdfsd fsdf sdfsd fsdf sdf sd fds fdsf dsf dsf ff fsd fsdf sdf sdf. Ffds fds fsdfsd fdsfdsfsdd sddsd dsddfsd dsf sdfsd fsdf sdfsd fsdf sdf sd fds fdsf dsf dsf ff fsd fsdf sdf sdf";
tempTxtFld.autoSize=TextFieldAutoSize.NONE;
addChild(tempTxtFld);
tempTxtFld.width=100;
tempTxtFld.height=90;
Any ideas?
R