Question : Flex Shared Object - Array Collection access

Hello,

I am trying to use a shared object to save an array collection of city objects. Each city object contains basic string properties (i.e. CITYName, State, Zipcode, etc...).  I can successfully write the shared object however, upon retrieval i am unable to access the inner properties of a given city object.

What am I doing wrong in terms of accessing the object properties contained within the array collection object? (See code below)

Thanks,

-rw



 
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
var tempAC:ArrayCollection = new ArrayCollection();


if( getObjects())
{
    tempAC = getObject(); //returns the only shared object i currently use.

    Alert.show("temp length " + tempAC.length.toString()); // current length returned is '7902' cities as expected

var i:int;
var cityObj:Object;
var tmpString:String;

//loop through array collection and collect city values;
for(i=0; i < tempAC.length(); i++)
{
    
     cityObj= new Object();
     cityObj= tempAC[i];

     tmpString += "City Name: "+ cityObj[i].CITYName.toString() + "  "+ cityObj.hasOwnProperty("CITYName") +"\r\n" ;

} 

  Alert.show(tmpString);   //this alert displays "City Name [object Object] true" for all entries in the array collection

}

Answer : Flex Shared Object - Array Collection access

you got the Object from your array with this line:

    cityObj= tempAC[i];

So cityObject is of type Object, but in your tmpString creation you're indexing cityObj like it's an Array or ArrayCollection

Change that line to the following:

tmpString += "City Name: "+ cityObj.CITYName.toString() + "  "+ cityObj.hasOwnProperty("CITYName") +"\r\n"
Random Solutions  
 
programming4us programming4us