Sending an object with arrays with objects in them

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Post Reply
TreeTree
Posts: 12
Joined: 28 May 2010, 00:22

Sending an object with arrays with objects in them

Post by TreeTree »

Is that possible with the sendObjectToGroup method?

Code: Select all

object.str = event.target.data.Str;
object.dex = event.target.data.Dex;
object.vit = event.target.data.Vit;
object.mag = event.target.data.Mag;
object.x = event.target.data.X;
object.y = event.target.data.Y;
var playerskillids:Array = event.target.data.SkillIDs.split (",");
var playerskillexps:Array = event.target.data.SkillExps.split (",");
var playerskilllevels:Array = event.target.data.SkillLevels.split (",");
playerskillids.splice (0, 1);
playerskillexps.splice (0, 1);
playerskilllevels.splice (0, 1);
object.playerskillids = playerskillids;
object.playerskillexps = playerskillexps;
object.playerskilllevels = playerskilllevels;

Code: Select all

var xml:XML = new XML (event.target.data);
var xmllist:XMLList = xml.weapon;
var weaponstats:Array = new Array ();
			
for each (var weapon:XML in xmllist) {
	weaponstats.push ({id:weapon.id, name:weapon.name, type:weapon.type, level:weapon.level, min:weapon.min, max:weapon.max});
}

object.weaponstats = weaponstats;
So I have the first function which just makes a new object and sets all the variables and their values. I even gave the object arrays with 10 elements each. All the values from the first code is received from a PHP file and database.

Then I load an XML and create an object with the values and push it into an array and set that array into my first object. Pretty much the same as the arrays in the first code except this array has objects as elements.

After I sent the object using the server method another class receives it and all the values, including the 3 arrays with the player skill info, are correct, except the XML array. When I trace the array it shows just 2 commas, so 3 elements. When I trace the length of the array it returns 3. When I trace each element's values like the id and name and level it returns undefined. So it still has the proper length but what happened to the values?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Yes
it's possible to send nested data with arrays/objects.
Types supported are: Number,String,Boolean,Array,Object.

The XML object is not supported by the serializer and that's why you don't get it on the other end. You should maybe call the toString() method to "flatten" it.

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply