views:

48

answers:

2

I find myself always typing something like

Alert.show("blah = " + blah);

In PHP we have

"blah = $blah"

In Ruby we have

"blah = #{blah}"

Do we have anything like that in Actionscript3?

Also...what is the proper name for what we are doing here?

Thanks!

A: 

Not sure if you mean the trace() function:

http://help.adobe.com/en_US/AS3LCR/Flash_10.0/package.html#trace()

As in:

trace("Blah: " + Blah);
Lillemanden
it doesn't matter the function using the string. i am just wondering if there is a way to include variables inside the actual string to avoid +
Tony
Ahhh, no I'm pretty sure there is no such functionality in ActionScript 3.
Lillemanden
+1  A: 

If you're asking whether you can include a variable name within a string and have it evaluated as opposed to treated like a literal (like your PHP example), the answer is no. This isn't a feature of the ActionScript language. However, you can achieve something like this by using the StringUtil's substitute method. Here's an example:

StringUtil.substitute("My name is {0} and I am {1} years old", name, age);

http://livedocs.adobe.com/flex/3/langref/mx/utils/StringUtil.html

Marplesoft