Solved

Arrays confusion

Posted on 2006-07-04
6
188 Views
Last Modified: 2010-08-05
I have some code --
==================
a = new Array();

b = new Array();
b["Eng"] = {relSize:"+0", txt:"Now is the time"} ;
b["Spa"] = {relSize:"+1", txt:"Ahora es el tiempo"} ;

t = "#main";
a[t] = b;

b = new Array();
b["Eng"] = {relSize:"+0", txt:"for all good men"} ;
a["#2nd"] = b;

trace(a.length);  ---- This returns 0 length !
trace(a[t]["Spa"].relSize + ", " + a[t]["Spa"].txt);
trace(a[t]["Eng"].relSize + ", " + a[t]["Eng"].txt);
trace(a["#2nd"]["Eng"].relSize + ", " + a["#2nd"]["Eng"].txt);
===============

This traces out correctly as --
0
+1, Ahora es el tiempo
+0, Now is the time
+0, for all good men
--------------------------------
EXCEPT: Why am I getting 0 length for the "a" array as noted above?

0
Comment
Question by:Donelson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 500 total points
ID: 17039763
Hi,
actual problem here is:

whether you have declared 'a' and 'b' as Array,
but these variables are not anymore holds array

The way you have populated them, you have coverted them to Objects.

To keep them as array, you should populate the values using index

for example:
a[0] = {some value};
a[1] = {some value};
0
 

Author Comment

by:Donelson
ID: 17040721
Aha!  Overlap between the array_index " [ ] " method and the object_index method " [ ] "

So. You can have a two-dimensional object!

Is there any way to get the number of properties on these objects?

Thanks, Aneesh.
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 17040775
Yes,

there is way to do it:

you can do it using "for(i in Object)" loop

but not, "for(i in Object)" starts from last index to first..


try following code:
-----------
a = new Array();

b = new Array();
b["Eng"] = {relSize:"+0", txt:"Now is the time"} ;
b["Spa"] = {relSize:"+1", txt:"Ahora es el tiempo"} ;

t = "#main";
a[t] = b;

b = new Array();
b["Eng"] = {relSize:"+0", txt:"for all good men"} ;
a["#2nd"] = b;

for ( i in a){
      trace(a[i]["Eng"].relSize + ", " + a[i]["Eng"].txt);
}
-----------

Rgds
Aneesh
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:Donelson
ID: 17048916
Aneesh

Yes, thanks, I knew about "for(i in foo)", ...

but is there a way to get the number of elements Without Counting them in a loop?

0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 17048946
sorry,
no other way....
0
 

Author Comment

by:Donelson
ID: 17049945
Thanks Aneesh - nice to speak with you again!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question