Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Flash Actionscript / July 2007



Tip: Looking for answers? Try searching our database.

Array syntax AS 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MATTANDIE - 31 Jul 2007 21:02 GMT
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
ah. Ok, thanks.
kglad - 31 Jul 2007 21:14 GMT
you're welcome.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.