Flex 3 简单聊天:代码审查请求;它适合现实生活中的应用吗?

发布于 2024-08-08 20:38:46 字数 2390 浏览 2 评论 0原文

我设法使用 Flex 3 / AS3 构建了一个简单的聊天,我想知道它是否适合现实生活中的应用程序?

mxml和代码 (code.as)

<?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init();">
        <mx:Script source="code.as" />
        <mx:TitleWindow title="Shat">
        <mx:VBox>
        <mx:TextArea width="236" id="eShat" height="190"/>
            <mx:HBox>
                <mx:TextInput id="eMessage" enter="sendMessage()"/>
                <mx:Button label="Send" id="eSend"  />
                </mx:HBox>
        </mx:VBox>
        </mx:TitleWindow>
    </mx:Application>

这是操作脚本中的

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

var nc:NetConnection = null;
var so:SharedObject = null;

private var chatname:String = "mychat";

private function init():void
{
    if(nc == null)
    {
        nc = new NetConnection();       
        nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        nc.connect("rtmp://localhost/simplu");
    }
}

private function netStatusHandler(event:NetStatusEvent):void 
{
    if (event.info.code == "NetConnection.Connect.Failed") 
    {
        trace(event.info.code);
    }
    if (event.info.code == "NetConnection.Connect.Rejected") 
    {
        trace(event.info.code);
    } 
    else if (event.info.code == "NetConnection.Connect.Success") 
    {
        so = SharedObject.getRemote(chatname, nc.uri, false);       
        so.addEventListener(SyncEvent.SYNC, syncHandler);               
        so.connect(nc);
        eSend.addEventListener(MouseEvent.CLICK, eSendClick);       
    } 
    else if (event.info.code == "NetConnection.Connect.Closed") 
    {
        trace(event.info.code);
    }
}

private function syncHandler(event:SyncEvent):void
{   
     if(so.data[chatname] != undefined) 
     {
        eShat.htmlText += so.data[chatname] + "\n";
        eShat.verticalScrollPosition = eShat.maxVerticalScrollPosition;
     }
}

private function eSendClick(event:Event):void
{
    sendMessage();
}

private function sendMessage():void
{
    so.setProperty(chatname, eMessage.text);    
    eMessage.text = "";
}

i managed to put together a simple chat using flex 3 / AS3, and i want to know if it is good for a real life application?

here is the mxml

<?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init();">
        <mx:Script source="code.as" />
        <mx:TitleWindow title="Shat">
        <mx:VBox>
        <mx:TextArea width="236" id="eShat" height="190"/>
            <mx:HBox>
                <mx:TextInput id="eMessage" enter="sendMessage()"/>
                <mx:Button label="Send" id="eSend"  />
                </mx:HBox>
        </mx:VBox>
        </mx:TitleWindow>
    </mx:Application>

and code in action script (code.as)

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

var nc:NetConnection = null;
var so:SharedObject = null;

private var chatname:String = "mychat";

private function init():void
{
    if(nc == null)
    {
        nc = new NetConnection();       
        nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        nc.connect("rtmp://localhost/simplu");
    }
}

private function netStatusHandler(event:NetStatusEvent):void 
{
    if (event.info.code == "NetConnection.Connect.Failed") 
    {
        trace(event.info.code);
    }
    if (event.info.code == "NetConnection.Connect.Rejected") 
    {
        trace(event.info.code);
    } 
    else if (event.info.code == "NetConnection.Connect.Success") 
    {
        so = SharedObject.getRemote(chatname, nc.uri, false);       
        so.addEventListener(SyncEvent.SYNC, syncHandler);               
        so.connect(nc);
        eSend.addEventListener(MouseEvent.CLICK, eSendClick);       
    } 
    else if (event.info.code == "NetConnection.Connect.Closed") 
    {
        trace(event.info.code);
    }
}

private function syncHandler(event:SyncEvent):void
{   
     if(so.data[chatname] != undefined) 
     {
        eShat.htmlText += so.data[chatname] + "\n";
        eShat.verticalScrollPosition = eShat.maxVerticalScrollPosition;
     }
}

private function eSendClick(event:Event):void
{
    sendMessage();
}

private function sendMessage():void
{
    so.setProperty(chatname, eMessage.text);    
    eMessage.text = "";
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑梦风尘 2024-08-15 20:38:46

查看聊天示例 在 Tour de Flex 中查看使用 BlazeDS 或 LCDS 的示例。

Check out the Chat sample in Tour de Flex for an example that uses BlazeDS or LCDS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文