How do you specify a multiple line string literal in Actionscript 3?
There is one example from this site: Multi-line strings in Actionscript 3
Because actionscript is based on javascript, you can use the cdata tags.
private var myString:String = ( <![CDATA[
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Maecenas dui lacus, sollicitudin nec laoreet a, vestibulum a
odio. Sed et lorem mauris, non porttitor ligula. Aliquam
convallis dolor rutrum justo semper nec aliquet orci....
]]> ).toString();
wow, very clever ... actually, i think this won't even work in most browser when it comes to JavaScript ...
i just wanted to amend an explanation of what actually happens: AS3 allows inline xml declarations through xml literals (which should be part of E4X) ... what you do, is declare an XML
literal and then convert it to a String
... likewise, you could write:
private var myString:String = ( [
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"Maecenas dui lacus, sollicitudin nec laoreet a, vestibulum a",
"odio. Sed et lorem mauris, non porttitor ligula. Aliquam",
"convallis dolor rutrum justo semper nec aliquet orci....",
] ).join("\n");
that would be declaring an Array
literal and converting it to a String
...
so in the end, you instruct the flash player to create an XML
object with one text node containing your text, and then use the String
representation of that object ...
(little side note: it is bad practice to declare String content in your code ... this should be loaded externally at runtime)
This worked great for me:
private var myString:String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."+"\n"+ "Maecenas dui lacus, sollicitudin nec laoreet a, vestibulum a";