简体   繁体   中英

Flash CS4/AS3 Dynamic Text Box

I have created a XML image gallery, which displays text in between each slide. Now I have created a movie clip with a dynamic text field (with Render HTML selected) to display the text from the XML which is pushed into an array. Now, this all works great BUT... /n or /r is not creating a new line break (as they need to be custom). Yet if I create an Array and manually push strings "Bla bla bla /n bla bla bla" I get a line break. I have tried converting the Array item to string (even though it already is), I would also avoid creating textField = new textField() any Ideas would be welcomed.

Cheers

Edit

You have two choices :

-as suggested put replace in your XML the \\n by a <br/> but encoded to be a valid XML &lt;br/&gt;

<image imageFile="GrandOpening1.jpg"
       text="XXXXX&lt;br/&lt;XXXXXX&lt;br/&lt;XXXX XXXX XXXXXX">
</image> 

-or at runtime when filling your textfield replace the \\n by a <br/>

myTextField.htmlText=xml.@text.toString().split("\\n").join("<br/>");

/n /r is not correct it 's \\n \\r .

Have you enable multiline option for your TextField.

由于您的TextField已启用HTML,因此最好使用<br>标记创建新的换行符。

\\n \\r only works in runtime and
won't work. I use a custom string to represent linebreak "#BR#" for example. Before you pass the string to the text box, replace all instances of "#BR#" with "\\n" using regular expression.

var str:String = xmlString; var pattern:RegExp = /#BR#/ig;//target all instances of #BR#(case insensitive) txt_textbox.text=str.replace(pattern, "\\n");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM