·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]as3的debug工具源代码

时间:2014-06-13 15:26酷播
[AS3]as3的debug工具源代码

很多网上的debug工具 浏览器调试flash 界面工具接收trace出来的数据 这种方式很好 记得以前as2的时期 需要在flash中单独做一个功能 就是显示我trace出来的数据 现在好了 AS3中的LocalConnection类 具体方法用途请自行查看帮助 下面我只具体介绍一下debug工具的原理与开发

原理:

swf文件与air文件通信 swf文件发送数据 air文件接收就得了

具体代码:

air主代码:

  1. package { 
  2.   import flash.display.MovieClip; 
  3.   import flash.events.MouseEvent; 
  4.   import flash.net.LocalConnection; 
  5.   import flash.system.Security; 
  6.   import flash.text.TextField; 
  7.   import flash.display.NativeWindow; 
  8.   public class MyDebug extends MovieClip { 
  9.     private var conn:LocalConnection; 
  10.     private var output:TextField; 
  11.     private var newWindow:NativeWindow; 
  12.     public function MyDebug():void { 
  13.       //Security.allowDomain("*"); 
  14.        newWindow = stage.nativeWindow; 
  15.        newWindow.orderToFront(); 
  16.        newWindow.alwaysInFront = true
  17.              clear_btn.label = "Crear"
  18.        clear_btn.addEventListener(MouseEvent.CLICK, crearHandler); 
  19.              conn = new LocalConnection(); 
  20.              conn.client = this
  21.        out_txt.text = "MyDebug\n"
  22.        conn.allowDomain("*"); 
  23.             try { 
  24.                  conn.connect("_myConnection"); 
  25.              } catch (error:ArgumentError) { 
  26.                 this.out_txt.appendText("Can't connect...the connection name is already being used by another SWF"); 
  27.              } 
  28.      } 
  29.      
  30.     private function crearHandler(e:MouseEvent):void { 
  31.       this.out_txt.text = ""
  32.      } 
  33.     public function lcHandler(msg:String):void { 
  34.             this.out_txt.appendText(msg + "\n"); 
  35.          } 
  36.      
  37.     public function array(_arr:Array):void { 
  38.       this.out_txt.appendText("-----CuPlayer.com-----START------" + _arr.length + "\n"); 
  39.       for(var i:int=0;i<_arr.length;i++){ 
  40.         if(_arr[i] is Array){ 
  41.           this.out_txt.appendText(i + "-->" + "    " + "arrayLen->" + _arr[i].length + "\n"); 
  42.            array(_arr[i]); 
  43.          }else{ 
  44.           this.out_txt.appendText(i + "      " + _arr[i] + "\n"); 
  45.          } 
  46.        } 
  47.       this.out_txt.appendText("----CuPlayer.com-------END-----" + i + "\n"); 
  48.      } 
  49.    } 

DebugArr类 此类为静态类 做为发送数据中介

  1. package { 
  2.   import flash.events.StatusEvent; 
  3.   import flash.net.LocalConnection; 
  4.   /** 
  5.     * ... 
  6.     * @author silva 
  7.     */ 
  8.   public class DebugArr{ 
  9.     private static var conn:LocalConnection = new LocalConnection(); 
  10.     public function DebugArr() { 
  11.        
  12.      } 
  13.     /** 
  14.       * 解析数组 
  15.       */ 
  16.     public static function array(_arr:Array):void { 
  17.        send("array", _arr); 
  18.      } 
  19.     //发送函数 
  20.     private static function send(operation:String, value:*):void { 
  21.       this.conn.addEventListener(StatusEvent.STATUS, status); 
  22.       this.conn.allowDomain("*"); 
  23.        conn.send("_myConnection", operation, value); 
  24.      } 
  25.     private static function status(e:StatusEvent):void { 
  26.       switch (e.level) { 
  27.                 case "status": 
  28.                     //trace("LocalConnection.send() succeeded"); 
  29.                     break; 
  30.                 case "error": 
  31.                      trace("LocalConnection.send() failed"); 
  32.                     break; 
  33.              } 
  34.      } 
  35.    } 

发送的 接收的都有了 先将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

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器