Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Line String Literal in Actionscript 3

How do you specify a multiple line string literal in Actionscript 3?

  • Multiline String Literal in C#

Note that this is sometimes called a here document, heredoc, hereis, multiline string, etc.

like image 301
Nick Sonneveld Avatar asked Jul 16 '09 04:07

Nick Sonneveld


2 Answers

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();
like image 182
Nick Sonneveld Avatar answered Sep 24 '22 04:09

Nick Sonneveld


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

like image 36
back2dos Avatar answered Sep 25 '22 04:09

back2dos