I asked this question in StackOverflow seven months ago, but apparently no one could give me a satisfactory answer. I have searched the entire Internet to no avail. So I am posting this here again, in the hope that this can be solved for the benefits of all. Please bear with me as I really need this to be done.
Here is my code so far.
import flash.net.SharedObject;
import flash.events.SyncEvent;
import flash.events.MouseEvent;
var nc:NetConnection;
var so:SharedObject;
nc = new NetConnection();
nc.client = { onBWDone: function():void{} };
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nc.connect("rtmp://localhost:1935/live");
var t = new TextField();
addChild(t);
var c = new TextField();
c.y=100;
c.text="SET SO";
addChild(c);
c.addEventListener('click',sd);
function sd(e:MouseEvent):void{
so.setProperty("total",3);
//so.setDirty("total");
//trace("a"+so.data.total);
}
function onNetStatus(event:NetStatusEvent):void{
if(event.info.code == "NetConnection.Connect.Success"){
so = SharedObject.getRemote("shObj",nc.uri);
so.addEventListener(SyncEvent.SYNC,syncHandler);
so.connect(nc);
so.setProperty("total",2);
}
}
function syncHandler(event:SyncEvent):void{
if (so.data.total) {
t.text = so.data.total;
}
}
I expected to see the number 3 as I clicked the text 'SET SO'. However, it seems that syncHandler is never fired. What should I do to make it work? Have I missed out something? Was the server correctly linked?