0

我一直在玩共享对象,试图了解它们是如何运作的。在这个基本的实际示例中,我选择了 sharedObject.getRemote 而不是使用 getLocal,因为我使用的是 Flash Media Server。我已经更新了 setProperty method() 中某些数据的值,然后如果该数据存在,我会尝试从 data 属性中检索它。当我运行应用程序时,输出面板应该是:

paris
250
true

但是,它声明了对未定义属性的访问。你能看看代码并告诉我我做错了什么吗?

import flash.net.NetConnection;
import flash.events.NetStatusEvent;
import flash.net.SharedObject;
import flash.events.SyncEvent;

var nc:NetConnection = new NetConnection();

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

nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);

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

    case "NetConnection.Connect.Close":
    trace("Closing time");
    break;

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

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

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

so.connect(nc);

so.addEventListener(SyncEvent.SYNC, seeSo);

 function seeSo(event:SyncEvent):void{
    trace(so.changeList[0].code);
    switch(so.changeList[0].code){
        case "clear":
        loadSo();
        break;

        case "Success":
        showSo();
        break;
    }


}

function loadSo():void{
    so.setProperty("city", "Paris");
    so.setProperty("bunch", "250");
}       so.setProperty("verity", "true");

function showSo():void{
    trace(so.data.city);
    trace(so.data.bunch);
}       trace(so.data.verity); 
4

0 回答 0