Question

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.

Was it helpful?

Solution

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();

OTHER TIPS

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

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";

you can also do this

var quote:String = "This was my very first experience with a video game. \
        Despite only being 4 or 5 years old when I first saw this game, \
        the comedic characters and unforgettable soundtrack still brings me incredible joy."
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top