Skip to main content
Inspiring
October 19, 2011
Question

chaining text : what the smater way ?

  • October 19, 2011
  • 1 reply
  • 539 views

Hi I am chaining text beetween diferents textfield. I find a way to do this by cheking the last caracter of the first textfield using getCharIndexAtPoint... and then cut the string using substring

It works but I want to know if ther is a smarter way to do this

here is the code. I don't like the "while (contrPt<0)" part of the code .. in some case this could bring some trouble

var aaaa : String = "aaaaa aaaa   a  a  aaaa a  a a a a  aa a   aa a  a a  aaaaa    aaa   aaaa a  aa  aa  aa   aaaaaa  aaaaaaa  aaaaaa  a aa   aa  aaa  aaaa aaaaa aaaaaaa aaaaaaaa aaaaaaaaa  aaaaaaaaaa aaaaaaaaaaa aaaaaaaaa aaa aaa aaaa aaa aaaa aaaa aaaa  "

var txtCour:TextFormat = new TextFormat();

txtCour.size = 14

txtCour.font = "Trebuchet MS"

txtCour.kerning = true

var contrPt : Number = -1

var inc : Number = 1

var TtA : TextField = new TextField() ; TtA.wordWrap = true ; TtA.multiline = true;

TtA.defaultTextFormat = txtCour

TtA.text = aaaa

TtA.x = 132; TtA.y = 10

    TtA.width = 100 ;TtA.height = 100

    addChild ( TtA)

    while (contrPt<0){

    contrPt  = TtA.getCharIndexAtPoint(TtA.width - inc, TtA.height -5)

    inc ++}

trace ( contrPt)

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
October 19, 2011

Can you provide more information regarding what you are trying to do?  You talk about chaining text from different textfields, but your code shows nothing of the sort that I can see, and the same goes for anything regarding your mention of using substring.

Inspiring
October 19, 2011

here his the complete test code ( I wont post full code) it's not intersting for the question ( this is the code i use to test)

var aaaa : String = "aaaaa aaaa   a  a  aaaa a  a a a a  aa a   aa a  a a  aaaaa    aaa   aaaa a  aa  aa  aa   aaaaaa  aaaaaaa  aaaaaa  a aa   aa  aaa  aaaa aaaaa aaaaaaa aaaaaaaa aaaaaaaaa  aaaaaaaaaa aaaaaaaaaaa aaaaaaaaa aaa aaa aaaa aaa aaaa aaaa aaaa  "

var txtCour:TextFormat = new TextFormat();

txtCour.size = 14

txtCour.font = "Trebuchet MS"

txtCour.kerning = true

var contrPt : Number = -1

var inc : Number = 1

var TtA : TextField = new TextField() ; TtA.wordWrap = true ; TtA.multiline = true;

var TtB : TextField = new TextField() ; TtB.wordWrap = true ; TtB.multiline = true;

TtA.defaultTextFormat = txtCour

TtB.defaultTextFormat = txtCour

TtA.text = aaaa

TtA.x = 132; TtA.y = 10

    TtA.width = 100 ;TtA.height = 100

    addChild ( TtA)

   

while (contrPt<0){

    contrPt  = TtA.getCharIndexAtPoint(TtA.width - inc, TtA.height -5)

    inc ++}

   

    mystB = mystA.substring(contrPt,0x7fffffff ) // cutting the string :

   

    TtB.text = mystB // put the end of the text in the second textfield

    addChild ( TtB)

//====================================================

The purpose of this is make a page layout that goes like this  ( the begining of the text is in the fist text field and the rest in the second text field:

ImageImageImageImageImageImageImage      FistTexfieldFistTexfieldFistTexfieldFistTexfield

ImageImageImageImageImageImageImage      FistTexfieldFistTexfieldFistTexfieldFistTexfield
ImageImageImageImageImageImageImage     FistTexfieldFistTexfieldFistTexfieldFistTexfield
ImageImageImageImageImageImageImage    

FistTexfieldFistTexfieldFistTexfieldFistTexfiel

secondTextFieldsecondTextFieldsecondTextFieldsecondTextFieldsecondTextFieldsecondTextField

secondTextFieldsecondTextFieldsecondTextFieldsecondTextFieldsecondTextFieldsecondTextField

secondTextFieldsecondTextFieldsecondTextFieldsecondTextFieldsecondTextFieldsecondTextField

secondTextFieldsecondTextFieldsecondTextFieldsecondTextFieldsecondTextFieldsecondTextField

Usualy people use html text to do this kind of things. In my case it's not possible