all groups > macromedia flash flashcom > january 2007 >
You're in the

macromedia flash flashcom

group:

Convert Shared Object properties into ordered array


Convert Shared Object properties into ordered array NormC_CAE
1/25/2007 3:18:38 PM
macromedia flash flashcom: I need to put the shared object data (that contains the client names) into an
ordered array.

The following is NOT useful:
for (var i in _chatSO.data) {
if (_chatSO.data[i] != null) {
var clientObj = _chatSO.data[i];
users.push(clientObj.username);
}
}

That doesn't solve my problem because each client will end up with an array of
different order, e.g., [client1, client2, client3] and [client2, client1,
client3] etc.

Context: Multiplayer game where I make 2 teams and assign a number and colour
(color) to each player. Each client (player) that joins needs to create movie
clips representing the previously joined players, each labeled with a number.
Unless they have access to the same array, it can't be done.

Thank you,
Norm (new to FMS)

Re: Convert Shared Object properties into ordered array B_Shack
1/25/2007 3:57:43 PM
Norm,
Here is the process for pushing so data into an array...

Shack

// Object iterator
function iterateObject(obj:Object):Void
{
if(obj != undefined){
for(var prop in myObject){
trace("Property :" + prop + "\tValeu :" + myObject(prop));
}
} else {
trace("Object required");
}
}
function reverseObject(obj:Object):Void
{
var a = [];
for ( var p in obj )
{
a.push ( { key: p, value: obj[p] } ); }

var len = a.length;
for ( var i = 0; i < len; i++ )
{
var item = a[i];
var key = item.key;
var value = item.value;
}
}

/*
Shared Object Info

You can store objects, or arrays of objects in a shared object property. The
server side code would look something like this:

my_so = SharedObject.get("someSharedObject", false);
myObject = new Object();
myObject["childObject1"] = new Object();
myObject["childObject2"] = new Object();
my_so.setProperty("somePropertyName", myObject);

So, now you have a property in the shared object named somePropertyName, and
its value is and object with two child objects. If you then wanted to
manipulate the object, you would do something like this:

myObject = my_so.getProperty("somePropertyName");
var someVar="someValue";
myObject.childObject1["somevar"] = someVar;
my_so.setProperty("somePropertyName", myObject);

What we did here was read the value of the shared object property into a
variable, add a variable to one of the child objects, and write the parent
object back into the shared object property.

A shared object can have as many properties as you need (a shared object is
still an object after all), you you can use separate properties to manage
separate arrays or arrays of objects.
*/

AddThis Social Bookmark Button