0

There appears to be an error in the Adobe documentation in regards using the shared object.send(). I am trying to execute the send method to all clients.

I copied the client and server-side code from Adobe and I am unable to invoke the function. This is my compile error in the output

Line 31 1119: Access of possibly undefined property doSomething through a reference with static type flash.net:SharedObject.

Any suggestions how i can fix this to as3 novice. Please can anyone help me?

var nc:NetConnection = new NetConnection();

nc.connect("rtmfp://localhost/submitSend");

nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);

function netHandler(event:NetStatusEvent):void{
    switch(event.info.code){
        case "NetConnection.Connect.Sucess":
        trace("Connecting...");
        break;

        case "NetConnection.Connect.Failed":
        trace("Unable to connect up");
        break;

        case "NetConnection.Connect.Rejected":
        trace("Whoops");
        break;
    }
}

var so:SharedObject = SharedObject.getRemote("mySo", nc.uri, true);

so.connect(nc);

so.doSomething = function(str) {
    // Process the str object.
};

Server side:

var so = SharedObject.get("mySo", true);
so.send("doSomething", "This is a test");
duTr
  • 714
  • 5
  • 21
marcus
  • 11
  • 2

1 Answers1

0

As said in my previous comment, a link to the document you're refering to would be welcome to help people helping you...

Here is already some points that ought to be mentionned:

  • You should add your event listeners before any call to connect().
  • You should connect your shared object only once you received the NetConnection.Connect.Success event (by the way, you have a typo in your sample on this name)
  • You should set you class instance as the client of your shared object.

I'm not sure all of this will fix your issue but you can try this:

var nc:NetConnection = new NetConnection();

private function netHandler(event:NetStatusEvent):void
{
    switch(event.info.code)
    {
        case "NetConnection.Connect.Success":
        {
            trace("Connecting...");
            connectSharedObject();
            break;
        }
        case "NetConnection.Connect.Failed":
        {
            trace("Unable to connect up");
            break;
        }
        case "NetConnection.Connect.Rejected":
        {
            trace("Whoops");
            break;
        }
    }
}

private function connectSharedObject():void
{
    var so:SharedObject = SharedObject.getRemote("mySo", nc.uri, true);
    so.client = this;
    so.connect(nc);
}

public function doSomething(str:String):void
{
    // Process the str object.
}

nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);
nc.connect("rtmfp://localhost/submitSend");
duTr
  • 714
  • 5
  • 21
  • Thank You duTr. Appreciate the help and comments. Sorry here's the link http://livedocs.adobe.com/flashmediaserver/3.0/hpdocs/help.html?content=00000371.html I tested the code and connected to the server just fine. This may sound like a stupid question. But, should i receive any notice or response in the output or admin console's live log in regards to the string message? Because i am unsure if the string message i sent succeeded or failed..Thanks – marcus May 10 '13 at 12:35
  • I can't check right now, but I think your server-side call to `so.send("doSomething", "This is a test");` should return `true` if the client method has been called, and `false` otherwise. – duTr May 10 '13 at 23:57
  • Sorry to be a nuisance..But I have slightly altered my server-side code it now looks like this application.onConnect = function(client){ trace("In onConnect"); application.acceptConnection(client); so = sharedObject.get("foo", true); so.send("doSomething", "this is a test"); It doesn't appear that the server is calling the sharedobject.send() hence the method is not been invoked to the connecting clients. In the client-side I have added onSync handler to try invoke a connection to the shared object to call the so.send but that was unsuccessful. I find way someday! Its not rocket science lol – marcus May 13 '13 at 13:40
  • If the `send()` call is performed on client connection, then I think it's normal your client method is not called as the client didn't connect the shared object yet! I'm not using FMS version 3 but the code I provided should work! You can use `setInterval()` in your `onConnect` handler to perform the call later and give time for the client to connect – duTr May 13 '13 at 22:13
  • Understood, thanks for all your help! That's all I needed to know. – marcus May 15 '13 at 13:46