Error #2044: 未处理的 StatusEvent:。 level=error, code=
在使用LocalConnection的时候,出现Error #2044: 未处理的 StatusEvent:。 level=error, code=这样的报错
以前是直接写在时间轴里的,没有报错。
这次是写在文档类。可是怎么搞都报错
例如.test1.swf加载了test2.swf,需要将test1的参数传到test2
1.加载test2.swf,然后在test2.swf建立一个连接,通知test1.swf已经建立完成(回调test1的t1Function()函数)
2.test1.swf收到test2.swf的回调之后也建立一个连接,并把参数发给test2.swf(回调test2r的t2Function(obj:Object)函数)
为了不重复写两次连接,所以写在一个as文件里
ConnectionObject.as
package com.zkl.net{import flash.events.StatusEvent;import flash.net.LocalConnection;/** * 建立一个连接名,然后发送一个连接信息 * @author zkl * 2010-8-3 10:57 */public class ConnectionObject{//回调对像private var _client:Object; //实例化连接private var _conn:LocalConnection;//准备一个 LocalConnection 对象,以接收来自 send() 命令(称为发送方 LocalConnection 对象)的命令。private var _connName:String;//接收的对像private var _connObj:String;//接收的句柄private var _connHandler:String;//接收的参数private var _connVar:Object;/** * 使用当前的连接对像,建立一个连接名,然后发送一个连接信息 * @param_client:当前服务对像 * @param_connName:连接名 * @param_connObj:要连接的对像 * @param_connHandler:连接的句柄 * @param_connVar:附带的参数 */public function ConnectionObject(_client:Object, _connName:String, _connObj:String, _connHandler:String, _connVar:Object = null):void{this._client = _client;this._connName = _connName;this._connObj = _connObj;this._connHandler = _connHandler;this._connVar = _connVar;init();}/** * 建立连接 */private function init():void{ _conn = new LocalConnection;_conn.client = _client;_conn.allowDomain("*");try {_conn.connect(_connName);}catch (err:ArgumentError) {trace(err);}}/** * 开始连接 */public function isConnection():void{ if (_connVar == null) {_conn.send(_connObj, _connHandler);}else {_conn.send(_connObj, _connHandler, _connVar);}_conn.addEventListener(StatusEvent.STATUS, onStatus);}/** * 关闭连接 */public function connClose():void{ _conn.close();_conn = null;}/** * 连接状态 * @parame */public function onStatus(e:StatusEvent):void {//_conn.removeEventListener(StatusEvent.STATUS, onStatus);switch(e.level) {case "status":trace(_client + "发送成功.");break;case "error":trace(_client + "发送失败!");break;}}}}
package {import com.zkl.net.ConnectionObject;import flash.display.MovieClip;import flash.display.Loader;import flash.net.URLRequest;import flash.events.Event;/** * ... * @author zkl */public class Test1 extends MovieClip {private var co:ConnectionObject;public function Test1() {var loader:Loader = new Loader();var movieUrl:URLRequest = new URLRequest("test2.swf");loader.load(movieUrl);loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);connObject();//------------------------------1}public function loadComplete(e:Event):void {addChild(e.target.content);//connObject();//-----------------------2}public function connObject():void {co = new ConnectionObject(this, "t2", "t1", "t2Function", { totalUnit:10 } );}public function t1Function():void {co.isConnection();co.connClose();}}}
package {import com.zkl.net.ConnectionObject;import flash.display.Loader;import flash.display.MovieClip;import flash.events.Event;import flash.net.URLRequest;/** * ... * @author zkl */public class Test2 extends MovieClip {private var co:ConnectionObject;public function Test2() {co = new ConnectionObject(this, "t1", "t2", "t1Function");co.isConnection();}public function t2Function(obj:Object):void {co.connClose();trace(obj.totalUnit);}}}