PDA

View Full Version : Help with shared objects


MaxVT103
08-03-2005, 07:04 PM
I am new to flashcomm and I am having tons of problems with SharedObjects. Right now all I am trying to do is create my own people list and am trying to use SharedObjects to do it but am running into problems of them not sharing anything in between or if they are even getting the data. I know I have tons of bugs probobly, but the book I am reading and using for reference isn't doing me much good because its tutorial didn't work on the SharedObject. Here is the code I am using so far.

Server-side:

load("components.asc");
//The first function that is run when the application is started, it initialises the variables
application.onAppStart = function()
{
//creation of server variables//
//----------------------------//
user_names = []; //creates a blank array to contain the users names
user_names[0] = 0; //initialises the first member of the array to having no users
user_conversations = []; //creates a blank array to hold the users conversation
user_conversations[0] = 0; //initialises the conversations to having none
chat_room = []; //creates a blank array to hold chat room variables


//initializing the variables to now be shared objects//
//---------------------------------------------------//
Users_so = SharedObject.get("Users", false); //initialises the SharedObject
Users_so.setProperty("UserNames", user_names); //attaches the user_names array to the shared object

Conversations_so = SharedObject.get("Conversations",false); //initialises the shard object for private conversations
Conversations_so.setProperty("Private_IM",user_conversations); //attatches the array that holds the conversations

Chat_so = SharedObject.get("Chat",false); //initialises the chat array
Chat_so.setProperty("Global_Chat",chat_room); //attaches the chat array to hold the global conversation
trace("Application Started");
//end of code for onAppStart function
}

//This function runs when a user connects to the application
application.onConnect = function(newClient,UserName,UserPassword)
{
//accepts the user to the connection
application.acceptConnection(newClient);

//adds the user to the usernames
user_names.push(UserName); //actually adds the users name to the list
user_names[0]++; //adds the user
trace("User Successfully added");
//updates the username array
Users_so.setProperty("UserNames",user_names);
trace("UserNames updated");
}


And here is what I am trying to use to access it on the client side


//enabling the netconnection debugger
#include "NetDebug.as"

//beginning coding of the net connection
var myConnection_nc:NetConnection = new NetConnection();

//trace function
myConnection_nc.onStatus = function(info){
trace("LEVEL: " + info.level + " CODE: " + info.code);
}
//connect function
appLogin = function(){

//making the connectio to the server
myConnection_nc.connect("rtmp://***.**.*.***/odu_flash_chat",login_txt.text,login_txt.text);
initSharedObjects();
}
connectionLight_mc.connect(myConnection_nc);

var connect_pbListener:Object = new Object();
connect_pbListener.click = function()
{
appLogin();
}
connect_pb.addEventListener("click",connect_pbListener);

initSharedObjects = function()
{
var Users_so:SharedObject = SharedObject.getRemote("Users_so",myConnection_nc.uri,false);
name_txt.text = Users_so.data.UserNames[0];
}
Users_so.onSync = function(info)
{
if(info[UserNames].code == "change")
{
name_txt.text = Users_so.data.UserNames[0];
}
}

By the way the book is: Macromedia Flash Communication Server MX. by: Kevin Towes

theflash
08-11-2005, 01:41 PM
you are using onSync in wrong way....
you will get an array of all the slots in so that were changed