1 | package {
|
---|
2 | import org.flashdevelop.utils.FlashConnect;
|
---|
3 | import com.serialization.json.JSON;
|
---|
4 |
|
---|
5 | public class tr {
|
---|
6 |
|
---|
7 | public static function ace( o:Object ):void {
|
---|
8 | if ( o == null )
|
---|
9 | FlashConnect.trace( 'null' );
|
---|
10 | else
|
---|
11 | FlashConnect.trace( o.toString() );
|
---|
12 |
|
---|
13 | // var tempError:Error = new Error();
|
---|
14 | // var stackTrace:String = tempError.getStackTrace();
|
---|
15 | // FlashConnect.trace( 'stackTrace:' + stackTrace );
|
---|
16 |
|
---|
17 | if ( false )
|
---|
18 | tr.trace_full();
|
---|
19 | }
|
---|
20 |
|
---|
21 | //
|
---|
22 | // e.g: tr.aces( 'my val', val );
|
---|
23 | //
|
---|
24 | public static function aces( ... optionalArgs ):void {
|
---|
25 |
|
---|
26 | var tmp:Array = [];
|
---|
27 | for each( var o:Object in optionalArgs )
|
---|
28 | {
|
---|
29 | // FlashConnect.trace( o.toString() );
|
---|
30 | if ( o == null )
|
---|
31 | tmp.push( 'null' );
|
---|
32 | else
|
---|
33 | tmp.push( o.toString() );
|
---|
34 | }
|
---|
35 |
|
---|
36 | FlashConnect.trace( tmp.join(', ') );
|
---|
37 | }
|
---|
38 |
|
---|
39 | // this doesn't work cos I don't know how to set 'permit debugging' yet
|
---|
40 | /**
|
---|
41 | * Found this at:
|
---|
42 | * http://www.ultrashock.com/forums/actionscript/can-you-trace-a-line-95261.html
|
---|
43 | */
|
---|
44 | static public function ace_full(snum:uint=3):void
|
---|
45 | {
|
---|
46 | // FROM:
|
---|
47 | // http://snippets.dzone.com/posts/show/3703
|
---|
48 | //----------------------------------------------------------------------------------------------------------------
|
---|
49 | // With debugging turned on, this is what we get:
|
---|
50 | //
|
---|
51 | // Error
|
---|
52 | // <tab>at com.flickaway::Trace$/log_full()[D:\web\flickaway_branch\flash\lib\com\flickaway\Trace.as:83]
|
---|
53 | // <tab>at com.flickaway::Trace$/print_r_full()[D:\web\flickaway_branch\flash\lib\com\flickaway\Trace.as:114]
|
---|
54 | // <tab>at com.flickaway::Trace$/print_r()[D:\web\flickaway_branch\flash\lib\com\flickaway\Trace.as:46]
|
---|
55 | // <tab>at com.flickaway::Params()[D:\web\flickaway_branch\flash\lib\com\flickaway\Params.as:36] <==== this line we want
|
---|
56 | // <tab>at com.flickaway::Params$/get_instance()[D:\web\flickaway_branch\flash\lib\com\flickaway\Params.as:27]
|
---|
57 | // <tab>at HomeDefault()[D:\web\flickaway_branch\flash\homepage\HomeDefault.as:57]
|
---|
58 | // <tab>at com.flickaway::Params()[D:\web\flickaway_branch\flash\lib\com\flickaway\Params.as:36])
|
---|
59 | //
|
---|
60 | // with debugging turned off:
|
---|
61 | //
|
---|
62 | // Error
|
---|
63 | // <tab>at com.flickaway::Trace$/log_full()
|
---|
64 | // <tab>at com.flickaway::Trace$/print_r_full()
|
---|
65 | // <tab>at com.flickaway::Trace$/print_r()
|
---|
66 | // <tab>at com.flickaway::Params()
|
---|
67 | // <tab>at com.flickaway::Params$/get_instance()
|
---|
68 | // <tab>at HomeDefault()
|
---|
69 | //----------------------------------------------------------------------------------------------------------------
|
---|
70 | var e:Error = new Error();
|
---|
71 | var str:String = e.getStackTrace(); // get the full text str
|
---|
72 |
|
---|
73 | if (str == null) // means we aren't on the Debug player
|
---|
74 | {
|
---|
75 | FlashConnect.trace( "(!debug) " );
|
---|
76 | }
|
---|
77 | else
|
---|
78 | {
|
---|
79 | var stacks:Array = str.split("\n"); // split into each line
|
---|
80 | var caller:String = tr.gimme_caller(stacks[snum]); // get the caller for just one specific line in the stack trace
|
---|
81 | FlashConnect.trace( caller );
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Returns a string like "[HomeDefault():51]" - line number present only if "permit debugging" is turned on.
|
---|
87 | */
|
---|
88 | static private function gimme_caller(line:String):String
|
---|
89 | {
|
---|
90 | //-------------------------------------------------------------------------------------------------
|
---|
91 | // the line can look like any of these (so we must be able to clean up all of them):
|
---|
92 | //
|
---|
93 | // <tab>at com.flickaway::Params()
|
---|
94 | // <tab>at com.flickaway::Params()[D:\web\flickaway_branch\flash\lib\com\flickaway\Params.as:36]
|
---|
95 | // <tab>at HomeDefault()
|
---|
96 | // <tab>at HomeDefault()[D:\web\flickaway_branch\flash\homepage\HomeDefault.as:57]
|
---|
97 | //-------------------------------------------------------------------------------------------------
|
---|
98 | var dom_pos:int = line.indexOf("::"); // find the '::' part
|
---|
99 | var caller:String;
|
---|
100 |
|
---|
101 | if (dom_pos == -1)
|
---|
102 | {
|
---|
103 | caller = line.substr(4); // just remove '<tab>at ' beginning part (4 characters)
|
---|
104 | }
|
---|
105 | else
|
---|
106 | {
|
---|
107 | caller = line.substr(dom_pos+2); // remove '<tab>at com.flickaway::' beginning part
|
---|
108 | }
|
---|
109 | var lb_pos:int = caller.indexOf("["); // get position of the left bracket (lb)
|
---|
110 |
|
---|
111 | if (lb_pos == -1) // if the lb doesn't exist (then we don't have "permit debugging" turned on)
|
---|
112 | {
|
---|
113 | return "[" + caller + "]";
|
---|
114 | }
|
---|
115 | else
|
---|
116 | {
|
---|
117 | var line_num:String = caller.substr(caller.lastIndexOf(":")); // find the line number
|
---|
118 | caller = caller.substr(0, lb_pos); // cut it out - it'll look like ":51]"
|
---|
119 | return "[" + caller + line_num; // line_num already has the trailing right bracket
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 |
|
---|
125 |
|
---|
126 | public static function ace_json( json:Object ):void {
|
---|
127 | tr.ace(JSON.serialize(json));
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|