flex聊天 发送QQ表情

代码:需要项目代码可以给我回帖并注明邮箱,或者直接去原出处下载(需要注册论坛ID)。

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> <mx:ArrayCollection id="arrColl"> <mx:source> <mx:Array id="arr"> <mx:Object data="0" tp="微笑" label="" icon="img/Face/0.swf"/> <mx:Object data="1" tp="撇嘴" label="" icon="img/Face/1.swf"/> <mx:Object data="2" tp="撇嘴" label="" icon="img/Face/2.swf"/> <mx:Object data="3" tp="撇嘴" label="" icon="img/Face/3.swf"/> <mx:Object data="4" tp="撇嘴" label="" icon="img/Face/4.swf"/> <mx:Object data="5" tp="撇嘴" label="" icon="img/Face/5.swf"/> <mx:Object data="6" tp="撇嘴" label="" icon="img/Face/6.swf"/> <mx:Object data="7" tp="撇嘴" label="" icon="img/Face/7.swf"/> <mx:Object data="8" tp="撇嘴" label="" icon="img/Face/8.swf"/> <mx:Object data="9" tp="撇嘴" label="" icon="img/Face/9.swf"/> <mx:Object data="10" tp="撇嘴" label="" icon="img/Face/10.swf"/> <mx:Object data="11" tp="微笑" label="" icon="img/Face/11.swf"/> <mx:Object data="12" tp="撇嘴" label="" icon="img/Face/12.swf"/> <mx:Object data="13" tp="撇嘴" label="" icon="img/Face/13.swf"/> <mx:Object data="14" tp="撇嘴" label="" icon="img/Face/14.swf"/> <mx:Object data="15" tp="撇嘴" label="" icon="img/Face/15.swf"/> <mx:Object data="16" tp="撇嘴" label="" icon="img/Face/16.swf"/> <mx:Object data="17" tp="撇嘴" label="" icon="img/Face/17.swf"/> <mx:Object data="18" tp="撇嘴" label="" icon="img/Face/18.swf"/> <mx:Object data="19" tp="撇嘴" label="" icon="img/Face/19.swf"/> <mx:Object data="20" tp="撇嘴" label="" icon="img/Face/20.swf"/> <mx:Object data="21" tp="撇嘴" label="" icon="img/Face/21.swf"/> <mx:Object data="22" tp="撇嘴" label="" icon="img/Face/22.swf"/> <mx:Object data="23" tp="撇嘴" label="" icon="img/Face/23.swf"/> <mx:Object data="24" tp="撇嘴" label="" icon="img/Face/24.swf"/> <mx:Object data="25" tp="撇嘴" label="" icon="img/Face/25.swf"/> <mx:Object data="26" tp="撇嘴" label="" icon="img/Face/26.swf"/> <mx:Object data="27" tp="撇嘴" label="" icon="img/Face/27.swf"/> <mx:Object data="28" tp="撇嘴" label="" icon="img/Face/28.swf"/> <mx:Object data="29" tp="撇嘴" label="" icon="img/Face/29.swf"/> <mx:Object data="30" tp="微笑" label="" icon="img/Face/30.swf"/> <mx:Object data="31" tp="撇嘴" label="" icon="img/Face/31.swf"/> <mx:Object data="32" tp="撇嘴" label="" icon="img/Face/32.swf"/> <mx:Object data="33" tp="撇嘴" label="" icon="img/Face/33.swf"/> <mx:Object data="34" tp="撇嘴" label="" icon="img/Face/34.swf"/> <mx:Object data="35" tp="撇嘴" label="" icon="img/Face/35.swf"/> <mx:Object data="36" tp="撇嘴" label="" icon="img/Face/36.swf"/> <mx:Object data="37" tp="撇嘴" label="" icon="img/Face/37.swf"/> <mx:Object data="38" tp="撇嘴" label="" icon="img/Face/38.swf"/> <mx:Object data="39" tp="撇嘴" label="" icon="img/Face/39.swf"/> <mx:Object data="40" tp="微笑" label="" icon="img/Face/40.swf"/> <mx:Object data="41" tp="撇嘴" label="" icon="img/Face/41.swf"/> <mx:Object data="42" tp="撇嘴" label="" icon="img/Face/42.swf"/> <mx:Object data="43" tp="撇嘴" label="" icon="img/Face/43.swf"/> <mx:Object data="44" tp="撇嘴" label="" icon="img/Face/44.swf"/> <mx:Object data="45" tp="撇嘴" label="" icon="img/Face/45.swf"/> <mx:Object data="46" tp="撇嘴" label="" icon="img/Face/46.swf"/> <mx:Object data="47" tp="撇嘴" label="" icon="img/Face/47.swf"/> <mx:Object data="48" tp="撇嘴" label="" icon="img/Face/48.swf"/> <mx:Object data="49" tp="撇嘴" label="" icon="img/Face/49.swf"/> <mx:Object data="50" tp="微笑" label="" icon="img/Face/50.swf"/> <mx:Object data="51" tp="撇嘴" label="" icon="img/Face/51.swf"/> <mx:Object data="52" tp="撇嘴" label="" icon="img/Face/52.swf"/> <mx:Object data="53" tp="撇嘴" label="" icon="img/Face/53.swf"/> <mx:Object data="54" tp="撇嘴" label="" icon="img/Face/54.swf"/> <mx:Object data="55" tp="撇嘴" label="" icon="img/Face/55.swf"/> <mx:Object data="56" tp="撇嘴" label="" icon="img/Face/56.swf"/> <mx:Object data="57" tp="撇嘴" label="" icon="img/Face/57.swf"/> <mx:Object data="58" tp="撇嘴" label="" icon="img/Face/58.swf"/> <mx:Object data="59" tp="撇嘴" label="" icon="img/Face/59.swf"/> <mx:Object data="60" tp="微笑" label="" icon="img/Face/60.swf"/> <mx:Object data="61" tp="撇嘴" label="" icon="img/Face/61.swf"/> <mx:Object data="62" tp="撇嘴" label="" icon="img/Face/62.swf"/> <mx:Object data="63" tp="撇嘴" label="" icon="img/Face/63.swf"/> <mx:Object data="64" tp="撇嘴" label="" icon="img/Face/64.swf"/> <mx:Object data="65" tp="撇嘴" label="" icon="img/Face/65.swf"/> <mx:Object data="66" tp="撇嘴" label="" icon="img/Face/66.swf"/> <mx:Object data="67" tp="撇嘴" label="" icon="img/Face/67.swf"/> <mx:Object data="68" tp="撇嘴" label="" icon="img/Face/68.swf"/> <mx:Object data="69" tp="撇嘴" label="" icon="img/Face/69.swf"/> <mx:Object data="70" tp="微笑" label="" icon="img/Face/70.swf"/> <mx:Object data="71" tp="撇嘴" label="" icon="img/Face/71.swf"/> <mx:Object data="72" tp="撇嘴" label="" icon="img/Face/72.swf"/> <mx:Object data="73" tp="撇嘴" label="" icon="img/Face/73.swf"/> <mx:Object data="74" tp="撇嘴" label="" icon="img/Face/74.swf"/> <mx:Object data="75" tp="撇嘴" label="" icon="img/Face/75.swf"/> <mx:Object data="76" tp="撇嘴" label="" icon="img/Face/76.swf"/> <mx:Object data="77" tp="撇嘴" label="" icon="img/Face/77.swf"/> <mx:Object data="78" tp="撇嘴" label="" icon="img/Face/78.swf"/> <mx:Object data="79" tp="撇嘴" label="" icon="img/Face/79.swf"/> <mx:Object data="80" tp="微笑" label="" icon="img/Face/80.swf"/> <mx:Object data="81" tp="撇嘴" label="" icon="img/Face/81.swf"/> <mx:Object data="82" tp="撇嘴" label="" icon="img/Face/82.swf"/> <mx:Object data="83" tp="撇嘴" label="" icon="img/Face/83.swf"/> <mx:Object data="84" tp="撇嘴" label="" icon="img/Face/84.swf"/> <mx:Object data="85" tp="撇嘴" label="" icon="img/Face/85.swf"/> <mx:Object data="86" tp="撇嘴" label="" icon="img/Face/86.swf"/> <mx:Object data="87" tp="撇嘴" label="" icon="img/Face/87.swf"/> <mx:Object data="88" tp="撇嘴" label="" icon="img/Face/88.swf"/> <mx:Object data="89" tp="撇嘴" label="" icon="img/Face/89.swf"/> <mx:Object data="90" tp="微笑" label="" icon="img/Face/90.swf"/> <mx:Object data="91" tp="撇嘴" label="" icon="img/Face/91.swf"/> <mx:Object data="92" tp="撇嘴" label="" icon="img/Face/92.swf"/> <mx:Object data="93" tp="撇嘴" label="" icon="img/Face/93.swf"/> <mx:Object data="94" tp="撇嘴" label="" icon="img/Face/94.swf"/> <mx:Object data="95" tp="撇嘴" label="" icon="img/Face/95.swf"/> <mx:Object data="96" tp="撇嘴" label="" icon="img/Face/96.swf"/> <mx:Object data="97" tp="撇嘴" label="" icon="img/Face/97.swf"/> <mx:Object data="98" tp="撇嘴" label="" icon="img/Face/98.swf"/> <mx:Object data="99" tp="撇嘴" label="" icon="img/Face/99.swf"/> <mx:Object data="100" tp="微笑" label="" icon="img/Face/100.swf"/> <mx:Object data="101" tp="撇嘴" label="" icon="img/Face/101.swf"/> <mx:Object data="102" tp="撇嘴" label="" icon="img/Face/102.swf"/> <mx:Object data="103" tp="撇嘴" label="" icon="img/Face/103.swf"/> <mx:Object data="104" tp="撇嘴" label="" icon="img/Face/104.swf"/> <mx:Object data="105" tp="撇嘴" label="" icon="img/Face/105.swf"/> <mx:Object data="106" tp="撇嘴" label="" icon="img/Face/106.swf"/> <mx:Object data="107" tp="撇嘴" label="" icon="img/Face/107.swf"/> <mx:Object data="108" tp="撇嘴" label="" icon="img/Face/108.swf"/> <mx:Object data="109" tp="撇嘴" label="" icon="img/Face/109.swf"/> <mx:Object data="110" tp="微笑" label="" icon="img/Face/110.swf"/> <mx:Object data="111" tp="撇嘴" label="" icon="img/Face/111.swf"/> <mx:Object data="112" tp="撇嘴" label="" icon="img/Face/112.swf"/> <mx:Object data="113" tp="撇嘴" label="" icon="img/Face/113.swf"/> <mx:Object data="114" tp="撇嘴" label="" icon="img/Face/114.swf"/> <mx:Object data="115" tp="撇嘴" label="" icon="img/Face/115.swf"/> <mx:Object data="116" tp="撇嘴" label="" icon="img/Face/116.swf"/> <mx:Object data="117" tp="撇嘴" label="" icon="img/Face/117.swf"/> <mx:Object data="118" tp="撇嘴" label="" icon="img/Face/118.swf"/> <mx:Object data="119" tp="撇嘴" label="" icon="img/Face/119.swf"/> <mx:Object data="120" tp="微笑" label="" icon="img/Face/120.swf"/> <mx:Object data="121" tp="撇嘴" label="" icon="img/Face/121.swf"/> <mx:Object data="122" tp="撇嘴" label="" icon="img/Face/122.swf"/> <mx:Object data="123" tp="撇嘴" label="" icon="img/Face/123.swf"/> <mx:Object data="124" tp="撇嘴" label="" icon="img/Face/124.swf"/> <mx:Object data="125" tp="撇嘴" label="" icon="img/Face/125.swf"/> <mx:Object data="126" tp="撇嘴" label="" icon="img/Face/126.swf"/> <mx:Object data="127" tp="撇嘴" label="" icon="img/Face/127.swf"/> <mx:Object data="128" tp="撇嘴" label="" icon="img/Face/128.swf"/> <mx:Object data="129" tp="撇嘴" label="" icon="img/Face/129.swf"/> <mx:Object data="130" tp="微笑" label="" icon="img/Face/130.swf"/> <mx:Object data="131" tp="撇嘴" label="" icon="img/Face/131.swf"/> <mx:Object data="132" tp="撇嘴" label="" icon="img/Face/132.swf"/> <mx:Object data="133" tp="撇嘴" label="" icon="img/Face/133.swf"/> <mx:Object data="134" tp="撇嘴" label="" icon="img/Face/134.swf"/> </mx:Array> </mx:source> </mx:ArrayCollection> <mx:Script> <!--[CDATA[ import mx.events.ColorPickerEvent; //占位符 private var placeholder:String="[img:{0}]"; private function imageclick(evt:Event):void { var img:Image=evt.currentTarget as Image; var idx:int=int(img.data); // var str:String=placeholder.replace("{0}", idx.toString()); // this.insertString(str); //关闭弹出菜单 this.popUpButton_pic.close(); } //设置字体属性 private function checkBox_fontsetup(evt:Event):void { var ch:CheckBox=evt.currentTarget as CheckBox; var data:String=ch.data.toString(); if (data == "fontWeight") { if (ch.selected) { // this.fontWeight="bold"; } else { // this.fontWeight="normal"; } } if (data == "fontStyle") { if (ch.selected) { // this.fontStyle="italic"; } else { // this.fontStyle="normal"; } } if (data == "textDecoration") { if (ch.selected) { // this.fontTextDecoration="underline"; } else { // this.fontTextDecoration="none"; } } } //设置字体颜色 private function colorPicker_color(evt:ColorPickerEvent):void { // fontColor=this.fontsetup_color.selectedColor; } private function insertString(insertStr:String):void { if (this.textEditor.selectionBeginIndex == this.textEditor.selectionEndIndex) { var startPart:String=this.textEditor.text.substring(0, this.textEditor.selectionBeginIndex); var endPart:String=this.textEditor.text.substring(this.textEditor.selectionEndIndex, this.textEditor.text.length); startPart+=insertStr; startPart+=endPart; this.textEditor.text=startPart; } else { this.textEditor.text=insertStr; } } ]]> </mx:Script> <mxanel x="168.5" y="82" width="410" height="322" layout="absolute" title="聊天室"> <mx:Canvas x="10" y="0" width="370" height="158" themeColor="#FF0042" borderStyle="inset" borderColor="#1094F1" id="cs"> <mx:VBox id="vd" updateComplete="updateCompleteHandler(event)" width="100%" height="100%" borderStyle="solid" borderThickness="1" borderColor="#000000" verticalScrollPolicy="auto" horizontalScrollPolicy="auto"> </mx:VBox> </mx:Canvas> <mxopUpButton id="popUpButton_pic" icon="@Embed('img/face.png')" openAlways="true" toolTip="请选择表情图片" width="50" x="19.5" y="166"> <mx:popUp> <mx:TitleWindow id="titleWindow_popUp" status="单击图片选择聊天表情" width="450" height="400" showCloseButton="true" verticalScrollPolicy="on" horizontalScrollPolicy="off" close="popUpButton_pic.close();"> <mx:ToolBar width="430"> <mx:Repeater id="myRep" dataProvider="{arrColl}"> <mx:Image click="imageclick(event)" buttonMode="true" data="{myRep.currentIndex}" toolTip="{myRep.currentItem.tp}" source="{myRep.currentItem.icon}"> </mx:Image> </mx:Repeater> </mx:ToolBar> </mx:TitleWindow> </mx:popUp> </mxopUpButton> <mx:TextArea id="textEditor" x="10" y="196" width="291" height="67"/> <mx:Button x="309" y="195" label="发送" height="68" width="71" fontSize="13" click="sendMessage()"/> <mxopUpButton id="popUpButton_fontSetup" icon="@Embed('img/a.png')" openAlways="true" toolTip="设置字体样式" width="50" x="77.5" y="166"> <mx:popUp> <mx:TitleWindow id="titleWindow_popUp_fontSetup" status="选择字体样式" showCloseButton="true" close="popUpButton_fontSetup.close();"> <mx:HBox> <mx:CheckBox id="fontsetup_fontWeight" change="checkBox_fontsetup(event)" data="fontWeight" toolTip="粗体" label=""> </mx:CheckBox> <mx:Image source="img/typeface/b.png" toolTip="粗体"> </mx:Image> <mx:CheckBox id="fontsetup_fontStyle" change="checkBox_fontsetup(event)" data="fontStyle" toolTip="倾斜" label=""> </mx:CheckBox> <mx:Image source="img/typeface/i.png" toolTip="倾斜"> </mx:Image> <mx:CheckBox id="fontsetup_textDecoration" change="checkBox_fontsetup(event)" data="textDecoration" toolTip="下划线" label=""> </mx:CheckBox> <mx:Image source="img/typeface/u.png" toolTip="下划线"> </mx:Image> <mx:ColorPicker id="fontsetup_color" change="colorPicker_color(event)" toolTip="颜色"> </mx:ColorPicker> </mx:HBox> </mx:TitleWindow> </mx:popUp> </mxopUpButton> <mx:TextInput x="141" y="166" width="84" text="姓名:" id="userName"/> </mxanel> <mxroducer id="producer" destination="mychat"> </mxroducer> <mx:Consumer id="consumer" destination="mychat" message="messagehandle(event)"> </mx:Consumer> <mx:Script> <![CDATA[ import mx.events.FlexEvent; import mx.controls.Label; import mx.containers.HBox; import mx.controls.Text; import mx.controls.Image; import mx.controls.SWFLoader; import mx.controls.Alert; import mx.containers.VBox; import mx.messaging.events.MessageAckEvent; import mx.messaging.events.ChannelFaultEvent; import mx.messaging.events.ChannelEvent; import mx.messaging.ChannelSet; import mx.messaging.channels.AMFChannel; import mx.messaging.channels.StreamingAMFChannel; import mx.messaging.events.MessageFaultEvent; import mx.messaging.messages.AsyncMessage; import mx.messaging.events.MessageEvent; public function init(){ initChannel(); consumer.subscribe(); producer.addEventListener(MessageFaultEvent.FAULT,error); } private function addEvent(){ // producer.addEventListener(ChannelEvent.CHANNEL_CONNECT,channelConnection); // producer.addEventListener(ChannelEvent.CHANNEL_DISCONNECT,channelDisconnect); // producer.addEventListener(ChannelFaultEvent.CHANNEL_FAULT,channelFault); // producer.addEventListener(MessageAckEvent.ACKNOWLEDGE } public function initChannel(){ var url="http://192.168.200.14:8080/J2EE/"; var myStreamingAMF:StreamingAMFChannel = new StreamingAMFChannel(url+"my-streaming-amf", url+"messagebroker/streamingamf"); var myPollingAMF:AMFChannel = new AMFChannel(url+"my-polling-amf", url+"messagebroker/amfpolling"); myPollingAMF.pollingEnabled = true; myPollingAMF.pollingInterval = 2000; var channelSet:ChannelSet = new ChannelSet(); channelSet.addChannel(myStreamingAMF); channelSet.addChannel(myPollingAMF); consumer.channelSet = channelSet; producer.channelSet = channelSet; } public function messagehandle(event:MessageEvent){ // ta.text+=event.message.body.text+"\n"; // ta.htmlText+=event.message.body.htmlText; this.vd.verticalScrollPosition=this.vd.maxVerticalScrollPosition; this.cs.verticalScrollPosition=cs.maxVerticalScrollPosition; var messages:String=event.message.body.text; // var image:Image=new Image; // image.source="img/Face/134.swf"; // image.autoLoad=true; // vd.addChild(image); //日期和时间 var messageDate:Text=this.getTxtMessage(event.message.body.userAndDate) messageDate.setStyle("color","red") vd.addChild(messageDate); vd.addChild(parseMessage(messages)); this.vd.verticalScrollPosition=this.vd.maxVerticalScrollPosition; // vd.addChild(image); // mx.controls.Alert.show(event.message.body.text); } private static var top:String="[img:"; /*** * 这段是主要的解析接受到的信息,麻烦哪位老大给优化下。有个问题就是 只能接收一行 * * */ private function parseMessage(messages:String):HBox{ var hBox:HBox=new HBox; var msg:String=messages; var swfArray:Array=msg.split(top); if(swfArray.length==1){ //如果==1,说明没有发送表情 hBox.addChild(getTxtMessage(msg)); // Alert.show(txt.text); return hBox; } var i:int=0; //下边的大致思路是,(是否有文字)swf(是否有文字) swf(是否有文字) for each(var swf:String in swfArray){ // i==0判断一个swf前边是否有文字,有的话就添加进Hbox 如:文字 swf if(i==0){ var startMessage:String=msg.substring(0,msg.indexOf("["));//开始的字体 if(startMessage!=""||startMessage!=null){ hBox.addChild(getTxtMessage(startMessage)); } } i++; if(swf.indexOf("]")!=-1){ var icon:String=swf.substring(0,swf.indexOf("]")); var mess:String=swf.substring(swf.indexOf("]")+1,swf.length); if(!isNaN(Number(icon))){ hBox.addChild(getImage(parseInt(icon))); } if(mess!=""||mess!=null){ hBox.addChild(getTxtMessage(mess)); } trace(icon); } } return hBox; } private function getImage(id:Number):Image{ var image:Image=new Image; image.source="img/Face/"+id+".swf"; trace(image.source); image.autoLoad=true; return image; } private function getTxtMessage(mess:String):Text{ var txt:Text=new Text; txt.text=mess; return txt; } private function sendMessage():void{ if(textEditor.text==""){ Alert.show("不能发送空消息"); return; } var message:AsyncMessage=new AsyncMessage(); // message.body.text=userName.text+":"+msg.text+" "; message.body.text=textEditor.text; message.body.userAndDate=userName.text+" "+new Date(); producer.send(message); textEditor.text=""; vd.verticalScrollPosition=vd.maxVerticalScrollPosition; this.cs.verticalScrollPosition=cs.maxVerticalScrollPosition; } public function error(event:MessageFaultEvent){ trace(event.message); } //滚动条自动滚动到最下面,方便用户看聊天记录 private function updateCompleteHandler(evt:FlexEvent):void { this.vd.verticalScrollPosition=this.vd.maxVerticalScrollPosition; } ]]--> </mx:Script> </mx:Application>

转自:

http://www.eb163.com/club/thread-3304-1-1.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值