Flex的窗口、局部变量、对象等运行期监视工具

由来:
Flex的Debug、Trace使用的fdb,虽然说没其他IDE开发方便,但对于用过linux/unix下gdb跟踪调试的我来说也差不多都一样,但这个fdb的启动太慢了(P4 1.7G 256Rambus),而且一般也没有什么断点调试的,也就是监视一下调试数据是否正确。后来就在mxml写个textbox自己输出一下,总是不太方便,今天看到一个比较好的Trace工具,就收下来!

在线演示:
http://coenraets.com/apps/load.jsp?app=inspector/sample
你可以输入 srv.result, this, myDataGrid.width 等对象或变量来监视状态。

使用方法:
在你需要监视的mxml文件里添加 <Inspect/>标记,当然对应的程序文件(见下)要包含在相同的目录了。
或者把下面的两个文件复制到 WEB-INF\flex\user_classes目录下,这样所有的mxml文件都可以直接引用了。

该工具包含两个文件:
Inspect.as
None.gif /*
None.gif    Author: Christophe Coenraets, Macromedia. Blog: http://coenraets.com
None.gif    Date:   11/5/2004
None.gif
*/     
None.gifclass Inspect {
None.gif
None.gif    
function  Inspect() {
None.gif        display();
None.gif    }
None.gif
None.gif    
function  display() {
None.gif        
var  popup  =  mx.managers.PopUpManager.createPopUp(_root, InspectWindow,  false , {deferred:  true });
None.gif        popup.width
= 500 ;
None.gif        popup.height
= 400 ;
None.gif        popup.x
= 50 ;
None.gif        popup.y
= 50 ;
None.gif    }
None.gif
None.gif}

InspectWindow.mxml
None.gif <? xml version="1.0" encoding="utf-8" ?>
None.gif
None.gif
<!--
None.gif    Author: Christophe Coenraets, Macromedia. Blog: http://coenraets.com
None.gif    Date:   11/5/2004
None.gif
-->
None.gif
None.gif
< mx:TitleWindow  xmlns:mx ="http://www.macromedia.com/2003/mxml"
None.gif    title
="Object Inspector"
None.gif    closeButton
="true"
None.gif    click
="deletePopUp()"
None.gif    initialize
="initComp()" >
None.gif
None.gif    
< mx:Metadata >
None.gif        [Event("debugEvent")]
None.gif    
</ mx:Metadata >
None.gif
None.gif    
< mx:Script >
None.gif        
<![CDATA[
None.gif
None.gif        function initComp() {
None.gif            this.addEventListener("debugEvent", mx.utils.Delegate.create(_root, doDebugEvent));
None.gif        }
None.gif
None.gif        function inspect() {
None.gif            var e=expr.text;
None.gif            dispatchEvent({type: 'debugEvent', expression: e, debugWindow: this})
None.gif        }
None.gif
None.gif        function doDebugEvent(event) {
None.gif            var value=eval(event.expression);
None.gif            event.debugWindow.addNode(event.debugWindow.objectTree, event.debugWindow.objectTree, event.expression, value);
None.gif        }
None.gif
None.gif        function doNodeOpen(event) {
None.gif            var nodeData=event.node.getData();
None.gif            var value=nodeData.value;
None.gif            if (!nodeData.loaded) {
None.gif                if (value instanceof Array) {
None.gif                    for (var i=0; i<value.length; i++)
None.gif                        addNode(objectTree, event.node, "["+i+"]", value[i]);
None.gif                } else if (value instanceof Object) {
None.gif                    for (var i in value)
None.gif                        addNode(objectTree, event.node, i, value[i]);
None.gif                }
None.gif                nodeData.loaded=true;
None.gif            }
None.gif        }
None.gif
None.gif        function addNode(tree, parentNode, attrName, attrValue) {
None.gif            var type=typeof attrValue;
None.gif            if (type=="string" || type=="number" || type=="boolean") {
None.gif                parentNode.addTreeNode(attrName +": "+type+" = "+attrValue);
None.gif            } else if (attrValue instanceof Date) {
None.gif                parentNode.addTreeNode(attrName +": Date = "+attrValue);
None.gif            } else if (attrValue instanceof Array) {
None.gif                if (attrValue.length==0)
None.gif                    parentNode.addTreeNode(attrName +": Array (length: 0)");
None.gif                else {
None.gif                    var node=parentNode.addTreeNode(attrName +" = Array (length: "+attrValue.length+")", {loaded: false, value: attrValue});
None.gif                    tree.setIsBranch(node, true);
None.gif                }
None.gif            } else if (attrValue instanceof Object) {
None.gif                if (attrValue.className!=null) {
None.gif                    type=attrValue.className;
None.gif                }
None.gif                var isBranch=false;
None.gif                for (var i in attrValue) {
None.gif                    isBranch=true;
None.gif                    break;
None.gif                }
None.gif                if (isBranch) {
None.gif                    var node=parentNode.addTreeNode(attrName+": "+type, {loaded: false, value: attrValue});
None.gif                    tree.setIsBranch(node, true);
None.gif                } else {
None.gif                    parentNode.addTreeNode(attrName+": "+type);
None.gif                }
None.gif            }
None.gif        }
None.gif
None.gif        
]]>
None.gif    
</ mx:Script >
None.gif
None.gif    
< mx:Tree  id ="objectTree"  openDuration ="0"  width ="100%"  height ="100%"  nodeOpen ="doNodeOpen(event)" />
None.gif
None.gif    
< mx:ControlBar >
None.gif        
< mx:Label  text ="Object to inspect:" />
None.gif        
< mx:TextInput  id ="expr"  width ="100%"  keyDown ="if(event.code==13) inspect();" />
None.gif        
< mx:Button  label ="Inspect"  click ="inspect()"  width ="65" />
None.gif        
< mx:Button  label ="Clear"  click ="objectTree.removeAll()"  width ="65" />
None.gif    
</ mx:ControlBar >
None.gif
None.gif
</ mx:TitleWindow >
None.gif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值