How do you specify a multiple line string literal in Actionscript 3?
Note that this is sometimes called a here document, heredoc, hereis, multiline string, etc.
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)
greetz
back2dos
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With