WEB-INF > flex > message-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<service id="message-service"
class="flex.messaging.services.MessageService">
<adapters>
<adapter-definition id="actionscript" class="flex.messaging.services.messaging.adapters.ActionScriptAdapter" default="true" />
<adapter-definition id="jms" class="flex.messaging.services.messaging.adapters.JMSAdapter"/>
</adapters>
<destination id="chat">
<properties>
<network>
<session-timeout>0</session-timeout>
</network>
<server>
<max-cache-size>1000</max-cache-size>
<message-time-to-live>0</message-time-to-live>
<durable>false</durable>
</server>
</properties>
<channels>
<channel ref="my-rtmp"/>
</channels>
</destination>
</service>
chatting1.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12" creationComplete="initApp()">
<mx:Script>
<![CDATA[
import mx.messaging.messages.AsyncMessage;
import mx.messaging.events.MessageEvent;
[Bindable]
public var userId:String;
private function initApp():void{
consumer.subscribe();
currentState = "logon";
}
private function logon():void{
userId = tUserId.text;
currentState = "chat";
}
private function send():void{
var messge:AsyncMessage = new AsyncMessage();
messge.body.userId = userId;
messge.body.msg = msg.text;
producer.send(messge);
msg.text = "";
}
public function messageHandler(event:MessageEvent):void{
log.text += event.message.body.userId + " : " + event.message.body.msg + "\n";
}
]]>
</mx:Script>
<mx:Producer id="producer" destination="chat"/>
<mx:Consumer id="consumer" destination="chat" message="messageHandler(event)"/>
<mx:Panel id="panel" width="100%" height="100%" verticalAlign="middle" horizontalAlign="center">
<mx:ControlBar id="cb" height="44"/>
</mx:Panel>
<mx:states>
<mx:State name="logon">
<mx:AddChild relativeTo="{panel}">
<mx:HBox>
<mx:Label text="User ID : "/>
<mx:TextInput id="tUserId" enter="logon()"/>
<mx:Button label="Logon" click="logon()"/>
</mx:HBox>
</mx:AddChild>
</mx:State>
<mx:State name="chat">
<mx:SetProperty target="{panel}" name="title" value="접속자 ID : [{userId}]" />
<mx:AddChild relativeTo="{panel}">
<mx:TextArea id="log" width="100%" height="100%"/>
</mx:AddChild>
<mx:AddChild relativeTo="{cb}">
<mx:HBox width="100%" paddingTop="0" paddingBottom="0">
<mx:TextInput id="msg" enter="send()" width="100%"/>
<mx:Button label="메시지전송" click="send()"/>
</mx:HBox>
</mx:AddChild>
</mx:State>
</mx:states>
</mx:Application>
'Study > Programming' 카테고리의 다른 글
자바 형변환 (0) | 2010.02.11 |
---|---|
자바 가비지, 컬렉션(Gabage Collection), 가비지 컬렉터(Gabage Collector) (1) | 2010.01.20 |
이클립스 FLEX 프로젝트 생성방법 (0) | 2009.08.10 |
JSP 게시판 만들기 (2) | 2009.07.27 |
JAVA Study (0) | 2009.07.21 |