Arrays and Objects
by jlagunas on Jul.21, 2008, under Actionscript
The following example shows you how to create arrays and objects using MXML and Actionscript 3.0.
Defining an Array in MXML:
<mx:Array> <mx:String>Mac Pro</mx:String> <mx:String>Mac Mini</mx:String> <mx:String>Macbook</mx:String> <mx:String>Macbook Air</mx:String> <mx:String>Macbook Pro</mx:String> <mx:String>iMac</mx:String> </mx:Array>
Defining an Array in Actionscript 3.0:
with constructor:
var macs:array = new Array("Mac Pro", "Mac Mini", "Macbook", "Macbook Air", "Macbook Pro", "iMac");
without constructor:
var macs:array = ["Mac Pro", "Mac Mini", "Macbook", "Macbook Air", "Macbook Pro", "iMac"];
Defining an Object in MXML:
<mx:Object id="Macbook" color="black" processor="2.4GHz Intel Core 2 Duo" Memory="2GB (up to 4GB)" storage="250GB">
Defining an Object in Actionscript 3.0:
with constructor:
var object:Object = new Object(); var subObject:Object = new Object(); object.subObject = subObject;
without constructor:
var macs:Object = {name:"Macbook", color:{color1:"white", color2:"black"}, processor:{processor1:"2.1GHz Intel Core 2 Duo", processor2:"2.4GHz Intel Core 2 Duo"}, memory:{memory1:"1GB (two 512MB)", memory2:"2GB (two 1GB)", memory3:"4GB (two 2GB)"}, storage:{hd1:"120GB", hd2:"160GB", hd3:"250GB"}};
Note: you can nest objects with properties within objects without having to declare variable names
No comments for this entry yet...
