/* * Copyright (c) 2005 Pablo Costantini (www.luminicbox.com). All rights reserved. * * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.mozilla.org/MPL/MPL-1.1.html * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import LuminicBox.Log.IPublisher; import LuminicBox.Log.LogEvent; /** * Publishes logging messages into the FlashInspector (if available)
* This publisher can be used in any enviroment as long as the FlashInspector is running. It can be used from inside the Flash editor or from the final production enviroment. This allows to see the logging messages even after the final SWF is in production. */ class LuminicBox.Log.ConsolePublisher implements IPublisher { private var _version:Number=0.1; private var _maxDepth:Number; /** * Sets the max. inspection depth.
* The default value is 4. * The max. valid value is 255. */ function set maxDepth(value:Number) { _maxDepth = (_maxDepth>255)?255:value; } /** * Gets the max. inspection depth */ function get maxDepth():Number { return _maxDepth; } /** * Return the publishers type name: "ConsolePublisher". */ function toString():String { return "ConsolePublisher"; } /** * Creates a ConsolePublisher instance with a default max. inspection depth of 4. */ function ConsolePublisher() { _maxDepth = 4; } /** * Serializes and sends a log message to the FlashInspector window. */ function publish(e:LogEvent):Void { var o:Object = LogEvent.serialize(e); o.argument = serializeObj(o.argument,1); var lc = new LocalConnection(); lc.send("_luminicbox_log_console", "log", o); } private function serializeObj(o,depth:Number) { var type = getType(o); var serial = new Object(); if(!type.inspectable) { serial.value = o; } else if(type.stringify) { serial.value = o+""; } else { if(depth <= _maxDepth) { if(type.name == "movieclip" || type.name == "button") serial.id = o + ""; var items:Array = new Array(); if(o instanceof Array) { for(var pos:Number=0; pos