Saturday, 28 March 2009 14:30

If you've ever needed to make multiline strings in AS3, you may have found yourself doing something awkward like this:

var s:String = "This is a multiline string\n";
s += "It has multiple lines.\n";
s += "Too bad the implementation is weird.";

Here's a trick to create true multiline strings in AS3 code, useful for blocks of JavaScript used in ExternalInterface calls:

var js:String = ( <![CDATA[
Your string
]]> ).toString(); "function(){" + js + "}" );

What this does is create an XML object, using the tag wrapped in a set of parenthesis. Then the toString() method is called to cast as a string. This works because AS3 code allows for multiline XML code, but not strings.

Thanks for the tip, Doug!

Last Updated on Thursday, 16 July 2009 11:33
Comments (1)
1 Saturday, 04 September 2010 10:13

Add your comment

Your name:
  The word for verification. Lowercase letters only with no spaces.
Word verification:

The Joomla!® name is used under a limited license from Open Source Matters in the United States and other countries. Jeff Channell is not affiliated with or endorsed by Open Source Matters or the Joomla!® Project.

Joomla Extensions