views:

213

answers:

1

Is it possible to execute a "foreach" through each of my SharedObjects?

Something like this . . .

_so = SharedObject.getLocal("test","/");
foreach (var item:Object in _so)
{
    // print key name and value
}
A: 

I'm not sure I understand. 1.Do you want to loop through all your Shared Objects ? 2.Do you want to loop through all your objects inside the data property of a SharedObject ?

1.Assuming sharedObjects is an array containing SharedObject instances

var sharedObjects:Array = ['test','fred','louie'];
var sharedObjectsData:Array = [];

for(var i:int = 0 ; i < sharedObjects.length ; i++){
sharedObjectsData.push(SharedObject.getLocal(sharedObjects[i],"/").data);
}

//or something like that

2.Try using an old school for in loop.

for(var i in _so.data){
trace('property: ' + i + ' value: ' + _so.data[i]);
}

Hope it helps!

George Profenza