转自:http://fykyx521.iteye.com/blog/380323
-
-
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;
}
}
]]>
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="";
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;
}
]]>
chat_biaoqing.zip
阅读(981) | 评论(0) | 转发(0) |