论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash AS编程教程
Tag:2.0,3.0菜鸟,游戏,,cs,技巧,源码,,文本,文字,函数,音乐,随机,拖拽,asp,access,xml,mc,视频教程

swf通信代理类,多个3.0与2.0swf之间的通信,共享对象在不同版本的swf间共享

文章类别:Flash AS编程 | 发表日期:2008-10-6 18:40:20


代理类由包括3个部分~以LocalConnection作为基类,主体是一个由2.0写的一个AgencySWF类~主要用于连接2.0代理类(ClientAgencySWF_2)实例或3.0代理类(ClientAgencySWF)并兼担共享数据存处的载体~

AgencySWF类

class AgencySWF extends LocalConnection {
    private var conName = 'agencySWF';
    private var $$sending_lc;
    public var text;
    public var Trace_Bool;
    private var Member_ID;
    private var txt;
    //private var _root.SO:SharedObject;
    public function AgencySWF(link) {
        var obj = {MP3UrlArr:[], MP3NameArr:[], ArtistArr:[], MoodArr:[], MP3InfoArr:[]};
        var arr = ["我是共享对象","我是共享对象","我是共享对象","我是共享对象"];
        // var arr=[obj,obj,obj,obj];
        _root.SO = SharedObject.getLocal("AgencySo");
        _root.SO.data.cookie == undefined ? _root.SO.data.cookie=arr : '';
        _root.SO.data.cookie = arr;
        ;
        if (link != undefined) {
            conName = link;
        }
        $$sending_lc = this;
        this.$$sending_lc.connect(conName);
        this.$$sending_lc.onStatus = function(infoObject:Object) {
            switch (infoObject.level) {
                case 'status' :
                    ;
                    trace(" 中介 回调 成功 ");
                    break;
                case 'error' :
                    trace("LocalConnection encountered an error.");
                    break;
            }
        };
    }
    //获取用户id
    private function setimd(arg) {
        trace(arg.imd);
        Member_ID = arg.imd;
        text = "Member_ID="+Member_ID;
        return Member_ID;
    }
    private function getimd(arg) {
        trace("call child success");
        return Member_ID;
    }
    //调用外部接口
    public function SendFunc(func, res) {
        
        $$sending_lc.send("agencySWF","agencyFunc",conName,func,res);
    }
    //外部调用接口  (外部连接名,调用本类的函数,参数)
    public function agencyFunc(callconnet, callfunc, callinfo) {
        text = "";
        var _l3 = {imd:_root.Member_ID, info:callinfo};
        if (Trace_Bool) {
            trace("------呼叫中介函数成功------");
            trace("ReConnect::"+callconnet+"   Func::"+callfunc);
            text = _root.txt.text+"ReConnect::"+callconnet+"   Func::"+callfunc;
            trace("   arguments::");
            for (var i in _13) {
                trace(i+'=='+_13[i]);
            }
        }
        $$sending_lc.send(callconnet,callfunc,_l3);
    }
    //外部接口函数 (外部连接名,要调用的本类方法,参数)
    public function callAgencyFunc(callConnet, callFunc, callInfo) {
        trace("AgencySWF Get ["+callConnet+"] Call  Success");
        var Result = {imd:Menber_ID, Info:this[callFunc](callInfo)};
          $$sending_lc.send(callConnet,callFunc,Result);
    }
    //调试开关
    private function Trace(bool) {
        $$sending_lc.send("agencySWF","setTrace");
    }
    //创建shareObject属性
    private function createShareObject(varName:String, newVar) {
        _root.SO.data[arguments[0]] == undefined ? my_so.data[arguments[0]]=arguments[1] : '';
        return _root.SO.data[arguments[0]];
    }
    private function getShareObject(arg) {
        
        return _root.SO.data[arg[0]];
    }
    //设置shareObject属性
    private function setShareObject(arg) {
        _root.SO.data[arg[0]] = arg[1];;
        return _root.SO.data[arg[0]];
    }
    public function SendMessage(arg) {
    trace('sendMessage:'+arguments)
    var client_id=arg[0];
    var func=arg[1]
    arg.shift()
    arg.shift()
    _root.setConnet(client_id,client_id,func,arg);
        //$$sending_lc.send(callConnet,callFunc,Result);
    }
}


ClientAgencySWF_2类

dynamic class ClientAgencySWF_2 extends LocalConnection {
    private var conName = 'lc_2';
    private var $$sending_lc;
    public var text;
    public var Trace_Bool;
    private var Member_ID;
    private var txt;
    public function ClientAgencySWF_2(link) {
        if (link != undefined) {
            conName = link;
        }
        $$sending_lc = this;
        this.$$sending_lc.connect(conName);
        this.$$sending_lc.onStatus = function(infoObject:Object) {
            switch (infoObject.level) {
                case 'status' :
                
                    trace("2.0Client successful");
                    break;
                case 'error' :
                    trace("listCall err");
                    break;
            }
        };
    }
    private function getimd(arg) {
        trace("call child success");
        return Member_ID;
    }
运行测试时请新建一个2.0文件 AgencySWF
住场景第一帧拷贝代码

var client3_:AgencySWF = new AgencySWF("agencySWF");
var client2_:AgencySWF = new AgencySWF("agencySWF2");
function setConnet(id,connetName,func,arg){
    trace(arguments)
    trace(_root[id])
    _root[id].callAgencyFunc(connetName,func,arg)
    }

再建一个2.0fla (client2.0fla)

第一帧代码

var ClientAgency :ClientAgencySWF_2= new ClientAgencySWF_2("client2_");
//(中介的方法,[要连接到的对象连接,要调用的对象的方法,要传输给对象的参数]
b1.onPress=function(){
ClientAgency.SendFunc('SendMessage',['client3_','getShareObject',['cookie']]);
}
b2.onPress=function(){
ClientAgency.SendFunc('getShareObject',['cookie']);
}

并于场景放两个按钮
命名为:b1,b2
再建一个3.0fla (client3.0fla)

第一帧代码
var ClientAgency:ClientAgencySWF=new ClientAgencySWF("client3_");
b1.addEventListener(MouseEvent.CLICK,callFunc)
function callFunc(event:MouseEvent){
ClientAgency.SendFunc('getShareObject',['cookie'])}

以上操作完毕请先运行代理
AgencySWF
在运行client3.0.fla
进行度取AgencySWF信息测试
再后运行client2.0fla
按b2进行读取
AgencySWF共享信息测试
按b1进行调用client3.0.fla的getShareObject方法测试
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://wxsr.blogbus.com/logs/16236087.html
视频教程列表
文章教程搜索
 
Flash AS推荐教程
Flash AS热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058