Antoine Lassauzay
Antoine Lassauzay

Reputation: 1607

How to refer to a variable in curly braces for XML attributes?

In AS3, I can write the following :

var message:String = "Hello";
var data:XML = <data>{message}</data>;

but how can I reference the variable to format an XML attribute ?

var color:String = "#FFFFFF";
var p:XML = <p><font color="{color}">{message}</font></p>;

Upvotes: 0

Views: 1285

Answers (2)

Patrick
Patrick

Reputation: 15717

Just remove the double-quote for your attribute and it should work :

var p:XML = <p><font color={color}>{message}</font></p>;

here your live example : http://wonderfl.net/c/xxtT

Upvotes: 2

Discipol
Discipol

Reputation: 3157

This is Flex's syntax :) If you wanna do it in plain old actionscript, use Regex. This will help you build up your expression: http://gskinner.com/RegExr/

Upvotes: 0

Related Questions