Use a Array when you look up a value by a numeric index. Use an Object
when you look up a value by a string key like "name" or "property".
 
BTW, I think using Object-literal syntax to combine these four lines
into
 
    categories.addItemAt({ name: "All", categoryID: o });
 
will create smaller, faster code. It's also more readable, IMHO.
 
- Gordon

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Chad Gray
Sent: Thursday, April 05, 2007 1:38 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] to use object or array -- 'Adobe Flex 2 Training
from the Source' book



I am reading the 'Adobe Flex 2 Training from the Source' book and have a
question as to why they used an object and not array. Page 118 for those
that have the book.

What they are doing is taking an array (categories) and appending a new
row to it Name=All and CategoryID=0.

Is there any advantage/disadvantage to setting catObj as an object and
not array? I would think you would want them to be the same thing.

// define new var catObj as an object
var catObj:Object = new Object();

// set the new object var NAME to ALL and set the CATEGORYID to 0
catObj.name = "All";
catObj.categoryID = 0;

// now use addItemAt to append the catObj object to the categories array
at the 0 position
categories.addItemAt(catObj, 0); 

The book is good, but the OOP stuff when making your own actionscript
classes in lesson 5 kind of confused me. Hopefully I will fully
understand what they did as I learn more about AS.



 

Reply via email to