Categories
Archives
Flying Virgin America | Home | Otherwise Blow Up
Filed under Quick Tips on July 25, 2008 by Javier JulioDefining Dynamic XML Literals in ActionScript 3
Recently, I was working on my first Flex project where I was consuming XML via a service. Whenever I wanted to make data changes with the service, I was required to send in an XML packet. Since AS3 has native support for XML literals, I wanted to create my small XML packet inline. For example:
var changeSet:XML =; ACTIVEQUOTE
With my XML content defined as a literal, all I needed was to dynamically set some attribute values from a value object. Using curly braces { }, I can bind to certain values. For example:
var policy:PolicyVO = note.getBody() as PolicyVO; var changeSet:XML =; ACTIVEQUOTE
Originally, I wrapped the curly braces with double quotes from my experience with MXML, but that does not apply here. With the double quotes, AS3 thinks you want the literal string rather than evaluating what is within the curly braces. Simply stripping the double quotes worked. A neat thing about this is that in AS3 you can also dynamically name tags too. For example, I could do this:
For a great resource for everything E4X in ActionScript 3, check out the AS3 E4X Rundown!
Trackback Pings (TrackBack URL for this entry)
http://www.arc90.com/cgi-bin/mt4/mt-tb.cgi/177.
Comments
Flying Virgin America | Main | Otherwise Blow Up

Thanks Javier. Bookmarked for future reference...
Posted on July 26, 2008 9:48 AM by Paul Johnson