很多网上的debug工具 浏览器调试flash 界面工具接收trace出来的数据 这种方式很好 记得以前as2的时期 需要在flash中单独做一个功能 就是显示我trace出来的数据 现在好了 AS3中的LocalConnection类 具体方法用途请自行查看帮助 下面我只具体介绍一下debug工具的原理与开发
原理:
swf文件与air文件通信 swf文件发送数据 air文件接收就得了
具体代码:
air主代码:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.net.LocalConnection;
import flash.system.Security;
import flash.text.TextField;
import flash.display.NativeWindow;
public class MyDebug extends MovieClip {
private var conn:LocalConnection;
private var output:TextField;
private var newWindow:NativeWindow;
public function MyDebug():void {
//Security.allowDomain("*");
newWindow = stage.nativeWindow;
newWindow.orderToFront();
newWindow.alwaysInFront = true;
clear_btn.label = "Crear";
clear_btn.addEventListener(MouseEvent.CLICK, crearHandler);
conn = new LocalConnection();
conn.client = this;
out_txt.text = "MyDebug\n";
conn.allowDomain("*");
try {
conn.connect("_myConnection");
} catch (error:ArgumentError) {
this.out_txt.appendText("Can't connect...the connection name is already being used by another SWF");
}
}
private function crearHandler(e:MouseEvent):void {
this.out_txt.text = "";
}
public function lcHandler(msg:String):void {
this.out_txt.appendText(msg + "\n");
}
public function array(_arr:Array):void {
this.out_txt.appendText("----------START------" + _arr.length + "\n");
for(var i:int=0;i<_arr.length;i++){
if(_arr[i] is Array){
this.out_txt.appendText(i + "-->" + " " + "arrayLen->" + _arr[i].length + "\n");
array(_arr[i]);
}else{
this.out_txt.appendText(i + " " + _arr[i] + "\n");
}
}
this.out_txt.appendText("----------END-----" + i + "\n");
}
}
}
DebugArr类 此类为静态类 做为发送数据中介
package {
import flash.events.StatusEvent;
import flash.net.LocalConnection;
/**
* ...
* @author silva
*/
public class DebugArr{
private static var conn:LocalConnection = new LocalConnection();
public function DebugArr() {
}
/**
* 解析数组
*/
public static function array(_arr:Array):void {
send("array", _arr);
}
//发送函数
private static function send(operation:String, value:*):void {
this.conn.addEventListener(StatusEvent.STATUS, status);
this.conn.allowDomain("*");
conn.send("_myConnection", operation, value);
}
private static function status(e:StatusEvent):void {
switch (e.level) {
case "status":
//trace("LocalConnection.send() succeeded");
break;
case "error":
trace("LocalConnection.send() failed");
break;
}
}
}
}
发送的 接收的都有了 先将air文件发布出来 导出air安装文件 先装好这个air文件 然后我们来测试一下吧
var arr:Array = [1, 2, 3, [4, 5,[0,7,8], 6],10];
DebugArr.array(arr);
//AIR输出
MyDebug
----------START------5
0 1
1 2
2 3
3--> arrayLen->4
----------START------4
0 4
1 5
2--> arrayLen->3
----------START------3
0 0
1 7
2 8
----------END-----3
3 6
----------END-----4
4 10
----------END-----5