探索Flash Media Server(二)


  来源: | 作者: | 浏览: | 发送给好友 | 添加到收藏夹
 尝试使用了SharedObject类

使用Local SharedObject
import mx.utils.Delegate; 
var lso:SharedObject = SharedObject.getLocal("test", "/"); 
output_txt.text = lso.data.msg; 
input_txt.addEventListener("keyDown", Delegate.create(this, inputFunc)); 
function inputFunc(obj) { 
  if (Key.isDown(Key.ENTER)) { 
    lso.data.msg = obj.target.text; 
    obj.target.text = ""; 
    if (lso.flush()) { 
      trace("write success"); 
    } 
  } 


使用Remote SharedLocal 
//连接 
var nc:NetConnection = new NetConnection(); 
var rso; 
nc.onStatus = checkConnect; 
nc.connect("rtmp://localhost/test1"); 
function checkConnect() { 
  if (this.isConnected) { 
    rso = SharedObject.getRemote("test", nc.uri); 
    rso.connect(nc); 
    rso.onSync = checkRso; 
  } 

//显示信息 
function checkRso(obj) { 
  var txt = this.data.msg; 
  if (txt.length>3) { 
    txt.shift(); 
  } 
  if (txt != undefined) { 
    msg_txt.text = ""; 
    for (var i = 0; i<txt.length; i++) { 
      msg_txt.text += txt[i]+newline; 
    } 
  } 

//发送信息 
import mx.utils.Delegate; 
input_txt.addEventListener("keyDown", Delegate.create(this, inputFunc)); 
function inputFunc(obj) { 
  if (rso.data.msg == undefined) { 
    rso.data.msg = []; 
  } 
  if (Key.isDown(Key.ENTER)) { 
    rso.data.msg.push(obj.target.text); 
    obj.target.text = ""; 
  } 
后者效果图
图片如下:

 
上一篇
闪动论坛 打印此页 发送给好友 返回顶部