Thursday, December 18, 2008

Beginner: AS3 XMLList as a Primitive and XML as a Complex Datatypes

Using Flex SDK 3.1.0 build 2710

I'm not sure if this is true across the board after doing a little searching on the web. It seems that people have had different experiences. But as far as I'm concerned right now, XML is being handled as a complex datatype and XMLList is being handled as a primitive datatype.

I'm looking to confirm this though.

Flash has two types of datatypes: primitives and complex. Primitives are datatypes such as Strings or Numbers where each type you associate them a new instance is created.

var abc:String='three wise men';
var copy:String=abc;

abc='two plain dogs';


This above example associates copies the variable abc into the variable copy so that changes in abc later will no be reflected in copy.

Complex datatypes, such as Objects, retain references to an original instance stored in memory.

var dog:Object = {chase:true, likes:'cars'};
var cat:Object = {chase:false, likes:'naps'};




In the above example the variable dog will now reference the same object as the variable cat. Therefore, changing the string 'likes' to mice will change both dog.likes and cat.likes.

XML and XMLList example.