Adding Attributes to an XML Element : XML Object « XML « Flash / Flex / ActionScript






Adding Attributes to an XML Element

 


package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){


        var example:XML = <example><someElement/></example>;
        
        example.someElement.@number = 12.1;
        example.someElement.@string = "example";
        example.someElement.@boolean = true;
        example.someElement.@array = ["a", null, 7, undefined, "c"];
        
        trace( example );
        
        example.someElement.@["bad-variable-name"] = "yes";
        
        example.someElement.@["color" + num] = "red";

    }
  }
}

        








Related examples in the same category

1.Creating an XML Object
2.Create the XML structure with a string
3.Understanding the XML Classes
4.Using Expressions within Literals: embed ActionScript code directly into your XML data.
5.Reading Elements in an XML Tree
6.Finding Elements by Name
7.Reading Text Nodes and Their Values