📄 airintrospector.js
字号:
htmlLoader = air.Introspector.runtime.HTMLLoader.createRootWindow(false); air.Introspector.addEventListener(htmlLoader, air.Introspector.runtime.Event.HTML_DOM_INITIALIZE, function(){ try{ air.Introspector.removeEventListener(htmlLoader, air.Introspector.runtime.Event.HTML_DOM_INITIALIZE, arguments.callee); htmlLoader.window.initCallbacks = loadDebugger.initCallbacks; htmlLoader.window.isLoaded = false; htmlLoader.window.config = air.Introspector.config; htmlLoader.window.activateDebug = activateDebug; htmlLoader.window.isAppSandbox = isAppSandbox; }catch(e){ air.Introspector.runtime.trace(e); air.Introspector.runtime.trace(e.line); } }); htmlLoader.window.isLoaded = false; var nativeWindow = htmlLoader.stage.nativeWindow; nativeWindow.width = 640; nativeWindow.height = 480; air.Introspector.addEventListener(htmlLoader, runtime.flash.events.HTMLUncaughtScriptExceptionEvent.UNCAUGHT_SCRIPT_EXCEPTION, function(e){ air.Introspector.logError(e.exceptionValue, {htmlLoader: self.htmlLoader}); e.preventDefault(); }); if(typeof air.Introspector.config.useAirDebugHtml=='undefined'||air.Introspector.config.useAirDebugHtml==false){ try{ //since AIR1.5 the htmlLoader will not allow string load in app sandbox //surrownded with try/catch in case we are running in older runtime htmlLoader.allowLoadStringInAppSandbox = true; }catch(e){} htmlLoader.loadString(air.Introspector.contentString); try{ //switch it back to false after load is complete htmlLoader.allowLoadStringInAppSandbox = false; }catch(e){} }else{ htmlLoader.load(new air.Introspector.runtime.URLRequest('app:/DebugUI.html')); } }else{ air.Introspector.noBridge(function(){ var w = air.Introspector.tryCreateWindow(loadDebugger.initCallbacks); if(w){ var htmlLoader = {window: w}; loadDebugger.htmlLoader = htmlLoader; } }); } loadDebugger.htmlLoader = htmlLoader; }, /** * @function findDebugWindow * @description Look up the Introspector in other windows. Maybe somebody else just opened it before us. */ findDebugWindow: function(){ if(isAppSandbox){ try{ if(air.Introspector.debugWindow&&air.Introspector.debugWindow.nativeWindow.closed==false) return air.Introspector.debugWindow; }catch(e){ } try{ var htmlWindows = air.Introspector.getHtmlWindows(true); for(var i=htmlWindows.length-1;i>=0;i--){ try{ if(typeof htmlWindows[i].htmlLoader.window.air!='undefined' && typeof htmlWindows[i].htmlLoader.window.air.Introspector!='undefined' && typeof htmlWindows[i].htmlLoader.window.air.Introspector.debugWindow!='undefined' && htmlWindows[i].htmlLoader.window.air.Introspector.debugWindow.nativeWindow.closed==false && htmlWindows[i].htmlLoader.window.isAppSandbox ) { return htmlWindows[i].htmlLoader.window.air.Introspector.debugWindow; } }catch(e){ //this window is not initialized yet //just get next window } } }catch(e){} }else{ return air.Introspector.debugWindow; } return null; }, //application browser formats // 0 - text // 1 - images // 2 - xml (you may want to add your own xml type here) formats : { 'png':1, 'gif':1, 'zip':1, 'air':1, 'jpg':1, 'jpeg':1, 'txt':0, 'html':0, 'js':0, 'xml':2, 'opml':2, 'css':0, 'htm':0, '':0 }, /** * @function canInit * @description Check if we got parentSandboxBridge available * @disabled */ canInit: function(){/* if(!isAppSandbox&&typeof parentSandboxBridge=='undefined'){ alert('You need to include AIRIntrospector.js in application sandbox too!'); return false; }*/ return true; }, /** * @function logArguments * @description */ logArguments: function(args, config){ if(!air.Introspector.canInit()) return; config.timestamp = new Date(); air.Introspector.init(config.type=='error', true, function(){ air.Introspector.debugWindow.logArguments(args, config); }); }, /** * @function logError * @description */ logError: function(error, config){ air.Introspector.init(false, true, function(){ air.Introspector.debugWindow.logError(error, config); }); }, /** * @function showCssElement * @description */ showCssElement: function(element){ var debugWindow = air.Introspector.findDebugWindow(); if(debugWindow){ debugWindow.showCssElement(element); } }, checkIfIsInstanceOfHTMLLoader: function (child){ var className = runtime.flash.utils.getQualifiedClassName(child); if( className == "flash.html::HTMLLoader" ) return true; if( className == "mx.core::FlexHTMLLoader" ) return true; return false; }, /** * @function findLoader * @description Finds the first HTMLLoader in flash display object list */ findLoader: function (stage, loaders){ try{ for(var i=stage.numChildren-1;i>=0;i--){ var child = stage.getChildAt(i); if(air.Introspector.checkIfIsInstanceOfHTMLLoader(child)){ loaders.push([child]); }else if(child.htmlLoader!=null&&air.Introspector.checkIfIsInstanceOfHTMLLoader(child.htmlLoader)){ loaders.push([child.htmlLoader, child.id || child.toString()]); }else{ air.Introspector.findLoader(child, loaders); } } }catch(e){ } return null; }, /** * @function getHtmlWindows * @description Returns an array of all HTML windows */ getHtmlWindows: function(includeInspectors){ if(isAppSandbox){ var windowNodes = []; var windows = air.Introspector.runtime.NativeApplication.nativeApplication.openedWindows; for(var i=windows.length-1;i>=0;i--){ var loaders = []; air.Introspector.findLoader(windows[i].stage, loaders); for(var j=loaders.length-1;j>=0;j--){ var loaderItem = loaders[j]; var loader = loaderItem[0]; var label = loaderItem[1]; if(typeof includeInspectors=='undefined' && typeof loader.window!='undefined' && typeof loader.window.air!='undefined' && typeof loader.window.air.Introspector!='undefined' && typeof loader.window.air.Introspector.localIframeDebug != 'undefined' ){ continue; } windowNodes.push({ nativeWindow: windows[i], stage: windows[i].stage, htmlLoader : loader, label: label }); } } return windowNodes; }else{ //should not be here return []; } }, /** * @function twoDigits * @description int 2 string with two digits */ twoDigits: function(val){ if(val<10) return '0'+val; return val+''; }, /** * @function escapeHtml * @description Escapes html in order to display it in html */ escapeHtml: function(html){ return (html+'').replace(/&/g, '&').replace(/"/g, """).replace(/</g, '<').replace(/>/g, '>'); }, tree: { }, /** * @function isNumberObject * @description */ isNumberObject: function(obj){ try{ //can we catch isNaN only for NaN return (obj+0==obj&&!isNaN(obj)); }catch(e){ } return false; }, /** * @function isStringObject * @description */ isStringObject: function(obj){ try{ return (typeof(obj.match) != "undefined" && obj.match.toString().indexOf("[native code]")>0); }catch(e){ } return false; }, /** * @function isDateObject * @description */ isDateObject: function(obj){ try{ return (typeof(obj.getDate) != "undefined" && obj.getDate.toString().indexOf("[native code]")>0); }catch(e){ } return false; }, /** * @function isArgumentsObject * @description */ isArgumentsObject: function(obj){ try{ return obj.toString()=='[object Arguments]'; }catch(e){ } return false; }, /** * @function isXMLObject * @description */ isXMLObject: function(obj){ try{ if(obj.xmlVersion&&obj.firstChild!=null) return obj.xmlVersion!=''; }catch(e){ } return false; }, /** * @function isArrayObject * @description */ isArrayObject: function(obj){ try{ return (typeof(obj.push) != "undefined" && obj.push.toString().indexOf("[native code]")>0); }catch(e){ } return false; }, /** * @function isItemNative * @description */ isItemNative: function(obj){ try{ return (typeof(obj.item) != "undefined" && obj.item.toString().indexOf("[native code]")>0); }catch(e){ } return false; }, /** * @function dump * @description */ dump: function (obj, levels, level){ if(air.Introspector.isArgumentsObject(obj)&&obj.length==1) return air.Introspector.dump(obj[0]); if(typeof levels=='undefined') { levels=1; } if(typeof level=='undefined') { level=0; } try{ if(typeof obj=='undefined'){ return '[undefined]'; } if(obj==null){ return '[null]'; } var list = [];// if(air.Introspector.isXMLObject(obj)){// disable for the moment// return;// } if(air.Introspector.isStringObject(obj) ||air.Introspector.isNumberObject(obj) ||air.Introspector.isDateObject(obj)){ if(level==0){ try{ return obj+''; }catch(e){ return e+''; }; } return''; } var isItemNative = air.Introspector.isItemNative(obj); var parseArray = air.Introspector.isArrayObject(obj)||air.Introspector.isArgumentsObject(obj)||isItemNative; var parseHash = !parseArray || isItemNative; if (parseArray){ var l = obj.length; for(var i=0;i<l;i++){ var value; try{ value = obj[i]; if(typeof value=='undefined') {value = '[undefined]'}; }catch(e){ value = e+''; } list.push([i,value]); } } if(parseHash) { for(var i in obj){ var value; try{ value = obj[i]; if(typeof value=='undefined') {value = '[undefined]'}; }catch(e){ value = e+''; } list.push([i,value]); } } if(air.Introspector.config.debugRuntimeObjects && !parseArray){ try{ var typeDescription = runtime.flash.utils.describeType(obj); if(!this.domParser) this.domParser = new DOMParser(); var typeXml = this.domParser.parseFromString(typeDescription, "text/xml"); var child = typeXml.firstChild.firstChild; while(child){ if(child.nodeName=='accessor'||child.nodeName=='constant'||child.nodeName=='method'||child.nodeName=='variable'){ var name = child.getAttribute('name'); if(name!=null && name!='prototype'){ try{ list.push([name,obj[name]]); }catch(e){ list.push([name,'']+''); } } } child = child.nextSibling; } }catch(e){ //just hide the error } } list.sort(function(node1, node2){ var isNode1Number = parseInt(node1[0])==node1[0]; var isNode2Number = parseInt(node2[0])==node2[0]; if(isNode1Number&&isNode2Number){ return parseInt(node1[0])-parseInt(node2[0]); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -