Skip to main content
Inspiring
July 14, 2007
Answered

Remote Shared Object kicking my butt

  • July 14, 2007
  • 1 reply
  • 308 views
After 4 days, I'm still stuck with what should be a simple learning exercise. I'm not a newbie developer by any means so this shouldn't be beyond me. After a couple weeks of reading, I'm now trying to do some bite size exercises to ramp up on Communication Server (using Flex as the back end ). I'm missing something in my understanding and could use a good quick swift kick in the pants to get me going.

All I want to do is created a server side remote object, then when a client connects, send and add a simple string to the remote object. Then have the client receive the update and display the information in a text box. Below is the code I'm trying to use, cleaned up a bit (so their might be a typo or two). It captures the idea of what I'm trying to do.

I'm not sure what I'm doing wrong. The idea is to send a test string to the server on connect, and have the server add it to the server side shared object. In theory, I think, this will fire the client's onsync event to send the change back to the client. The onsync fires but I'm not seeing the information in the client... just get an 'undefined'.. What am I missing? Save me a week of pulling out my hair, if you can, please!

Thank you!

==================server asc================================
application.onAppStart = function()
{
trace("onAppStart");
//create server side shared object
test_so = SharedObject.get("myTestSharedObject");
}
application.onConnect = function (client, someTextForDisplaying)
{
test_so.setProperty(myProperty, someTextForDisplaying);
return true;
}

==================client ================================
var my_so: SharedObject;
var nc:NetConnection;

//this is triggered by a UI button click
function createConnection():void
{
//connect to the server
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler );
nc.objectEncoding = ObjectEncoding.AMF0;
//
nc.connect( "rtmp:/testApplication", "testString");

}

//connected so now connect the client to the server side remote object
function netStatusHandler( event:NetStatusEvent ):void
{
switch( event.info.code ) {
case "NetConnection.Connect.Success":
// Connection succeeded now create components
// Simple User shared object and event handling
SharedObject.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;

my_so = SharedObject.getRemote("myTestSharedObject", nc.uri, false);
my_so.addEventListener( SyncEvent.SYNC, usersSyncHandler );
my_so.connect( nc );
break;
case "NetConnection.Connect.Rejected":
Alert.show( "Connection Rejected.", "Something went wrong" );
break;

}
}

//this is the event fired when the remote shared object changes
function usersSyncHandler( event:SyncEvent ):void
{
//show the returned information on the UI
txtDisplay = event.target.data.myProperty;
//or
txtDisplay = txtDisplay + my_so.data.myProperty;
}
    This topic is closed to new replies. Start a new post to keep the conversation going.
    Correct answer jonpor
    Solved it... not sure what the problem was but it is working finally.......

    1 reply

    jonporAuthorCorrect answer
    Inspiring
    July 14, 2007
    Solved it... not sure what the problem was but it is working finally.......