Hello,
I have been going through the tutorials in Adobe's Flash 8 training from the
source, and I have run into a syntax question about arrays and was hoping
someone could explain something for me.
specifically why I can trace an element in the first example but not in the
second. (IE. why does the second format not work and what do i need to do to
make it work.
ex1.
var directory:Array = [{name:"John", phone:"919-555-5698"}, {name:"Kelly",
phone:"232-555-3333"}, {name:"Ross", phone:"434-555-5655"}];
In this example I can run a trace to any item in the array.
ex 2.
var directory = new Array();
directory[0].Name = "John"
directory[0].Phone = "919-555-5698"
directory[1].Name = "Kelly"
directory[1].Phone = "232-555-3333"
directory[2].Name = "Ross"
directory[2].Phone = "434-555-5655"
all traces come up as undefined.
I have used the second examples format before with very few problems, so any
insight to this would be greatly appreciated.
Thanks.
kglad - 31 Jul 2007 21:09 GMT
directory[0] is undefined so trying to assign a property to it (like Name or
Phone) is going to fail.
to remedy you need to define directory[0] to be an object:
directory[0]={}
// or
directory[0]=new Object();
MATTANDIE - 31 Jul 2007 21:11 GMT
kglad - 31 Jul 2007 21:14 GMT