0

我正在开发简单的聊天应用程序,我的主类是 asac.as。单击发送按钮时,它给了我异常 Unhandled AsyncErrorEvent:。text=Error #2095: flash.net.SharedObject 无法调用回调receiveMessag,连接成功,不知道为什么会出现错误。chat.asc 是服务器上的聊天文件。谁能告诉我有什么问题?

public class ASAC
{
    protected var so:SharedObject;
    protected var chatStr:String;
    protected var nc1:NetConnection;
    protected var myResponder:Responder = new Responder(onReply);
    protected var chatMsgPanel:TextArea;
    public var Vg:Group = new Group()

    public function ASAC()
    {
        super();

    }
    public function addChatPanel():void{




        chatMsgPanel = new TextArea();
        chatMsgPanel.width = 240;
        chatMsgPanel.height = 240;
        chatMsgPanel.x = 2;


        var msgInput:TextInput = new TextInput()
        msgInput.x = 2;
        msgInput.y = chatMsgPanel.height+1;
        msgInput.width = 165


        var msgSendBtn:Button = new Button()
        msgSendBtn.x = msgInput.width + 5;
        msgSendBtn.y = chatMsgPanel.height+1;
        msgSendBtn.label = "Send"
        msgSendBtn.addEventListener(MouseEvent.CLICK, msgSend);

        var roomLabel:Label = new Label();
        roomLabel.text = "Rooms";

        Vg.addElement(chatMsgPanel)
        Vg.addElement(msgInput)
        Vg.addElement(msgSendBtn);
    }
    public function chatConnection():void{

        nc1 = new NetConnection();

        nc1.client = this
        nc1.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        nc1.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        nc1.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler)
        nc1.objectEncoding = flash.net.ObjectEncoding.AMF0;
        nc1.connect("rtmp:/simple_chat");

        SharedObject.defaultObjectEncoding  = flash.net.ObjectEncoding.AMF0;            
        so = SharedObject.getRemote("message", nc1.uri, false);
        so.client = this;
        so.addEventListener(SyncEvent.SYNC, soOnSync);
        so.connect(nc1);


    }
    public function asyncErrorHandler(event:AsyncErrorEvent):void 
    {
        Alert.show("========================= asyncErrorHandler"+"\r");
        //ignore
    }
    private function soOnSync(event:SyncEvent):void
    {
        chatMsgPanel.text += "soOnSync \n";

        for (var prop:String in so.data) 
        {
            chatMsgPanel.text += "prop "+prop+" = "+so.data[prop]+"\n";

        }

    }


    public function netStatusHandler(event:NetStatusEvent):void 
    {
        chatMsgPanel.text += "netStatusHandler";



        for ( var prop:String in event.info)
        {
            chatMsgPanel.text += "prop : "+prop+" = "+event.info[prop]+"\n";


        }

        chatMsgPanel.text += event.info.code+"\n\n";
    }

    private function securityErrorHandler(event:SecurityErrorEvent):void 
    {
        chatMsgPanel.text += "securityErrorHandler \n";

        for (var prop:String in event) 
        {
            chatMsgPanel.text += "prop "+prop+" = "+event[prop]+"\n";
        }

    }
    public function msgSend(e:Event):void{

        nc1.client = this;
        so.client   = this;
        nc1.call("chat.sendMessage", myResponder, chatMsgPanel.text);

    }
    private function onReply(result:Object):void 
    {
        if (!result)    return;

        chatMsgPanel.text += "onReply : resultObj = " + result+"\n";
        for ( var prop:String in result)
        {
            chatMsgPanel.text += "prop : "+prop+" = "+result[prop]+"\n"; 
        }

    }

    }
}

服务器上的聊天.asc

try { var dummy = Chat; } catch ( e ) { // #ifndef Chat

/**
 * Chat component class
 */
Chat = function() 
{
    // Get a non persistent shared object for sending broadcasts
    this.message_so = SharedObject.get( "message", false );
}

// send a message to all others participating in the chat session
Chat.prototype.sendMessage = function( mesg ) 
{
    this.message_so.send( "receiveMessage", mesg );
}

chat    = new Chat();

} // #endif
4

0 回答 0