matt poole
10-21-2003, 11:52 AM
Im trying to store multiple levels of data in a shared object by using a reference to an array in the setProperty() method in server-side AS.
I know the data is going in cos I can trace it using the netConnection debugger. The probelm is reading the data out of the so on the client.
Can anyone see whats going wrong??
heres the SS AS
application.onAppStart = function()
{
//Get the server shared object dataso
application.dataso = SharedObject.get("dataso", false);
LocalClientData = new Array();
trace("Array Created");
application.dataso.setProperty("RemoteClientData", LocalClientData);
application.nextId = 0;
}
application.onConnect = function(newClient, lastname, firstname)
{
trace("Next ID: " + application.nextId);
newClient.id = application.nextId;
trace("New Client ID: " + newClient.id);
application.acceptConnection(newClient);
trace("Accepted Client connection");
trace("Number of Clients: " + application.clients.length);
LocalClientData[newClient.id] = new Array();
LocalClientData[newClient.id][0] = firstname;
LocalClientData[newClient.id][1] = lastname;
trace("Client Property Array added to ClientData Array");
application.dataso.setProperty("RemoteClientData", LocalClientData);
application.nextId++;
//Proves that each client exists in the shared obj
newarr = application.dataso.getProperty("RemoteClientData");
for ( var i in newarr) {
for ( var j in newarr[i]) {
trace(newarr[i][j]);
}
}
}
application.onDisconnect = function(client)
{
trace("Client ID: " + LocalClientData[client.id][0] + " " + LocalClientData[client.id][1] + " has disconnected");
}
heres the client side:
#include "NetDebug.as"
// Open connection to the server
client_nc = new NetConnection();
// If connection is closed, clear the History and the list
client_nc.onStatus = function(info) {
trace("Level: " + info.level + newline + "Code: " + info.code);
}
function doConnect() {
if (Connect_btn.getLabel() == "Login") {
// is the application instance.
_root.client_nc.connect("rtmp:/class_shared_objects/myInstance", _root.surname.text, _root.firstname.text);
// attached connection light to net obj
//light_mc.connect(client_nc);
// Update button label
Connect_btn.setLabel("Logout");
// Create a remote shared object to keep track
// of the users. The value client_nc.uri is the URI of the
// NetConnection the shared object will use to connect to the
// server. I.e., the one just created.
dataso = SharedObject.getRemote("dataso", _root.client_nc.uri, false);
// Attach the shared object to 'client_nc'
dataso.connect(_root.client_nc);
//Read from shared obj
trace(dataso.data[0]); // <= heres the problem bit
} else if (Connect_btn.getLabel() == "Logout") {
// Close connection
_root.client_nc.close();
// Rest button label
Connect_btn.setLabel("Login");
}
}
cheers for your help:)
I know the data is going in cos I can trace it using the netConnection debugger. The probelm is reading the data out of the so on the client.
Can anyone see whats going wrong??
heres the SS AS
application.onAppStart = function()
{
//Get the server shared object dataso
application.dataso = SharedObject.get("dataso", false);
LocalClientData = new Array();
trace("Array Created");
application.dataso.setProperty("RemoteClientData", LocalClientData);
application.nextId = 0;
}
application.onConnect = function(newClient, lastname, firstname)
{
trace("Next ID: " + application.nextId);
newClient.id = application.nextId;
trace("New Client ID: " + newClient.id);
application.acceptConnection(newClient);
trace("Accepted Client connection");
trace("Number of Clients: " + application.clients.length);
LocalClientData[newClient.id] = new Array();
LocalClientData[newClient.id][0] = firstname;
LocalClientData[newClient.id][1] = lastname;
trace("Client Property Array added to ClientData Array");
application.dataso.setProperty("RemoteClientData", LocalClientData);
application.nextId++;
//Proves that each client exists in the shared obj
newarr = application.dataso.getProperty("RemoteClientData");
for ( var i in newarr) {
for ( var j in newarr[i]) {
trace(newarr[i][j]);
}
}
}
application.onDisconnect = function(client)
{
trace("Client ID: " + LocalClientData[client.id][0] + " " + LocalClientData[client.id][1] + " has disconnected");
}
heres the client side:
#include "NetDebug.as"
// Open connection to the server
client_nc = new NetConnection();
// If connection is closed, clear the History and the list
client_nc.onStatus = function(info) {
trace("Level: " + info.level + newline + "Code: " + info.code);
}
function doConnect() {
if (Connect_btn.getLabel() == "Login") {
// is the application instance.
_root.client_nc.connect("rtmp:/class_shared_objects/myInstance", _root.surname.text, _root.firstname.text);
// attached connection light to net obj
//light_mc.connect(client_nc);
// Update button label
Connect_btn.setLabel("Logout");
// Create a remote shared object to keep track
// of the users. The value client_nc.uri is the URI of the
// NetConnection the shared object will use to connect to the
// server. I.e., the one just created.
dataso = SharedObject.getRemote("dataso", _root.client_nc.uri, false);
// Attach the shared object to 'client_nc'
dataso.connect(_root.client_nc);
//Read from shared obj
trace(dataso.data[0]); // <= heres the problem bit
} else if (Connect_btn.getLabel() == "Logout") {
// Close connection
_root.client_nc.close();
// Rest button label
Connect_btn.setLabel("Login");
}
}
cheers for your help:)