PDA

View Full Version : SharedObject.onSync


galak
03-20-2009, 04:04 AM
Ok here it goes...

Hi guys, I'm totally new to FMS, but I already have to get down to understanding it real quick, got a dead line for next week to hand a multi conferencing system (but that's not the problem). So here is the question:

I have two similar swf, panel.swf and panel_admin.swf, they are set in the same folder on the server.

I would like them both to be watching the same serverSide object and launch a function if it changes. So the code I have is he following:

Server side

application.onAppStart = function(){
counterSO = SharedObject.get("control_panel", true)
counterSO.setProperty("user", '')
counterSO.setProperty("action", '')

}

application.onConnect = function(clientObj, action, user){
application.acceptConnection(clientObj);
if(user != undefined && action != undefined){
counterSO.setProperty("user", user)
counterSO.setProperty("action", action)
clientObj.call("check_func", null, user, action);
}else{
counterSO.setProperty("user", "")
counterSO.setProperty("action", "")
}



}


On the admin side there is a button that calls the server, changes the Shared Object like this:

function call_fms(action, user){
conn_nc.connect(dir,action,user);
};


then the other swf has the following code

var conn_nc:NetConnection = new NetConnection();
var dir:String = "rtmp:/admin_panel";
conn_nc.onStatus = function(info) {
check_conn();
};
function check_conn() {
var counterSO = SharedObject.getRemote("control_panel", dir, true);
counterSO.onSync = function(list) {
DO_SOMETHING_HERE()
};
counterSO.connect(conn_nc);
}

conn_nc.connect(dir);


The thing I don't understand is that when I paste the user code in the admin file, well it works perfectly, but once the code is in two separate swf, they stop communicating.

So I suppose my question is how do I build a listener on one swf that is warned when the shared object is modified by another swf?

Thanks a lot guys

David

galak
03-22-2009, 01:23 AM
Ok,

For anyone that could be interested, I found a work around to the onSync issue. since it doesn't seem very reliable, that is it doesn't always update in real time, what I did, is instead of changing the variable of the sharedObject a wait for it to sync,

I call the connection again and pass my variables through it (the on connect is very reliable) and in the onConnect function I have the sharedObject call a function to on all users passing the said variables. It works like a charm !

Cheers,

David