Flex 3 简单聊天:代码审查请求;它适合现实生活中的应用吗?
我设法使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看聊天示例 在 Tour de Flex 中查看使用 BlazeDS 或 LCDS 的示例。
Check out the Chat sample in Tour de Flex for an example that uses BlazeDS or LCDS.