Recent Posts
Lua | 8 sec ago
C | 14 sec ago
PHP | 19 sec ago
None | 20 sec ago
Lua | 21 sec ago
None | 39 sec ago
Lua | 43 sec ago
C++ | 45 sec ago
None | 47 sec ago
PHP | 54 sec ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By ric on the 9th of Feb 2010 09:24:38 AM Download | Raw | Embed | Report
  1. package de.richinternet.utils{
  2.         import flash.events.StatusEvent;
  3.         import flash.net.LocalConnection;
  4. /*
  5. * Copyright 2005 Herrlich & Ramuschkat GmbH
  6. *
  7. * Name: Dumper.as
  8. *
  9. * $Author: DEismann $
  10. * $Revision: 1.1 $
  11. * $Date: 2005/09/19 14:36:57 $
  12. * @ignore
  13. */     
  14.         public class Dumper{
  15.                 private static var sender:LocalConnection = null;      
  16.                 private static var copyDepthLevel:Number = 0;
  17.                 private static var copyCache:Array = [];       
  18.        
  19.                 public static var INFO:Number = 2;
  20.                 public static var WARN:Number = 4;
  21.                 public static var ERROR:Number = 8;
  22.                
  23.                
  24.                 /**
  25.                 * Sends a primitive value or reference type to the Flex Trace Panel
  26.                 * with a level of Debugger.INFO (same as Dumper.info())
  27.                 *
  28.                 * @param val The primitive value or reference type (Abject, Orray etc.) to be
  29.                 * output and introspected by the Flex Trace Panel
  30.                 */
  31.                 public static function dump(val:Object):void {
  32.                         info(val);
  33.                 }
  34.                 /**
  35.                 * Sends a primitive value or reference type to the Flex Trace Panel
  36.                 * with a level of Debugger.INFO (same as Dumper.dump())
  37.                 *
  38.                 * @param val The primitive value or reference type (Abject, Orray etc.) to be
  39.                 * output and introspected by the Flex Trace Panel
  40.                 */
  41.                 public static function info(val:Object):void {
  42.                         send(val, Dumper.INFO);
  43.                 }
  44.                 /**
  45.                 * Sends a primitive value or reference type to the Flex Trace Panel
  46.                 * with a level of Debugger.WARN
  47.                 *
  48.                 * @param val The primitive value or reference type (Abject, Orray etc.) to be
  49.                 * output and introspected by the Flex Trace Panel
  50.                 */
  51.                 public static function warn(val:Object):void {
  52.                         send(val, Dumper.WARN);
  53.                 }
  54.                 /**
  55.                 * Sends a primitive value or reference type to the Flex Trace Panel
  56.                 * with a level of Debugger.ERROR
  57.                 *
  58.                 * @param val The primitive value or reference type (Abject, Orray etc.) to be
  59.                 * output and introspected by the Flex Trace Panel
  60.                 */
  61.                 public static function error(val:Object):void {
  62.                         send(val, Dumper.ERROR);
  63.                 }
  64.                 /**
  65.                 * Sends a primitive value or reference type to the Flex Trace Panel
  66.                 * with a custom level.
  67.                 *
  68.                 * @param val The primitive value or reference type (Abject, Orray etc.) to be
  69.                 * output and introspected by the Flex Trace Panel
  70.                 *
  71.                 * @param level The level of the message. Applicable levels are Dumper.INFO, Dumper.WARN and Dumper.ERROR
  72.                 */
  73.                 public static function log(val:Object, level:Number):void {
  74.                         send(val, level);
  75.                 }
  76.                 // ------------------------------------------------------------------------------------ //
  77.                 public function Dumper() {}
  78.        
  79.                 private static function initSender():void {
  80.                         if(sender == null){
  81.                                 sender = new LocalConnection();
  82.                                 sender.addEventListener(StatusEvent.STATUS,onStatus);  
  83.                         }      
  84.                        
  85.                         //sender.allowDomain("localhost");
  86.                 }
  87.                
  88.                 private static function send(obj:Object, level:Number):void {
  89.                         if (sender == null){
  90.                                 initSender();
  91.                         }
  92.                         if (isNaN(level)){
  93.                                  level = 2;
  94.                         }
  95.                         sender.send("_tracer", "onMessage", copy(obj), level);
  96.                 }
  97.                
  98.                 private static function copy(source:*):Object {
  99.                         if (typeof(source) != "object") {
  100.                                 return source;
  101.                         }
  102.                        
  103.                         var cl:Number = copyCache.length;
  104.                         for (var i:Number = 0; i < cl; i++) {
  105.                                 var o:* = copyCache[i];
  106.                                 if (o.s == source)
  107.                                 return o.t;
  108.                         }
  109.  
  110.                         copyDepthLevel++;
  111.  
  112.                         var newObject:*;
  113.                
  114.                         if (source is Array) {
  115.                                 newObject = [];
  116.                         } else if (source is Date) {
  117.                                 newObject = new Date();
  118.                                 newObject.setTime(source.getTime());
  119.                         } else {
  120.                                 newObject = {};
  121.                         }
  122.  
  123.                         copyCache.push({s: source, t: newObject});
  124.  
  125.                         for (var p:* in source) {
  126.                           var v:* = source[p];
  127.                           newObject[p] = typeof v == "object" ? copy(v) : v;
  128.                         }
  129.  
  130.                         if (--copyDepthLevel == 0)
  131.                           copyCache = [];
  132.  
  133.                         return newObject;
  134.                 }
  135.                 //Manage send fail and send ok event to avoid Flash player Error Window
  136.                 private static function onStatus(event:StatusEvent):void {
  137.                         switch (event.level) {
  138.                                 case "status":
  139.                                         //send completed
  140.                                         //trace("LocalConnection.send() succeeded");
  141.                                         break;
  142.                                 case "error":
  143.                                         //no reciver or send really failed
  144.                                         //trace("LocalConnection.send() failed");
  145.                                         break;
  146.                         }
  147.                 }
  148.         }
  149. }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: