├── README.md
├── bin
├── Console.swc
├── ConsoleRemote.air
├── SampleBasic.swf
├── consoleRemote.swf
├── sampleAdvanced.swf
└── sampleStyle.swf
├── build
├── build.xml
├── ivy.tmpl
├── ivysettings.xml.template
├── local.properties.template
└── project.properties
├── doc
├── ASDoc.txt
├── Addons.txt
├── CommandLineHelp.txt
├── GettingStarted.txt
├── ReadMe.txt
├── console_controls.png
└── icons
│ ├── icon128.png
│ ├── icon16.png
│ ├── icon32.png
│ └── icon48.png
├── samples
├── SampleAssets.swf
├── flash
│ ├── ConsoleRemote.as
│ ├── SampleAdvanced.as
│ ├── SampleBasic.as
│ └── SampleStyle.as
└── remote_air
│ ├── ConsoleRemoteAIR-app.xml
│ └── ConsoleRemoteAIR.as
└── src
└── com
└── junkbyte
└── console
├── Cc.as
├── Console.as
├── ConsoleChannel.as
├── ConsoleConfig.as
├── ConsoleStyle.as
├── KeyBind.as
├── addons
├── autoFocus
│ └── CommandLineAutoFocusAddon.as
├── commandprompt
│ ├── CommandChoice.as
│ └── CommandPrompt.as
├── displaymap
│ ├── DisplayMapAddon.as
│ └── DisplayMapPanel.as
├── htmlexport
│ ├── ConsoleHTMLRefsGen.as
│ ├── ConsoleHtmlExportAddon.as
│ └── template.html
└── memoryRecorder
│ ├── MemoryRecorder.as
│ └── MemoryRecorderAddon.as
├── core
├── CommandLine.as
├── ConsoleCore.as
├── ConsoleTools.as
├── Executer.as
├── Graphing.as
├── KeyBinder.as
├── LogReferences.as
├── Logs.as
├── MemoryMonitor.as
└── Remoting.as
├── view
├── ChannelsPanel.as
├── ConsolePanel.as
├── GraphingPanel.as
├── MainPanel.as
├── PanelsManager.as
├── RollerPanel.as
└── Ruler.as
└── vos
├── GraphGroup.as
├── GraphInterest.as
├── Log.as
├── WeakObject.as
└── WeakRef.as
/README.md:
--------------------------------------------------------------------------------
1 | Flash-Console is Actionscript 3 logger/debugger for flash, flex and AIR.
2 | It comes with a collection of features to help speed up your development.
3 |
4 | Console overlays on top of your flash application. Remote logging feature is also available to log to an external console. No special browser or player version is required.
5 |
6 |
7 |
8 | #Main features
9 | * *Channels*
10 | * *Priorities* aka levels with colour code
11 | * *Object linking* where you can click on objects in log to inspect aka introspection
12 | * *[CommandLineHelp Command line]* _CL_ - lets you execute code at runtime (as3 syntax)
13 | * *[Remoting Remote logging]* also as Adobe AIR app
14 | * No dependencies, requirements and non-invasive
15 | * Super fast!
16 | * *[Addons]* adds specialized features
17 |
18 | #Other features
19 | * *filtering*/searching via exact match or regular expression
20 | * *Roller tool* _Ro_ - shows display map of what's under your mouse pointer
21 | * *Graph reporting* numeric values (such as FPS, memory, user definable)
22 | * *Ruler tool* _RL_ - Measure distances/degrees on screen
23 | * Garbage collection monitor - notifies you when objects of your interest are being garbage collected.
24 | * *Key-binding* to functions
25 | * Non-repetitive tracing
26 | * Customizable UI
27 | * Easy to remove when no longer needed
28 |
29 | Console adds 50KB to your SWF.
30 |
31 | #Controls
32 |
img
33 |
34 | #Demo
35 | * Demo Console: http://console.junkbyte.com/sample.html
36 | * Advanced features: http://console.junkbyte.com/advanced.html
37 | * Demo Remote Console: http://console.junkbyte.com/remote.html
38 | * To test the remote, open the normal console link and send messages to console to see that remote console also recieve the updates.
39 | * Custom style: http://console.junkbyte.com/style.html
40 |
41 | See ReadMe for requirements and changes log.
42 |
43 | See GettingStarted wiki for basic usages.
44 |
45 | Any bugs or feature requests, please use Issues tab: https://github.com/junkbyte/flash-console/issues
46 |
47 | Any comments (good / bad / feature requests) after using Console?
48 | Please email luaye (@at) junkbyte(.dot) com
49 | Thank you
50 |
51 |
52 | ----
53 | NOTE: This project is migrated from google codes repository https://code.google.com/p/flash-console/
54 |
--------------------------------------------------------------------------------
/bin/Console.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junkbyte/flash-console/3bbe291ed1d2f23b6e236cbed070f15699a7ff39/bin/Console.swc
--------------------------------------------------------------------------------
/bin/ConsoleRemote.air:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junkbyte/flash-console/3bbe291ed1d2f23b6e236cbed070f15699a7ff39/bin/ConsoleRemote.air
--------------------------------------------------------------------------------
/bin/SampleBasic.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junkbyte/flash-console/3bbe291ed1d2f23b6e236cbed070f15699a7ff39/bin/SampleBasic.swf
--------------------------------------------------------------------------------
/bin/consoleRemote.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junkbyte/flash-console/3bbe291ed1d2f23b6e236cbed070f15699a7ff39/bin/consoleRemote.swf
--------------------------------------------------------------------------------
/bin/sampleAdvanced.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junkbyte/flash-console/3bbe291ed1d2f23b6e236cbed070f15699a7ff39/bin/sampleAdvanced.swf
--------------------------------------------------------------------------------
/bin/sampleStyle.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junkbyte/flash-console/3bbe291ed1d2f23b6e236cbed070f15699a7ff39/bin/sampleStyle.swf
--------------------------------------------------------------------------------
/build/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | "Version ${build.version}${build.stage}. build ${build.number} @ ${build.date}"
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 | "Packaging to Zip. Make sure you have commited new files to SVN as it will only package versioned files."
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 | [IVY download] Downloading ivy jar into your ant's lib folder (${ANT_HOME}) ${ANT_HOME}/lib/ivy-${ivy.download.version}.jar from ${ivy.download.url}
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 | [IVY download] Done
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
--------------------------------------------------------------------------------
/build/ivy.tmpl:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
10 |
13 |
14 |
20 |
21 |
22 | Flash-Console is Actionscript 3 logger/debugger for flash, flex and AIR. It comes with a collection of features to help speed up your development.
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
39 |
--------------------------------------------------------------------------------
/build/ivysettings.xml.template:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/build/local.properties.template:
--------------------------------------------------------------------------------
1 | svnant.path = D:/Program Files (x86)/eclipse/svnant-1.3.0/lib/
2 | FLEX_HOME = D:/Program Files (x86)/flex_sdk_4.1
3 | ANT_HOME = E:/Development/__ant
4 | AIR_CERT_PASS = Console
5 |
6 | # ivy jar download settings
7 | # if downloading ivy specify the mirror from where to download. you can find the mirrors list here:
8 | # http://ant.apache.org/ivy/download.cgi -->
9 | ivy.download.mirror=http\://apache.deathculture.net
10 | ivy.download.version=2.2.0
11 | ivy.download.file=apache-ivy-${ivy.download.version}-bin.zip
12 | ivy.download.url=${ivy.download.mirror}/ant/ivy/${ivy.download.version}/${ivy.download.file}
--------------------------------------------------------------------------------
/build/project.properties:
--------------------------------------------------------------------------------
1 | #Wed Feb 22 00:11:41 GMT 2012
2 | build.number=611
3 | build.date=2012/02/22 00\:11
4 | build.version=2.6
5 | build.stage=
6 |
--------------------------------------------------------------------------------
/doc/ASDoc.txt:
--------------------------------------------------------------------------------
1 | #summary ASDoc
2 | #labels Phase-Deploy
3 |
4 |
5 |
6 | please see: http://console.junkbyte.com/2.6/asdoc
--------------------------------------------------------------------------------
/doc/Addons.txt:
--------------------------------------------------------------------------------
1 | #summary List of Console addons
2 | #labels Phase-Implementation
3 |
4 | Addons are located in samples/addons/com/junkbyte/console/addons
5 | These add functionality on top of base console.
6 | They are not compiled as part of SWC package at the moment as some may require additional libraries.
7 |
8 |
9 | ==Display Map==
10 | * Displays a panel mapping the display tree/map.
11 | * Start from code: `DisplayMapAddon.start();`
12 | * Add to menu: `DisplayMapAddon.addToMenu();`
13 | * Register to commandLine: `DisplayMapAddon.registerCommand();` use /mapdisplay, starts mapping from current command scope.
14 |
15 |
16 | ==HTML Export==
17 | * Export console logs to a HTML file. preserves channels and priorities.
18 | * It also have all those filtering features in HTML page.
19 | * Add to menu: `ConsoleHtmlExportAddon.addToMenu();`
20 | * blog: http://junkbyte.com/wp/as3/console/console-logs-to-html-export-addon/
21 | * Requires com.adobe.serialization.json.JSON. (May replace in your own code with flash player 11's native JSON)
22 |
23 |
24 | ==Command Prompt==
25 | * Simulates 'command prompt' style user input.
26 | * Ask to choose from a selection of input, user enter into command line to choose a selection.
27 | * Could be useful for 'utility' sort of app where there is no GUI to represent user options.
28 | * Currently undocumented. see source code of `CommandPrompt.as`.
29 |
30 |
31 | ==CommandLine Auto focus==
32 | * Sets focus to commandLine input field whenever Console becomes visible, e.g after entering password key.
--------------------------------------------------------------------------------
/doc/console_controls.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junkbyte/flash-console/3bbe291ed1d2f23b6e236cbed070f15699a7ff39/doc/console_controls.png
--------------------------------------------------------------------------------
/doc/icons/icon128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junkbyte/flash-console/3bbe291ed1d2f23b6e236cbed070f15699a7ff39/doc/icons/icon128.png
--------------------------------------------------------------------------------
/doc/icons/icon16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junkbyte/flash-console/3bbe291ed1d2f23b6e236cbed070f15699a7ff39/doc/icons/icon16.png
--------------------------------------------------------------------------------
/doc/icons/icon32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junkbyte/flash-console/3bbe291ed1d2f23b6e236cbed070f15699a7ff39/doc/icons/icon32.png
--------------------------------------------------------------------------------
/doc/icons/icon48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junkbyte/flash-console/3bbe291ed1d2f23b6e236cbed070f15699a7ff39/doc/icons/icon48.png
--------------------------------------------------------------------------------
/samples/SampleAssets.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junkbyte/flash-console/3bbe291ed1d2f23b6e236cbed070f15699a7ff39/samples/SampleAssets.swf
--------------------------------------------------------------------------------
/samples/flash/ConsoleRemote.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package
26 | {
27 | import com.junkbyte.console.Cc;
28 | import com.junkbyte.console.core.Remoting;
29 |
30 | import flash.display.*;
31 | import flash.events.*;
32 |
33 | [SWF(width='600',height='420',backgroundColor='0xCCCCCC',frameRate='60')]
34 | // used to compile in flex/fdt
35 | // Might want to add compile argument: -use-network=false
36 | // To compile in flash, point this class as document class.
37 | // comment out the metadata tag above if you are getting an error.
38 |
39 | public class ConsoleRemote extends Sprite {
40 |
41 | public function ConsoleRemote() {
42 |
43 | Cc.start(this);
44 | Cc.commandLine = true;
45 | Cc.config.maxLines = 2000;
46 | Cc.config.maxRepeats = 200;
47 | Cc.config.commandLineAllowed = true;
48 |
49 | // Start remote service.
50 | Cc.instance.remoter.remoting = Remoting.RECIEVER;
51 | // Disable scaling and moving
52 | Cc.instance.panels.mainPanel.moveable = false;
53 | Cc.instance.panels.mainPanel.scalable = false;
54 | //
55 |
56 | stage.scaleMode = StageScaleMode.NO_SCALE;
57 | stage.align = StageAlign.TOP_LEFT;
58 | stage.addEventListener(Event.RESIZE, onStageResize);
59 | onStageResize();
60 | }
61 | private function onStageResize(e : Event = null) : void {
62 | Cc.width = stage.stageWidth;
63 | Cc.height = stage.stageHeight;
64 | }
65 | }
66 | }
--------------------------------------------------------------------------------
/samples/flash/SampleAdvanced.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package
26 | {
27 | import com.junkbyte.console.Cc;
28 | import com.junkbyte.console.addons.autoFocus.CommandLineAutoFocusAddon;
29 | import com.junkbyte.console.addons.displaymap.DisplayMapAddon;
30 | import com.junkbyte.console.addons.htmlexport.ConsoleHtmlExportAddon;
31 |
32 | import flash.display.*;
33 | import flash.geom.Rectangle;
34 |
35 | [SWF(width='700',height='300',backgroundColor='0xFFFFFF',frameRate='30')]
36 | // Might want to add compile argument: -use-network=false -debug=true
37 |
38 | public dynamic class SampleAdvanced extends MovieClip{
39 |
40 | private var temp:Object = {object1:{subObj:{text:"Some randome text", number:123}, subArr:[2,3,4,5]}, object2:{arr:[3,4,5]}};
41 |
42 | public function SampleAdvanced() {
43 | stage.scaleMode = StageScaleMode.NO_SCALE;
44 | //
45 | // SET UP - only required once
46 | //
47 |
48 | Cc.startOnStage(this, "`"); // "`" - change for password. This will start hidden
49 | Cc.visible = true; // show console, because having password hides console.
50 | Cc.commandLine = true; // enable command line
51 | //Cc.memoryMonitor = true;
52 | //Cc.fpsMonitor = true;
53 | //Cc.displayRoller = true;
54 |
55 | Cc.config.commandLineAllowed = true;
56 | Cc.width = 700;
57 | Cc.height = 300;
58 | Cc.config.remotingPassword = ""; // Just so that remote don't ask for password
59 | Cc.remoting = true;
60 |
61 | Cc.addMenu("T1", Cc.log, ["Greetings 1"], "This is a test menu 1");
62 | Cc.addMenu("T2", Cc.log, ["Greetings 2"], "This is a test menu 2");
63 | Cc.addMenu("spam100k", spam, [100000]);
64 | //
65 | // End of setup
66 | //
67 | Cc.log("Lets try some object linking...");
68 | Cc.info("Here is a link to stage: ", stage);
69 | Cc.info("Here is a link to Cc class", Cc);
70 | Cc.info("Here is a link to Console instance", Cc.instance);
71 | //
72 | // HTML text
73 | Cc.addHTML("Here is HTML purple bold and italic text.");
74 | Cc.addHTMLch("html", 8, "Mix objects inside html like this >", this,"<");
75 |
76 | Cc.log("___");
77 |
78 | // explode an object into its values..
79 | Cc.log("Cc.explode() test:");
80 | Cc.explode(temp);
81 |
82 | Cc.log("___");
83 | Cc.info("Try the new search highlighting... Type '/filter link' in commandline below.");
84 | //
85 | Cc.addSlashCommand("test", function():void{ Cc.log("Do the test!");} );
86 | Cc.addSlashCommand("test2", function(param:String):void{Cc.log("Do the test 2 with param string:", param);} );
87 |
88 | //
89 | //Graphing feature examples
90 | //Graph the current mouseX and mouseY values
91 | Cc.addGraph("mouse", this,"mouseX", 0xff3333,"X", new Rectangle(560,180,80,80), true);
92 | Cc.addGraph("mouse", this,"mouseY", 0x3333ff,"Y");
93 | // Sine wave graph generated by commandline execution, very expensive way to graph but it works :)
94 | Cc.addGraph("mouse", this,"(Math.sin(flash.utils.getTimer()/1000)*300)+300", 0x119911,"sine");
95 |
96 | //
97 | // Garbage collection monitor
98 | var aSprite:Sprite = new Sprite();
99 | Cc.watch(aSprite, "aSprite");
100 | aSprite = null;
101 | // it probably won't get garbage collected straight away,
102 | // but if you have debugger version of flash player installed,
103 | // you can open memory monitor (M) and then press G in that panel to force garbage collect
104 | // You will see "[C] GARBAGE COLLECTED 1 item(s): aSprite"
105 |
106 |
107 | // register 'export' button, which exports logs to HTML. (This is an addon).
108 | // source file located at samples/addons/ com.junkbyte.console.addons.htmlexport.ConsoleHtmlExport
109 | // requires JSON: com.adobe.serialization.json.JSON
110 | ConsoleHtmlExportAddon.addToMenu();
111 |
112 |
113 | DisplayMapAddon.registerCommand();
114 | DisplayMapAddon.addToMenu("DM"); // DisplayMapper. click on DM button at top menu to start.
115 |
116 |
117 | CommandLineAutoFocusAddon.registerToConsole(); // this addon auto focus to commandline when console becomes visible
118 |
119 | // Test of Cc.stack, If you have debugger version installed you will see a stack trace like:
120 | // HELLO
121 | // @ SampleAdvanced/e()
122 | // @ SampleAdvanced/d()
123 | // @ SampleAdvanced/c()
124 | a(); // see function e() below
125 |
126 | }
127 | private function a():void{
128 | b();
129 | }
130 | private function b():void{
131 | c();
132 | }
133 | private function c():void{
134 | d();
135 | }
136 | private function d():void{
137 | e();
138 | }
139 | private function e():void{
140 | Cc.stack("Hello from stack trace.");
141 | }
142 | private function spam(chars:int):void{
143 | var str:String = "";
144 | while(str.length < chars){
145 | str += "12345678901234567890123456789012345678901234567890123456789012345678901234567890";
146 | }
147 | Cc.log(str.substring(0, chars));
148 | Cc.log("<<",chars,"chars.");
149 | }
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/samples/flash/SampleBasic.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package
26 | {
27 | import com.junkbyte.console.Cc;
28 | import com.junkbyte.console.Console;
29 | import com.junkbyte.console.ConsoleChannel;
30 |
31 | import flash.display.*;
32 | import flash.events.*;
33 | import flash.text.TextField;
34 | import flash.utils.*;
35 |
36 | [SWF(width='640',height='480',backgroundColor='0xDDDDDD',frameRate='30')]
37 | public class SampleBasic extends MovieClip{
38 |
39 | [Embed(source="../SampleAssets.swf", symbol="SampleScreenClip", mimeType="application/x-shockwave-flash" )]
40 | public var ScreenClipClass:Class;
41 | public var screenClip:Sprite;
42 |
43 | private var _spamcount:int;
44 |
45 | public function SampleBasic() {
46 |
47 | //
48 | // SET UP - only required once
49 | //
50 | Cc.config.style.backgroundAlpha = 1;
51 |
52 | Cc.startOnStage(this, "`"); // "`" - change for password. This will start hidden
53 | Cc.visible = true; // Show console, because having password hides console.
54 |
55 | Cc.config.commandLineAllowed = true; // enable advanced (but security risk) features.
56 | Cc.config.tracing = true; // Also trace on flash's normal trace
57 | Cc.config.remotingPassword = ""; // Just so that remote don't ask for password
58 | Cc.remoting = true; // Start sending logs to remote (using LocalConnection)
59 |
60 | Cc.commandLine = true; // Show command line
61 |
62 | Cc.height = 220; // change height. You can set x y width height to position/size the main panel
63 | //
64 | // End of setup
65 | //
66 |
67 | demoBasics();
68 |
69 | setupUI();
70 | }
71 |
72 | private function demoBasics():void
73 | {
74 | Cc.log("Hello world.");
75 | Cc.info("An info message.", "Optionally there", "can be", "multiple arguments.");
76 | Cc.debug("A debug level log.", "You can also pass an object and it'll become a link to inspect:", this);
77 | Cc.warn("This is a warning log.", "Lets try the object linking again:", stage, " <- click it! (press 'exit' when done)");
78 | Cc.error("This is an error log.", "This link might not work because it can get garbage collected:", new Sprite());
79 | Cc.fatal("This is a fatal error log with high visibility.", "Also gets a stack trace on debug player...");
80 | //
81 | // Basic channel logging
82 | //
83 | Cc.infoch("myChannel", "Hello myChannel.");
84 | Cc.debugch("myChannel", "A debug level log.", "There is also Cc.errorch() and Cc.fatalch(). Skipping that for demo.");
85 | //
86 | // Instanced channel
87 | //
88 | var ch:ConsoleChannel = new ConsoleChannel('myCh');
89 | ch.info("Hello!", "Works just like other logging methods but this way you keep the channel as an instance.");
90 |
91 | //
92 | // Stack tracing
93 | //
94 | Cc.stack("Stack trace called from... (need debug player)");
95 | /* //If you have debug player, it'll show up in console as:
96 | Stack trace called from... (need debug player)
97 | @ Sample/demoBasics()
98 | @ Sample()
99 | */
100 | // Use Cc.stackch(...) to have channel name.
101 |
102 | //
103 | // Advanced logging
104 | //
105 | Cc.add("My advanced log in priority 2, 1st call", 2, true);
106 | Cc.add("My advanced log in priority 2, 2nd call", 2, true);
107 | Cc.add("My advanced log in priority 2, 3rd call", 2, true);
108 | Cc.add("My advanced log in priority 2, 4th call", 2, true);
109 | Cc.add("My advanced log in priority 2, 5th call", 2, true);
110 | // When 'no repeat' (3rd param) is set to true, it will not generate new lines for each log.
111 | // It will keep replacing the previous line with repeat turned on until a certain count is passed.
112 | // For example, if you are tracing download progress and you don't want to flood console with it.
113 | // If you want to specify the channel, use:
114 | // Use Cc.ch(channel:*, str:*, priority:int, isRepeating:Boolean)
115 | }
116 | //
117 | //
118 | //
119 | private function setupUI():void{
120 | screenClip = new ScreenClipClass();
121 | addChild(screenClip);
122 | getScreenChild("mcBunny").head.stop();
123 | TextField(getScreenChild("version")).text = "v"+Console.VERSION+Console.VERSION_STAGE;
124 | TextField(getScreenChild("txtPriority")).restrict = "0-9";
125 | TextField(getScreenChild("txtPriority2")).restrict = "0-9";
126 | setUpButton("btnInterval", "Start interval");
127 | setUpButton("btnAdd1", "Add");
128 | setUpButton("btnAdd2", "Add");
129 | setUpButton("btnSpam", "Spam");
130 | }
131 | private function getScreenChild(n:String):Object{
132 | return screenClip.getChildByName(n);
133 | }
134 | private function setUpButton(btnname:String, t:String):void{
135 | var btn:MovieClip = getScreenChild(btnname) as MovieClip;
136 | btn.stop();
137 | btn.buttonMode = true;
138 | btn.mouseChildren = false;
139 | btn.txt.text = t;
140 | btn.addEventListener(MouseEvent.CLICK, onButtonClick);
141 | btn.addEventListener(MouseEvent.ROLL_OVER, onButtonEvent);
142 | btn.addEventListener(MouseEvent.ROLL_OUT, onButtonEvent);
143 | }
144 | private function onButtonEvent(e:MouseEvent):void{
145 | MovieClip(e.currentTarget).gotoAndStop(e.type==MouseEvent.ROLL_OVER?"over":"out");
146 | }
147 | private function onButtonClick(e:MouseEvent):void{
148 | switch(MovieClip(e.currentTarget).name){
149 | case "btnAdd1":
150 | Cc.add(getScreenChild("txtLog").text,int(getScreenChild("txtPriority").text));
151 | break;
152 | case "btnAdd2":
153 | var ch:String = getScreenChild("txtChannel").text;
154 | var txt:String = getScreenChild("txtLog2").text;
155 | var lvl:int = int(getScreenChild("txtPriority2").text);
156 | Cc.ch(ch, txt, lvl);
157 | break;
158 | case "btnInterval":
159 | if(_interval){
160 | clearInterval(_interval);
161 | _interval = 0;
162 | getScreenChild("btnInterval").txt.text = "Start Interval";
163 | }else{
164 | _interval = setInterval(onIntervalEvent, 50);
165 | getScreenChild("btnInterval").txt.text = "Stop Interval";
166 | }
167 | break;
168 | case "btnSpam":
169 | spam();
170 | break;
171 | }
172 | }
173 | private function onIntervalEvent():void{
174 | Cc.ch("test", "Repeative log _ " + getTimer(), 5,true);
175 | }
176 | private function spam():void{
177 | for(var i:int = 0;i<100;i++){
178 | var str:String = "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.";
179 | var rand:int = Math.random()*5;
180 | if(rand == 1){
181 | str = "Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam,";
182 | }else if(rand == 2){
183 | str = "At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi";
184 | }else if(rand == 3){
185 | str = "Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae.";
186 | }else if(rand == 4){
187 | str = "Itaque earum rerum hic tenetur a sapiente delectus.";
188 | }else if(rand == 5){
189 | str = "voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis";
190 | }
191 | _spamcount++;
192 | Cc.ch("ch"+Math.round(Math.random()*5), _spamcount+" "+str, Math.round(Math.random()*4));
193 | }
194 | }
195 |
196 | private var _interval:uint;
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/samples/flash/SampleStyle.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package
26 | {
27 | import com.junkbyte.console.Cc;
28 |
29 | import flash.display.*;
30 |
31 | [SWF(width='640',height='420',backgroundColor='0',frameRate='30')]
32 | // Might want to add compile argument: -use-network=false -debug=true
33 |
34 | public dynamic class SampleStyle extends MovieClip{
35 |
36 | public function SampleStyle() {
37 | //
38 | // SETUP - only required once
39 | //
40 | // you must modify the styles before starting console.
41 | Cc.config.style.big(); // BIGGER text. this modifies the config variables such as traceFontSize, menuFontSize
42 | Cc.config.style.whiteBase(); // Black on white. this modifies the config variables such as priority0, priority1, etc
43 | Cc.config.style.backgroundAlpha = 1; // makes it non-transparent background.
44 |
45 | //// Alternatively you can modify the style variables directly:
46 | //config.style.traceFontSize = 16;
47 | //config.style.menuColor = 0xFF0000;
48 | //
49 |
50 | Cc.startOnStage(this, "`"); // "`" - change for password. This will start hidden
51 | Cc.visible = true; // show console, because having password hides console.
52 | Cc.commandLine = true; // enable command line
53 | Cc.config.commandLineAllowed = true;
54 |
55 | Cc.width = 640;
56 | Cc.height = 320;
57 | //
58 | // END OF SETUP
59 | //
60 |
61 |
62 | //
63 | // SAMPLE LOGS
64 | //
65 | Cc.info("Hello world.");
66 | Cc.log("A log message for console.", "optionally there", "can be", "multiple arguments.");
67 | Cc.debug("A debug level log.");
68 | Cc.warn("This is a warning log.");
69 | Cc.error("This is an error log.", "multiple arguments are supported", "for above basic logging methods.");
70 | Cc.fatal("This is a fatal error log.", "with high visibility");
71 | //
72 | Cc.infoch("myChannel", "Hello myChannel.");
73 | Cc.logch("myChannel", "A log message at myChannel.", "optionally there", "can be", "multiple arguments.");
74 | Cc.debugch("myChannel", "A debug level log.");
75 | Cc.warnch("myChannel", "This is a warning log.");
76 | Cc.errorch("myChannel", "This is an error log.", "multiple arguments are supported", "for above basic logging methods.");
77 |
78 |
79 | Cc.info("Custom css examples:");
80 | Cc.config.style.styleSheet.setStyle("purple",{color:'#FF00FF', fontWeight:'bold', display:'inline'});
81 | Cc.addHTML("My special PURPLE text.");
82 |
83 | Cc.config.style.styleSheet.setStyle(".spacy",{letterSpacing:10});
84 | Cc.addHTML("Here is big letter spacing.");
85 |
86 |
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/samples/remote_air/ConsoleRemoteAIR-app.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | com.junkbyte.console.ConsoleRemoteAIR
4 | 2.6
5 | Console Remote
6 | Console Remote
7 |
8 | flash-console Remote
9 |
10 | Lu Aye Oo (c) 2010
11 |
12 | Console Remote
13 | ConsoleRemoteAIR.swf
14 | none
15 | true
16 | true
17 | 150 100
18 | true
19 | true
20 | true
21 |
22 | Flash-Console/ConsoleRemote
23 | Flash-Console
24 |
25 | icon16.png
26 | icon32.png
27 | icon48.png
28 | icon128.png
29 |
30 | false
31 | false
32 |
--------------------------------------------------------------------------------
/samples/remote_air/ConsoleRemoteAIR.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package {
26 | import flash.events.ProgressEvent;
27 | import flash.net.Socket;
28 |
29 | import com.junkbyte.console.Console;
30 | import com.junkbyte.console.ConsoleConfig;
31 | import com.junkbyte.console.core.Remoting;
32 | import com.junkbyte.console.view.ConsolePanel;
33 |
34 | import flash.display.MovieClip;
35 | import flash.display.StageAlign;
36 | import flash.display.StageScaleMode;
37 | import flash.events.Event;
38 | import flash.events.MouseEvent;
39 | import flash.filters.GlowFilter;
40 | import flash.text.TextField;
41 | import flash.events.ServerSocketConnectEvent;
42 | import flash.net.ServerSocket;
43 | import flash.filesystem.File;
44 | import flash.filesystem.FileStream;
45 | import flash.filesystem.FileMode;
46 | import flash.display.NativeWindowDisplayState;
47 | import flash.display.NativeWindowResize;
48 |
49 | public class ConsoleRemoteAIR extends MovieClip {
50 | private var _c : Console;
51 | private var _serverSocket : ServerSocket;
52 |
53 | public function ConsoleRemoteAIR() {
54 | var config : ConsoleConfig = new ConsoleConfig();
55 | config.maxLines = 2000;
56 | config.style.backgroundAlpha = 0.55;
57 | config.commandLineAllowed = true;
58 | _c = new Console(null, config);
59 | addChild(_c);
60 | _c.visible = true;
61 | _c.remoter.remoting = Remoting.RECIEVER;
62 | _c.commandLine = true;
63 | _c.x = 10;
64 | _c.y = 10;
65 | _c.addMenu("top", toggleOnTop, null, "Toggle always in front");
66 | _c.addMenu("save", saveToFile, null, "Save to file");
67 | var menu : TextField = _c.panels.mainPanel.getChildByName("menuField") as TextField;
68 | menu.doubleClickEnabled = true;
69 | menu.addEventListener(MouseEvent.DOUBLE_CLICK, ondouble);
70 | _c.panels.mainPanel.addEventListener(ConsolePanel.DRAGGING_STARTED, moveHandle);
71 | _c.panels.mainPanel.addEventListener(ConsolePanel.SCALING_STARTED, scaleHandle);
72 |
73 | _c.filters = new Array(new GlowFilter(0, 0.7, 5, 5));
74 |
75 | _c.panels.mainPanel.addEventListener(Event.CLOSE, onMainPanelClose);
76 | stage.frameRate = 60;
77 | stage.scaleMode = StageScaleMode.NO_SCALE;
78 | stage.align = StageAlign.TOP_LEFT;
79 | stage.addEventListener(Event.RESIZE, onStageResize);
80 | onStageResize();
81 |
82 | _c.addSlashCommand("listen", function (params:String = ""):void{
83 | var parts:Array = params.split(/\s+/);
84 | bindServer(parts[0], parts[1]);
85 | });
86 | _c.cl.localCommands.push("listen");
87 | _c.report("Use /listen ip port command to listen to socket connection.", -2);
88 | _c.report("Example /listen 127.0.0.1 200 command to listen to socket connection.", -1);
89 | }
90 |
91 | private function toggleOnTop() : void {
92 | stage.nativeWindow.alwaysInFront = !stage.nativeWindow.alwaysInFront;
93 | _c.report("Always in front " + (stage.nativeWindow.alwaysInFront ? "enabled." : "disabled"), -1);
94 | }
95 |
96 | private function onMainPanelClose(e : Event) : void {
97 | stage.nativeWindow.close();
98 | }
99 |
100 | private function saveToFile() : void {
101 | try {
102 | var docsDir : File = File.desktopDirectory;
103 | docsDir.browseForSave("Save Log As");
104 | docsDir.addEventListener(Event.SELECT, saveData);
105 | } catch (err : Error) {
106 | _c.error("Failed:", err.message);
107 | }
108 | }
109 |
110 | private function saveData(e : Event) : void {
111 | var file : File = e.target as File;
112 | if (!file.exists) {
113 | var path : String = file.nativePath;
114 | var dot : int = path.lastIndexOf(".");
115 | var separator : int = path.lastIndexOf(File.separator);
116 | if (dot < 0 || separator > dot) {
117 | file.nativePath = path + ".txt";
118 | }
119 | }
120 | var str : String = _c.getAllLog(File.lineEnding);
121 | var stream : FileStream = new FileStream();
122 | try {
123 | stream.open(file, FileMode.WRITE);
124 | stream.writeUTFBytes(str);
125 | stream.close();
126 | _c.report("Saved log to " + file.nativePath, -1);
127 | } catch(e : Error) {
128 | // maybe read-only , etc
129 | _c.report("There was a problem saving the log to " + file.nativePath + "\n" + e, 10);
130 | }
131 | }
132 |
133 | private function ondouble(e : Event) : void {
134 | if (stage.nativeWindow.displayState != NativeWindowDisplayState.MAXIMIZED) {
135 | stage.nativeWindow.maximize();
136 | } else {
137 | stage.nativeWindow.restore();
138 | }
139 | }
140 |
141 | private function moveHandle(e : Event) : void {
142 | stage.nativeWindow.startMove();
143 | }
144 |
145 | private function scaleHandle(e : Event) : void {
146 | _c.panels.mainPanel.stopScaling();
147 | stage.nativeWindow.startResize(NativeWindowResize.BOTTOM_RIGHT);
148 | }
149 |
150 | private function onStageResize(e : Event = null) : void {
151 | _c.width = stage.stageWidth - 20;
152 | _c.height = stage.stageHeight - 20;
153 | }
154 |
155 | public function bindServer(host : String, port : int) : void {
156 | if (_serverSocket && _serverSocket.bound) {
157 | _serverSocket.close();
158 | }
159 | _serverSocket = new ServerSocket();
160 | _serverSocket.bind(port, host);
161 | _serverSocket.addEventListener(ServerSocketConnectEvent.CONNECT, onConnect);
162 | _serverSocket.listen();
163 | _c.report("Listening to: " + _serverSocket.localAddress + ":" + _serverSocket.localPort, -1);
164 | }
165 |
166 | private function onConnect(event : ServerSocketConnectEvent) : void {
167 | var clientSocket : Socket = event.socket;
168 | clientSocket.addEventListener(ProgressEvent.SOCKET_DATA, onClientSocketData);
169 | _c.report("Connection from " + clientSocket.remoteAddress + ":" + clientSocket.remotePort);
170 | }
171 |
172 | private function onClientSocketData(event : ProgressEvent) : void {
173 | var clientSocket : Socket = event.currentTarget as Socket;
174 | _c.remoter.handleSocket(clientSocket);
175 | }
176 | }
177 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/ConsoleChannel.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console {
26 | import flash.display.DisplayObjectContainer;
27 |
28 | public class ConsoleChannel {
29 |
30 | private var _c:*; // because it could be Console or Cc. This is the cheapest way I think...
31 | private var _name:String;
32 |
33 | public var enabled:Boolean = true;
34 |
35 | /**
36 | * Construct channel instance
37 | *
38 | * @param String Name of channel
39 | * @param String (optional) instance of Console, leave blank to use C.
40 | */
41 | public function ConsoleChannel(n:*, c:Console = null){
42 | _name = Console.MakeChannelName(n);
43 | if (_name == Console.GLOBAL_CHANNEL) _name = Console.DEFAULT_CHANNEL;
44 | // allowed to pass in Console here incase you want to use a different console instance from whats used in Cc
45 | _c = c?c:Cc;
46 | }
47 | public function add(str:*, priority:Number = 2, isRepeating:Boolean = false):void{
48 | if(enabled) _c.ch(_name, str, priority, isRepeating);
49 | }
50 | /**
51 | * Add log line with priority 1 to channel
52 | * Allows multiple arguments for convenience use.
53 | *
54 | * @param String to be logged, any type can be passed and will be converted to string
55 | */
56 | public function log(...args):void{
57 | multiadd(_c.logch, args);
58 | }
59 | /**
60 | * Add log line with priority 3 to channel
61 | * Allows multiple arguments for convenience use.
62 | *
63 | * @param String to be logged, any type can be passed and will be converted to string
64 | */
65 | public function info(...args):void{
66 | multiadd(_c.infoch, args);
67 | }
68 | /**
69 | * Add log line with priority 5 to channel
70 | * Allows multiple arguments for convenience use.
71 | *
72 | * @param String to be logged, any type can be passed and will be converted to string
73 | */
74 | public function debug(...args):void{
75 | multiadd(_c.debugch, args);
76 | }
77 | /**
78 | * Add log line with priority 7 to channel
79 | * Allows multiple arguments for convenience use.
80 | *
81 | * @param String to be logged, any type can be passed and will be converted to string
82 | */
83 | public function warn(...args):void{
84 | multiadd(_c.warnch, args);
85 | }
86 | /**
87 | * Add log line with priority 9 to channel
88 | * Allows multiple arguments for convenience use.
89 | *
90 | * @param Name of channel, if a non-string param is passed, it will use the object's class name as channel name.
91 | * @param String to be logged, any type can be passed and will be converted to string
92 | */
93 | public function error(...args):void{
94 | multiadd(_c.errorch, args);
95 | }
96 | /**
97 | * Add log line with priority 10 to channel
98 | * Allows multiple arguments for convenience use.
99 | *
100 | * @param Name of channel, if a non-string param is passed, it will use the object's class name as channel name.
101 | * @param String to be logged, any type can be passed and will be converted to string
102 | */
103 | public function fatal(...args):void{
104 | multiadd(_c.fatalch, args);
105 | }
106 | private function multiadd(f:Function, args:Array):void{
107 | if(enabled) f.apply(null, new Array(_name).concat(args));
108 | }
109 | /**
110 | * Add log line with priority 10 to channel
111 | * Allows multiple arguments for convenience use.
112 | *
113 | * @param Name of channel, if a non-string param is passed, it will use the object's class name as channel name.
114 | * @param String to be logged, any type can be passed and will be converted to string
115 | */
116 | public function stack(str:*, depth:int = -1, priority:Number = 5):void{
117 | if(enabled) _c.stackch(name, str, depth, priority);
118 | }
119 |
120 | /**
121 | * Expand object values and print in channel - similar to JSON encode
122 | *
123 | * @param obj Object to explode
124 | * @param depth Depth of explosion, -1 = unlimited
125 | */
126 | public function explode(obj:Object, depth:int = 3):void{
127 | _c.explodech(name, obj, depth);
128 | }
129 | /**
130 | * Print the display list map to channel
131 | *
132 | * @param base Display object to start mapping from
133 | * @param maxstep Maximum child depth. 0 = unlimited
134 | */
135 | public function map(base:DisplayObjectContainer, maxstep:uint = 0):void{
136 | _c.mapch(name, base, maxstep);
137 | }
138 |
139 | /**
140 | * Output an object's info such as it's variables, methods (if any), properties,
141 | * superclass, children displays (if Display), parent displays (if Display), etc - to channel.
142 | * Similar to clicking on an object link or in commandLine: /inspect OR /inspectfull.
143 | * However this method does not go to 'inspection' channel but prints on the Console channel.
144 | *
145 | * @param obj Object to inspect
146 | * @param detail Set to true to show inherited values.
147 | *
148 | */
149 | public function inspect(obj:Object, detail:Boolean = true):void{
150 | _c.inspectch(name, obj, detail);
151 | }
152 |
153 | /**
154 | * Get channel name
155 | * Read only
156 | */
157 | public function get name():String{
158 | return _name;
159 | }
160 | /**
161 | * Clear channel
162 | */
163 | public function clear():void{
164 | _c.clear(_name);
165 | }
166 |
167 | public function toString():String{
168 | return "[ConsoleChannel "+name+"]";
169 | }
170 | }
171 | }
172 |
--------------------------------------------------------------------------------
/src/com/junkbyte/console/ConsoleConfig.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console {
26 |
27 | public class ConsoleConfig {
28 |
29 | /**
30 | * Password sequence to toggle console's visibility. If password is set, console will start hidden. Set Cc.visible = ture to unhide at start.
31 | * Must be ASCII chars. Example passwords: ` OR debug.
32 | * Password will not trigger if you have focus on an input TextField.
33 | */
34 | public var keystrokePassword:String;
35 |
36 | /**
37 | * Set Password required to connect from remote.
38 | *
39 | * Must be set before starting remote.
40 | * Set to null (deafult) to use keystrokePassword.
41 | * Set to "" (blank string), to disable remoting password.
42 | *
43 | */
44 | public var remotingPassword:String;
45 |
46 | //////////////////////
47 | // //
48 | // LOGGING CONIFG //
49 | // //
50 | //////////////////////
51 |
52 | /**
53 | * Maximum number of logs Console should remember.
54 | * 0 = unlimited. Setting to very high will take up more memory and potentially slow down.
55 | */
56 | public var maxLines:uint = 1000;
57 |
58 | /**
59 | * Frames before repeating line is forced to print to next line.
60 | *
61 | * Set to -1 to never force. Set to 0 to force every line.
62 | * Default = 75;
63 | *
64 | */
65 | public var maxRepeats:int = 75;
66 |
67 | /**
68 | * Auto stack trace logs for this priority and above
69 | * default priortiy = 10; fatal level
70 | */
71 | public var autoStackPriority:int = Console.FATAL;
72 |
73 | /**
74 | * Default stack trace depth
75 | */
76 | public var defaultStackDepth:int = 2;
77 |
78 | /**
79 | * Object linking allows you click on individual objects you have logged to inspect the detials in a specific view.
80 | * The down side is that it will take a little more memory to keep a WEAK reference to all objects pass for logging.
81 | * Potentially a security risk as users will be able to explore your code interface.
82 | */
83 | public var useObjectLinking:Boolean = true;
84 |
85 | /**
86 | * Seconds in which object links should be hard referenced for.
87 | * If you logged a temp object (object that is not referenced anywhere else), it will become a link in console.
88 | * However it will get garbage collected almost straight away which prevents you from clicking on the object link.
89 | * (You will normally get this message: "Reference no longer exists")
90 | * This feature allow you to set how many seconds console should hard reference object logs.
91 | * Example, if you set 120, you will get 2 mins guaranteed time that any object link will work since it first appeared.
92 | * Default is 0, meaning everything is weak linked straight away.
93 | * Recommend not to use too high numbers. possibly 120 (2 minutes) is max you should set.
94 | *
95 | * Example:
96 | *
97 | * Cc.log("This is a temp object:", new Object());
98 | * // if you click this link in run time, it'll most likely say 'no longer exist'.
99 | * // However if you set objectHardReferenceTimer to 60, you will get AT LEAST 60 seconds before it become unavailable.
100 | *
101 | */
102 | public var objectHardReferenceTimer:uint = 0;
103 |
104 | /**
105 | * Use flash's build in (or external) trace().
106 | *
107 | * When turned on, Console will also call trace() for all console logs.
108 | * Trace function can be replaced with something of your own (such as Flex's logging) by
109 | * setting your own function into traceCall variable.
110 | * Default function: trace("["+channel+"] "+text);
111 | *
112 | * @see traceCall
113 | */
114 | public var tracing:Boolean;
115 |
116 | /**
117 | * Assign custom trace function.
118 | *
119 | * Console will only call this when Cc.config.tracing is set to true.
120 | * Custom function must accept 3 parameters:
121 | * - String channel name.
122 | * - String the log line.
123 | * - int priority level -2 to 10.
124 | *
125 | *
126 | * Default function calls flash build-in trace in this format: "[channel] log line" (ignores priority)
127 | * Example:
128 | * Cc.config.traceCall = function(ch:String, line:String, level:int):void {
129 | * trace("["+ch+"] "+line);
130 | * }
131 | *
132 | * @see tracing
133 | */
134 | public var traceCall:Function = function (ch:String, line:String, ...args):void{
135 | trace("["+ch+"] "+line);
136 | };
137 |
138 |
139 | /**
140 | * Specifies whether to show timestamps in Console.
141 | */
142 | public var showTimestamp:Boolean = false;
143 |
144 |
145 | /**
146 | * Time stamp formatter.
147 | *
148 | * Function must accept a single uint param and return a formatted string.
149 | *
150 | *
151 | * Default formatter returns as 'MM:SS' (10:20)
152 | *
153 | */
154 | public var timeStampFormatter:Function = function(timer:uint):String
155 | {
156 | var s:uint = timer*0.001;
157 | return makeTimeDigit(s/60)+":"+makeTimeDigit(s%60);
158 | };
159 |
160 | private function makeTimeDigit(v:uint):String{
161 | if(v < 10) return "0"+v;
162 | return String(v);
163 | }
164 |
165 | /**
166 | * Specifies whether to show line numbers in console.
167 | */
168 | public var showLineNumber:Boolean = false;
169 |
170 | // Work in progress
171 | //public var rolloverStackToolTip:Boolean = false;
172 |
173 | ///////////////////////
174 | // //
175 | // REMOTING CONFIG //
176 | // //
177 | ///////////////////////
178 |
179 | /**
180 | * Shared connection name used for remoting
181 | * You can change this if you don't want to use default channel
182 | * Other remotes with different remoting channel won't be able to connect your flash.
183 | * Start with _ to work in any domain + platform (air/swf - local / network)
184 | * Note that local to network sandbox still apply.
185 | */
186 | public var remotingConnectionName:String = "_Console";
187 |
188 | /**
189 | * allowDomain and allowInsecureDomain of remoting LocalConnection.
190 | * Default: "*"
191 | * see LocalConnection -> allowDomain for info.
192 | */
193 | public var allowedRemoteDomain:String = "*";
194 |
195 | ///////////////////
196 | // //
197 | // MISC CONFIG //
198 | // //
199 | ///////////////////
200 |
201 | /**
202 | * Full Command line features usage allowance.
203 | *
204 | * CommandLine is a big security risk for your code and flash.
205 | * It is a very good practice to disable it after development phase.
206 | * On the other hand having it on full access will let you debug the code easier.
207 | *
208 | */
209 | public var commandLineAllowed:Boolean;
210 |
211 | /**
212 | * CommandLine autoscoping
213 | *
214 | * When turned on, it will autoscope to objects returned without the need to call the command "/".
215 | *
216 | */
217 | public var commandLineAutoScope:Boolean;
218 |
219 | /**
220 | * CommandLine input pass through function
221 | *
222 | * Function to call when user enter commandLine input via main console panel.
223 | * This can be used to essentially replace built-in commandLine functionality.
224 | * If function returns a String, that string is executed as command.
225 | *
226 | * - Example below prints the command input insted of executing:
227 | * Cc.config.commandLineInputPassThrough = function(commandStr:String):String{
228 | * Cc.info("Received command input: '"+commandStr+"'.");
229 | * return null;
230 | * };
231 | *
232 | *
233 | */
234 | public var commandLineInputPassThrough:Function;
235 |
236 | /**
237 | * Commandline auto hinting and auto-completion
238 | *
239 | * When using config.commandLineInputPassThrough feature,
240 | * it maybe be convenient to turn off commandLineAutoCompleteEnabled.
241 | *
242 | */
243 | public var commandLineAutoCompleteEnabled:Boolean = true;
244 |
245 | /**
246 | * Key binding availability
247 | *
248 | * While turned off, you can still bind keys.
249 | * Just that it will not trigger so long as the keyBindsEnabled is set to false.
250 | *
251 | */
252 | public var keyBindsEnabled:Boolean = true;
253 |
254 | /**
255 | * Display Roller availability
256 | *
257 | * You are able to turn it off incase you need better security.
258 | *
259 | */
260 | public var displayRollerEnabled:Boolean = true;
261 |
262 | /**
263 | * Ruler tool availability
264 | */
265 | public var rulerToolEnabled:Boolean = true;
266 |
267 | /**
268 | * Determine if Console should hide mouse cursor when using Ruler tool.
269 | *
270 | * You may want to turn it off if your app/game don't use system mouse.
271 | * Default: true
272 | *
273 | */
274 | public var rulerHidesMouse:Boolean = true;
275 |
276 | /**
277 | * Local shared object used for storing user data such as command line history
278 | * Set to null to disable storing to local shared object.
279 | */
280 | public var sharedObjectName:String = "com.junkbyte/Console/UserData";
281 |
282 | /** Local shared object path */
283 | public var sharedObjectPath:String = "/";
284 |
285 | /**
286 | * Remembers viewing filters such as channels and priority level over different sessions.
287 | *
288 | * - Must be set before starting console (before Cc.start / Cc.startOnStage)
289 | * - Requires sharedObject feature turned on
290 | * - Because console's SharedObject is shared across, your filtering settings will carry over to other flash projects
291 | * - You may want to set sharedObjectName to store project specificly
292 | *
293 | */
294 | public var rememberFilterSettings:Boolean;
295 |
296 | /**
297 | * Keeping Console on top of display list.
298 | *
299 | * When turned on (by default), console will always try to put it self on top of the parent's display list.
300 | * For example, if console is started in root, when a child display is added in root, console will move it self to the
301 | * top of root's display list to try to overlay the new child display. - making sure that console don't get covered.
302 | *
303 | *
304 | * However, if Console's parent display (root in example) is covered by another display (example: adding a child directly to stage),
305 | * console will not be able to pull it self above it as it is in root, not stage.
306 | * If console is added on stage in the first place, there won't be an issue as described above. Use Cc.startOnStage(...).
307 | *
308 | *
309 | * Keeping it turned on may have other side effects if another display is also trying to put it self on top,
310 | * they could be jumping layers as they fight for the top layer.
311 | *
312 | */
313 | public var alwaysOnTop:Boolean = true;
314 |
315 | ////////////////////
316 | // //
317 | // STYLE CONFIG //
318 | // //
319 | ////////////////////
320 |
321 | /**
322 | * Get style configuration used.
323 | */
324 | public function get style():ConsoleStyle{
325 | return _style;
326 | }
327 |
328 | /////////////////////
329 | // //
330 | // END OF CONFIG //
331 | // //
332 | /////////////////////
333 |
334 | private var _style:ConsoleStyle;
335 |
336 | public function ConsoleConfig(){
337 | _style = new ConsoleStyle();
338 | }
339 | }
340 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/ConsoleStyle.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console {
26 | import flash.text.StyleSheet;
27 |
28 | public class ConsoleStyle {
29 |
30 | /** Font for menus and almost all others */
31 | public var menuFont:String = "Arial";
32 |
33 | /** Default font size */
34 | public var menuFontSize:int = 12;
35 |
36 | /** Font for trace field */
37 | public var traceFont:String = "Verdana";
38 |
39 | /** Font size for trace field */
40 | public var traceFontSize:int = 11;
41 |
42 | /** Panels background color */
43 | public var backgroundColor:uint;
44 |
45 | /** Panels background alpha */
46 | public var backgroundAlpha:Number = 0.9;
47 |
48 | /** Color of scroll bar, scaler, etc. Some gets alpha applied */
49 | public var controlColor:uint = 0x990000;
50 |
51 | /** Size of controls, scroll bar, scaler, etc */
52 | public var controlSize:uint = 5;
53 |
54 | /** Command line background and text color. Background gets alpha so it is less visible. */
55 | public var commandLineColor:uint = 0x10AA00;
56 |
57 | /** Font color for high priority text, such as user input. */
58 | public var highColor:uint = 0xFFFFFF;
59 |
60 | /** Font color for less important / smaller text */
61 | public var lowColor:uint = 0xC0C0C0;
62 |
63 | /** Font color for log header text (line number, channel and time stamp) */
64 | public var logHeaderColor:uint = 0xC0C0C0;
65 |
66 | /** Font color for menu */
67 | public var menuColor:uint = 0xFF8800;
68 |
69 | /** Font color for highlighted menu */
70 | public var menuHighlightColor:uint = 0xDD5500;
71 |
72 | /** Font color for channel names */
73 | public var channelsColor:uint = 0xFFFFFF;
74 |
75 | /** Font color for current channel name */
76 | public var channelColor:uint = 0x0099CC;
77 |
78 | //
79 |
80 | /** Color of log priority level 0.*/
81 | public var priority0:uint = 0x3A773A;
82 | /** Color of log priority level 1. C.log(...)*/
83 | public var priority1:uint = 0x449944;
84 | /** Color of log priority level 2. */
85 | public var priority2:uint = 0x77BB77;
86 | /** Color of info log priority level 3. C.info(...) */
87 | public var priority3:uint = 0xA0D0A0;
88 | /** Color of log priority level 4. */
89 | public var priority4:uint = 0xD6EED6;
90 | /** Color of debug log priority level 5. */
91 | public var priority5:uint = 0xE9E9E9;
92 | /** Color of log priority level 6. C.debug(...) */
93 | public var priority6:uint = 0xFFDDDD;
94 | /** Color of warn log priority level 7. */
95 | public var priority7:uint = 0xFFAAAA;
96 | /** Color of log priority level 8. C.warn(...) */
97 | public var priority8:uint = 0xFF7777;
98 | /** Color of error log priority level 9. C.error(...) */
99 | public var priority9:uint = 0xFF2222;
100 | /** Color of fatal log priority level 10. C.fatal(...) */
101 | public var priority10:uint = 0xFF2222; // priority 10, also gets a bold
102 |
103 | /** Color of console status log.*/
104 | public var priorityC1:uint = 0x0099CC;
105 | /** Color of console event log.*/
106 | public var priorityC2:uint = 0xFF8800;
107 |
108 |
109 | /** Show top menu */
110 | public var topMenu:Boolean = true;
111 |
112 | /** Show command line scope */
113 | public var showCommandLineScope:Boolean = true;
114 |
115 | /** Maximum number of channels to display on top menu */
116 | public var maxChannelsInMenu:int = 7;
117 |
118 | /** Panel snapping radius during drag move. default:3, set to 0 to disable*/
119 | public var panelSnapping:int = 3;
120 |
121 | /** Panels background corner rounding */
122 | public var roundBorder:int = 10;
123 |
124 |
125 | /** Use white base pre configuration */
126 | public function whiteBase():void{
127 | backgroundColor = 0xFFFFFF;
128 | controlColor = 0xFF3333;
129 | commandLineColor = 0x66CC00;
130 | //
131 | highColor = 0x000000;
132 | lowColor = 0x333333;
133 | logHeaderColor = 0x444444;
134 | menuColor = 0xCC1100;
135 | menuHighlightColor = 0x881100;
136 | channelsColor = 0x000000;
137 | channelColor = 0x0066AA;
138 | //
139 | priority0 = 0x44A044;
140 | priority1 = 0x339033;
141 | priority2 = 0x227722;
142 | priority3 = 0x115511;
143 | priority4 = 0x003300;
144 | priority5 = 0x000000;
145 | priority6 = 0x660000;
146 | priority7 = 0x990000;
147 | priority8 = 0xBB0000;
148 | priority9 = 0xDD0000;
149 | priority10 = 0xDD0000;
150 | priorityC1 = 0x0099CC;
151 | priorityC2 = 0xFF6600;
152 | }
153 | /** Use bigger font size */
154 | public function big():void{
155 | traceFontSize = 13;
156 | menuFontSize = 14;
157 | }
158 |
159 | /////////////////////
160 | // //
161 | // END OF CONFIG //
162 | // //
163 | /////////////////////
164 |
165 | private var _css:StyleSheet;
166 | /**
167 | * Construct ConsoleStyle. Starts with default black based style.
168 | * You must set up the desired style and configuration before starting Console.
169 | */
170 | public function ConsoleStyle() {
171 | _css = new StyleSheet();
172 | }
173 |
174 | /**
175 | * Called by console at start to generate the style sheet based on the style settings set
176 | * If you ever changed the style settings after console have already started,
177 | * calling this method have a good chance of updating console style on the fly as well - not guarantee tho.
178 | */
179 | public function updateStyleSheet():void {
180 | _css.setStyle("high",{color:hesh(highColor), fontFamily:menuFont, fontSize:menuFontSize, display:'inline'});
181 | _css.setStyle("low",{color:hesh(lowColor), fontFamily:menuFont, fontSize:menuFontSize-2, display:'inline'});
182 | _css.setStyle("menu",{color:hesh(menuColor), display:'inline'});
183 | _css.setStyle("menuHi",{color:hesh(menuHighlightColor), display:'inline'});
184 | _css.setStyle("chs",{color:hesh(channelsColor), fontSize:menuFontSize, leading:'2', display:'inline'});
185 | _css.setStyle("ch",{color:hesh(channelColor), display:'inline'});
186 | _css.setStyle("tt",{color:hesh(menuColor),fontFamily:menuFont,fontSize:menuFontSize, textAlign:'center'});
187 | _css.setStyle("r",{textAlign:'right', display:'inline'});
188 | _css.setStyle("p",{fontFamily:traceFont, fontSize:traceFontSize});
189 | _css.setStyle("p0",{color:hesh(priority0), display:'inline'});
190 | _css.setStyle("p1",{color:hesh(priority1), display:'inline'});
191 | _css.setStyle("p2",{color:hesh(priority2), display:'inline'});
192 | _css.setStyle("p3",{color:hesh(priority3), display:'inline'});
193 | _css.setStyle("p4",{color:hesh(priority4), display:'inline'});
194 | _css.setStyle("p5",{color:hesh(priority5), display:'inline'});
195 | _css.setStyle("p6",{color:hesh(priority6), display:'inline'});
196 | _css.setStyle("p7",{color:hesh(priority7), display:'inline'});
197 | _css.setStyle("p8",{color:hesh(priority8), display:'inline'});
198 | _css.setStyle("p9",{color:hesh(priority9), display:'inline'});
199 | _css.setStyle("p10",{color:hesh(priority10), fontWeight:'bold', display:'inline'});
200 | _css.setStyle("p-1",{color:hesh(priorityC1), display:'inline'});
201 | _css.setStyle("p-2",{color:hesh(priorityC2), display:'inline'});
202 | _css.setStyle("logs",{color:hesh(logHeaderColor), display:'inline'});
203 | }
204 | /**
205 | * Style sheet used by Console.
206 | *
207 | * You may add your own style definitions if you plan to use Cc.addHTML feature excessively.
208 | * Only CSS properties supported by flash will work.
209 | *
210 | *
211 | * At console startup, it sets several style sets using settings from ConsoleStyle, such as trace font size, menu color, etc.
212 | *
213 | * - List of build in styles:
214 | *
215 | * - high - color:ConsoleStyle.highColor
216 | * - low - color:ConsoleStyle.lowColor
217 | * - menu - color:ConsoleStyle.menuColor
218 | * - menuHi - color:ConsoleStyle.menuHighlightColor
219 | * - chs - color:ConsoleStyle.channelsColor, fontSize:ConsoleStyle.menuFontSize, leading:2, display:inline
220 | * - r - textAlign:right (does not always work in logging)
221 | * - p - fontFamily:traceFont, fontSize:traceFontSize
222 | * - p0 - (priority0) color:priority0
223 | * - p1 - (priority1) color:priority1
224 | * - p2 - (priority2) color:priority2
225 | * - p3 - (priority3) color:priority3
226 | * - p4 - (priority4) color:priority4
227 | * - p5 - (priority5) color:priority5
228 | * - p6 - (priority6) color:priority6
229 | * - p7 - (priority7) color:priority7
230 | * - p8 - (priority8) color:priority8
231 | * - p9 - (priority9) color:priority9
232 | * - p10 - (priority10) color:priority10, fontWeight:bold
233 | * - p-1 - (priority-1) color:priority-1
234 | * - p-2 - (priority-2) color:priority-2
235 | * - tt - (tooltip) color:channelsColor, fontFamily:menuFont, fontSize:menuFontSize, textAlign:center
236 | *
237 | * - Adding new style example:
238 | *
239 | * Cc.config.style.styleSheet.setStyle("purple",{color:'#FF00FF', fontWeight:'bold', display:'inline'});
240 | * Cc.addHTML("My special <purple>PURPLE</purple> text");
241 | *
242 | * - Example 2:
243 | *
244 | * Cc.config.style.styleSheet.setStyle(".spacy",{letterSpacing:10});
245 | * Cc.addHTML("Here is <span class='spacy'>big letter spacing</span>.");
246 | *
247 | *
248 | */
249 | public function get styleSheet():StyleSheet {
250 | return _css;
251 | }
252 | private function hesh(n:Number):String{
253 | return "#"+n.toString(16);
254 | }
255 | }
256 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/KeyBind.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console
26 | {
27 | public class KeyBind
28 | {
29 |
30 | private var _code:Boolean;
31 | private var _key:String;
32 |
33 | /**
34 | * @param code Pass a single string (e.g. "a") OR pass keyCode (e.g. Keyboard.F1)
35 | * @param shift Set true if shift key needs to be pressed to trigger
36 | * @param ctrl Set true if ctrl key needs to be pressed to trigger
37 | * @param alt Set true if alt key needs to be pressed to trigger
38 | */
39 | public function KeyBind(v:*, shift:Boolean = false, ctrl:Boolean = false, alt:Boolean = false, onUp:Boolean = false)
40 | {
41 | _key = String(v).toUpperCase();
42 | if(v is uint){
43 | _code = true;
44 | }else if(!v || _key.length != 1) {
45 | throw new Error("KeyBind: character (first char) must be a single character. You gave ["+v+"]");
46 | }
47 |
48 | if(_code) _key = "keycode:"+_key;
49 | if(shift) _key+="+shift";
50 | if(ctrl) _key+="+ctrl";
51 | if(alt) _key+="+alt";
52 | if(onUp) _key+="+up";
53 |
54 | }
55 |
56 | public function get useKeyCode():Boolean
57 | {
58 | return _code;
59 | }
60 | public function get key():String
61 | {
62 | return _key;
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/addons/autoFocus/CommandLineAutoFocusAddon.as:
--------------------------------------------------------------------------------
1 | package com.junkbyte.console.addons.autoFocus
2 | {
3 | import com.junkbyte.console.Cc;
4 | import com.junkbyte.console.Console;
5 | import com.junkbyte.console.view.ConsolePanel;
6 | import com.junkbyte.console.view.MainPanel;
7 |
8 | import flash.events.Event;
9 | import flash.text.TextField;
10 |
11 | /**
12 | * This addon sets focus to commandLine input field whenever Console becomes visible, e.g after entering password key.
13 | */
14 | public class CommandLineAutoFocusAddon
15 | {
16 | public static function registerToConsole(console:Console = null):void
17 | {
18 | if (console == null)
19 | {
20 | console = Cc.instance;
21 | }
22 | if (console == null)
23 | {
24 | return;
25 | }
26 |
27 | console.panels.mainPanel.addEventListener(ConsolePanel.VISIBLITY_CHANGED, onPanelVisibilityChanged);
28 | }
29 |
30 | private static function onPanelVisibilityChanged(event:Event):void
31 | {
32 | var mainPanel:MainPanel = event.currentTarget as MainPanel;
33 |
34 | if (mainPanel.visible == false)
35 | {
36 | return;
37 | }
38 |
39 | var commandField:TextField = mainPanel.getChildByName("commandField") as TextField;
40 |
41 | if (commandField && commandField.stage)
42 | {
43 | commandField.stage.focus = commandField;
44 | var textLen:uint = commandField.text.length;
45 | commandField.setSelection(textLen, textLen);
46 | }
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/com/junkbyte/console/addons/commandprompt/CommandChoice.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.addons.commandprompt {
26 |
27 | public class CommandChoice {
28 |
29 | public var key:String;
30 | public var callback:Function;
31 | public var text:String;
32 |
33 | public function CommandChoice(choiceKey : String, selectionCallback:Function, txt : String = "") {
34 | key = choiceKey;
35 | callback = selectionCallback;
36 | text = txt;
37 | }
38 |
39 | public function toHTMLString():String{
40 | var txt:String = (text ? text : "" );
41 | if(key) return "> "+key+": " + txt;
42 | return txt ? txt : "[CommandChoice empty]";
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/com/junkbyte/console/addons/commandprompt/CommandPrompt.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.addons.commandprompt {
26 | import com.junkbyte.console.Cc;
27 | import com.junkbyte.console.Console;
28 |
29 | /**
30 | * Command prompt addon.
31 | *
32 | * - Simulates 'command prompt' style user input.
33 | * - Ask to choose from a selection of input, user enter into command line to choose a selection.
34 | * - Could be useful for 'utility' sort of app where there is no GUI to represent user options.
35 | *
36 | */
37 | public class CommandPrompt {
38 |
39 | public var ch : String = Console.CONSOLE_CHANNEL;
40 | public var headerQuestion:String;
41 | public var footerText:String;
42 | public var defaultCallback:Function;
43 |
44 | protected var _console:Console;
45 | protected var _choices:Array = new Array();
46 |
47 | private var _wasAutoCompleteEnabled:Boolean;
48 | private var _wasScopeShown:Boolean;
49 |
50 | public function CommandPrompt(headerQuestion:String = null, defaultCB:Function = null, choices:Array = null){
51 |
52 | this.headerQuestion = headerQuestion;
53 | defaultCallback = defaultCB;
54 | if(choices){
55 | _choices = choices;
56 | }
57 | }
58 |
59 | public function addCmdChoice(cmdChoice:CommandChoice):void {
60 | _choices.push(cmdChoice);
61 | }
62 |
63 | public function start():void{
64 | if (console) {
65 | console.config.commandLineInputPassThrough = commandLinePassThrough;
66 | _wasAutoCompleteEnabled = console.config.commandLineAutoCompleteEnabled;
67 | _wasScopeShown = console.config.style.showCommandLineScope;
68 | console.config.commandLineAutoCompleteEnabled = false;
69 | console.config.style.showCommandLineScope = false;
70 | ask();
71 | }
72 | }
73 |
74 | protected function ask():void{
75 | if(headerQuestion){
76 | console.addHTMLch(ch, -2, "" + headerQuestion + "");
77 | }
78 | printChoices();
79 | if(footerText !== null){
80 | console.addHTMLch(ch, -2, footerText);
81 | }
82 | }
83 |
84 | protected function printChoices():void{
85 | for each (var choice:CommandChoice in _choices) {
86 | console.addHTMLch(ch, 4, choice.toHTMLString());
87 | }
88 | }
89 |
90 | protected function commandLinePassThrough(command:String):void{
91 | for each (var choice:CommandChoice in _choices) {
92 | if (choice.key.toLowerCase() == command.toLowerCase()) {
93 | end();
94 | choice.callback(choice.key);
95 | return;
96 | }
97 | }
98 | if(defaultCallback != null){
99 | end();
100 | defaultCallback(command);
101 | }
102 | }
103 |
104 | protected function end():void{
105 | console.config.commandLineInputPassThrough = null;
106 | console.config.commandLineAutoCompleteEnabled = _wasAutoCompleteEnabled;
107 | console.config.style.showCommandLineScope = _wasScopeShown;
108 | }
109 |
110 | public function setConsole(targetC:Console):void{
111 | if(targetC) _console = targetC;
112 | }
113 |
114 | protected function get console():Console{
115 | if(_console) return _console;
116 | return Cc.instance;
117 | }
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/com/junkbyte/console/addons/displaymap/DisplayMapAddon.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.addons.displaymap
26 | {
27 | import com.junkbyte.console.Cc;
28 | import com.junkbyte.console.Console;
29 | import com.junkbyte.console.view.ConsolePanel;
30 |
31 | import flash.display.DisplayObject;
32 |
33 | /**
34 | * Display tree mapping panel addon
35 | *
36 | *
37 | * - Displays a panel mapping the display tree/map.
38 | * - Start from code: DisplayMapAddon.start();
39 | * - Add to menu: DisplayMapAddon.addToMenu();
40 | * - Register to commandLine: DisplayMapAddon.registerCommand(); use /mapdisplay, starts mapping from current command scope.
41 | *
42 | */
43 | public class DisplayMapAddon
44 | {
45 | /**
46 | * Start DisplayMapAddon
47 | *
48 | * @param startingContainer Starting DisplayObject to map.
49 | * @param console Instance to Console. You do not need to pass this param if you use Cc.
50 | */
51 | public static function start(targetDisplay:DisplayObject, console:Console = null):DisplayMapPanel
52 | {
53 | if (console == null)
54 | {
55 | console = Cc.instance;
56 | }
57 | if (console == null)
58 | {
59 | return null;
60 | }
61 | var mapPanel:DisplayMapPanel = new DisplayMapPanel(console);
62 | mapPanel.start(targetDisplay);
63 | console.panels.addPanel(mapPanel);
64 | return mapPanel;
65 | }
66 |
67 | /**
68 | * Register DisplayMapAddon to console slash command.
69 | *
70 | * @param commandName Command name to trigger. Default = 'mapdisplay'
71 | * @param console Instance to Console. You do not need to pass this param if you use Cc.
72 | */
73 | public static function registerCommand(commandName:String = "mapdisplay", console:Console = null):void
74 | {
75 | if (console == null)
76 | {
77 | console = Cc.instance;
78 | }
79 | if (console == null || commandName == null)
80 | {
81 | return;
82 | }
83 |
84 | var callbackFunction:Function = function(... arguments:Array):void
85 | {
86 | var scope:* = console.cl.run("this");
87 | if (scope is DisplayObject)
88 | {
89 | start(scope as DisplayObject, console);
90 | }
91 | else
92 | {
93 | console.error("Current scope", scope, "is not a DisplayObject.");
94 | }
95 | }
96 | console.addSlashCommand(commandName, callbackFunction);
97 | }
98 |
99 |
100 | /**
101 | * Add DisplayMapAddon to console top menu.
102 | *
103 | * @param menuName Name of menu. Default = 'DM'
104 | * @param startingContainer Starting DisplayObject to map. When null, it uses console's parent display.
105 | * @param console Instance to Console. You do not need to pass this param if you use Cc.
106 | */
107 | public static function addToMenu(menuName:String = "DM", startingContainer:DisplayObject = null, console:Console = null):void
108 | {
109 | if (console == null)
110 | {
111 | console = Cc.instance;
112 | }
113 | if (console == null || menuName == null)
114 | {
115 | return;
116 | }
117 |
118 | var callbackFunction:Function = function():void
119 | {
120 | var panel:DisplayMapPanel = console.panels.getPanel(DisplayMapPanel.NAME) as DisplayMapPanel;
121 | if(panel)
122 | {
123 | panel.close();
124 | }
125 | else
126 | {
127 | if(startingContainer == null)
128 | {
129 | startingContainer = console.parent;
130 | }
131 | panel = start(startingContainer);
132 | panel.x = console.mouseX - panel.width * 0.5;
133 | panel.y = console.mouseY + 10;
134 | }
135 | }
136 | console.addMenu(menuName, callbackFunction);
137 | }
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/src/com/junkbyte/console/addons/displaymap/DisplayMapPanel.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.addons.displaymap
26 | {
27 | import com.junkbyte.console.Console;
28 | import com.junkbyte.console.core.LogReferences;
29 | import com.junkbyte.console.view.ConsolePanel;
30 |
31 | import flash.display.DisplayObject;
32 | import flash.display.DisplayObjectContainer;
33 | import flash.events.Event;
34 | import flash.events.TextEvent;
35 | import flash.text.TextField;
36 | import flash.text.TextFieldAutoSize;
37 | import flash.utils.Dictionary;
38 |
39 | /**
40 | * @private
41 | */
42 | public class DisplayMapPanel extends ConsolePanel
43 | {
44 |
45 | public static const NAME:String = "displayMapPanel";
46 |
47 | public static var numOfFramesToUpdate:uint = 10;
48 |
49 | private var rootDisplay:DisplayObject;
50 |
51 | private var mapIndex:uint;
52 |
53 | private var indexToDisplayMap:Object;
54 |
55 | private var openings:Dictionary;
56 |
57 | private var framesSinceUpdate:uint;
58 |
59 | public function DisplayMapPanel(m:Console)
60 | {
61 | super(m);
62 | name = NAME;
63 | init(60, 100, false);
64 | txtField = makeTF("mapPrints");
65 | txtField.multiline = true;
66 | txtField.autoSize = TextFieldAutoSize.LEFT;
67 | registerTFRoller(txtField, onMenuRollOver, linkHandler);
68 | registerDragger(txtField);
69 | addChild(txtField);
70 | }
71 |
72 | public function start(container:DisplayObject):void
73 | {
74 | rootDisplay = container;
75 | openings = new Dictionary(true);
76 |
77 | if (rootDisplay == null)
78 | {
79 | return;
80 | }
81 |
82 | rootDisplay.addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true);
83 |
84 | addToOpening(rootDisplay);
85 | }
86 |
87 | public function stop():void
88 | {
89 | if (rootDisplay == null)
90 | {
91 | return;
92 | }
93 |
94 | rootDisplay.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
95 | rootDisplay = null;
96 | }
97 |
98 | private function onEnterFrame(event:Event):void
99 | {
100 | framesSinceUpdate++;
101 | if (framesSinceUpdate >= numOfFramesToUpdate)
102 | {
103 | framesSinceUpdate = 0;
104 | update();
105 | }
106 | }
107 |
108 | private function update():void
109 | {
110 | mapIndex = 0;
111 | indexToDisplayMap = new Object();
112 |
113 | var string:String = "";
114 |
115 | if (rootDisplay == null)
116 | {
117 | string += "null";
118 | }
119 | else
120 | {
121 | string += "
";
122 |
123 | var rootParent:DisplayObjectContainer = rootDisplay.parent;
124 | if (rootParent)
125 | {
126 | string += "" + makeLink(rootParent, " ^ ", "focus") + "" + makeName(rootParent) + "
";
127 | string += printChild(rootDisplay, 1);
128 | }
129 | else
130 | {
131 | string += printChild(rootDisplay, 0);
132 | }
133 | }
134 |
135 | txtField.htmlText = string + "
";
136 |
137 | width = txtField.width + 4;
138 | height = txtField.height;
139 | }
140 |
141 | private function printChild(display:DisplayObject, currentStep:uint):String
142 | {
143 | if (display == null)
144 | {
145 | return "";
146 | }
147 | if (display is DisplayObjectContainer)
148 | {
149 | var string:String;
150 | var container:DisplayObjectContainer = display as DisplayObjectContainer;
151 | if (openings[display] == true)
152 | {
153 | string = "" + generateSteps(display, currentStep) + makeLink(display, "-" + container.numChildren, "minimize") + " " + makeName(display) + "
";
154 | string += printChildren(container, currentStep + 1);
155 | }
156 | else
157 | {
158 | string = "" + generateSteps(display, currentStep) + makeLink(display, "+" + container.numChildren, "expand") + " " + makeName(display) + "
";
159 | }
160 | return string;
161 | }
162 | return "" + generateSteps(display, currentStep) + makeName(display) + "
";
163 | }
164 |
165 | private function printChildren(container:DisplayObjectContainer, currentStep:uint):String
166 | {
167 | var string:String = "";
168 | var len:uint = container.numChildren;
169 | for (var i:uint = 0; i < len; i++)
170 | {
171 | string += printChild(container.getChildAt(i), currentStep);
172 | }
173 | return string;
174 | }
175 |
176 | private function generateSteps(display:Object, steps:uint):String
177 | {
178 | var str:String = "";
179 | for (var i:uint = 0; i < steps; i++)
180 | {
181 | if (i == steps - 1)
182 | {
183 | if (display is DisplayObjectContainer)
184 | {
185 | str += makeLink(display, " > ", "focus");
186 | }
187 | else
188 | {
189 | str += " > ";
190 | }
191 | }
192 | else
193 | {
194 | str += " · ";
195 | }
196 | }
197 | return str;
198 | }
199 |
200 | private function onMenuRollOver(e:TextEvent):void
201 | {
202 | var txt:String = e.text ? e.text.replace("event:", "") : "";
203 |
204 | if (txt == "close")
205 | {
206 | txt = "Close";
207 | }
208 | else if (txt.indexOf("expand") == 0)
209 | {
210 | txt = "expand";
211 | }
212 | else if (txt.indexOf("minimize") == 0)
213 | {
214 | txt = "minimize";
215 | }
216 | else if (txt.indexOf("focus") == 0)
217 | {
218 | txt = "focus";
219 | }
220 | else
221 | {
222 | txt = null;
223 | }
224 | console.panels.tooltip(txt, this);
225 | }
226 |
227 | private function makeName(display:Object):String
228 | {
229 | return makeLink(display, display.name, "scope") + " {}";
230 | }
231 |
232 | private function makeLink(display:Object, text:String, event:String):String
233 | {
234 | mapIndex++;
235 | indexToDisplayMap[mapIndex] = display;
236 | return "" + text + "";
237 | }
238 |
239 | private function getDisplay(string:String):DisplayObject
240 | {
241 | var split:Array = string.split("_");
242 | return indexToDisplayMap[split[split.length - 1]];
243 | }
244 |
245 | protected function linkHandler(e:TextEvent):void
246 | {
247 | TextField(e.currentTarget).setSelection(0, 0);
248 | console.panels.tooltip(null);
249 |
250 | if (e.text == "close")
251 | {
252 | close();
253 | }
254 | else if (e.text.indexOf("expand") == 0)
255 | {
256 | addToOpening(getDisplay(e.text));
257 | }
258 | else if (e.text.indexOf("minimize") == 0)
259 | {
260 | removeFromOpening(getDisplay(e.text));
261 | }
262 | else if (e.text.indexOf("focus") == 0)
263 | {
264 | focus(getDisplay(e.text) as DisplayObjectContainer);
265 | }
266 | else if (e.text.indexOf("scope") == 0)
267 | {
268 | scope(getDisplay(e.text));
269 | }
270 | else if (e.text.indexOf("inspect") == 0)
271 | {
272 | inspect(getDisplay(e.text));
273 | }
274 |
275 | e.stopPropagation();
276 | }
277 |
278 | private function focus(container:DisplayObjectContainer):void
279 | {
280 | rootDisplay = container;
281 | addToOpening(container);
282 | update();
283 | }
284 |
285 | private function addToOpening(display:DisplayObject):void
286 | {
287 | if (openings[display] == undefined)
288 | {
289 | openings[display] = true;
290 | update();
291 | }
292 | }
293 |
294 | private function removeFromOpening(display:DisplayObject):void
295 | {
296 | if (openings[display] != undefined)
297 | {
298 | delete openings[display];
299 | update();
300 | }
301 | }
302 |
303 | protected function scope(display:DisplayObject):void
304 | {
305 | console.cl.setReturned(display, true);
306 | }
307 |
308 | protected function inspect(display:DisplayObject):void
309 | {
310 | console.refs.focus(display);
311 | }
312 |
313 | override public function close():void
314 | {
315 | stop();
316 | super.close();
317 | }
318 | }
319 | }
320 |
--------------------------------------------------------------------------------
/src/com/junkbyte/console/addons/htmlexport/ConsoleHTMLRefsGen.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.addons.htmlexport
26 | {
27 | import com.junkbyte.console.Console;
28 | import com.junkbyte.console.core.LogReferences;
29 | import com.junkbyte.console.vos.Log;
30 |
31 | import flash.utils.describeType;
32 |
33 | /**
34 | * @private
35 | */
36 | public class ConsoleHTMLRefsGen
37 | {
38 | private static const refSearchExpression:RegExp = //g;
39 |
40 | private var console:Console;
41 | private var referencesDepth:uint;
42 |
43 | private var referencesMap:Object;
44 |
45 | public function ConsoleHTMLRefsGen(console:Console, referencesDepth:uint)
46 | {
47 | this.console = console;
48 | this.referencesDepth = referencesDepth;
49 | }
50 |
51 | public function fillData(data:Object):void
52 | {
53 | referencesMap = new Object();
54 |
55 | data.references = referencesMap;
56 |
57 | var line:Log = console.logs.last;
58 | while(line)
59 | {
60 | processRefIdsFromLine(line.text);
61 | line = line.prev;
62 | }
63 | }
64 |
65 | private function processRefIdsFromLine(line:String, currentDepth:uint = 0):void
66 | {
67 | refSearchExpression.lastIndex = 0;
68 | var result:Object = refSearchExpression.exec(line);
69 | while(result != null)
70 | {
71 | var id:uint = uint(result[2]);
72 | processRefId(id, currentDepth);
73 | result = refSearchExpression.exec(line);
74 | }
75 | }
76 |
77 | private function processRefId(id:uint, currentDepth:uint):void
78 | {
79 | var obj:* = console.refs.getRefById(id);
80 | if(obj != null && referencesMap[id] == null)
81 | {
82 | referencesMap[id] = processRef(obj, currentDepth);
83 | }
84 | }
85 |
86 | private function processRef(obj:Object, currentDepth:uint):Object
87 | {
88 | // should reuse code from LogReference, but not possible atm. wait for modular version.
89 |
90 | var V:XML = describeType(obj);
91 | var cls:Object = obj is Class?obj:obj.constructor;
92 | var clsV:XML = describeType(cls);
93 |
94 | var isClass:Boolean = obj is Class;
95 |
96 | var result:Object = new Object();
97 | var isstatic:Boolean;
98 | var targetObj:Object;
99 |
100 |
101 | result.name = LogReferences.EscHTML(V.@name);
102 | /*
103 | var properties:Object = new Object();
104 | result.properties = properties;
105 | properties.isStatic = V.@isDynamic=="true";
106 | properties.isDynamic = V.@isDynamic=="true";
107 | properties.isFinal = V.@isFinal=="true";
108 | */
109 | //
110 | // constants
111 | //
112 | var constants:Object = new Object();
113 | result.constants = constants;
114 | for each (var constantX:XML in clsV..constant)
115 | {
116 | constants[constantX.@name.toString()] = makeValue(cls, constantX.@name.toString(), currentDepth);
117 | }
118 | //
119 | // accessors
120 | //
121 | var accessors:Object = new Object();
122 | result.accessors = accessors;
123 | var staticAccessors:Object = new Object();
124 | result.staticAccessors = staticAccessors;
125 | for each (var accessorX:XML in clsV..accessor)
126 | {
127 | isstatic = accessorX.parent().name()!="factory";
128 | targetObj = isstatic ? staticAccessors : accessors;
129 |
130 | if(accessorX.@access.toString() != "writeonly" && (isstatic || !isClass))
131 | {
132 | targetObj[accessorX.@name] = makeValue(isstatic?cls:obj, accessorX.@name.toString(), currentDepth);
133 | }
134 | }
135 |
136 | //
137 | // variables
138 | //
139 | var variables:Object = new Object();
140 | result.variables = variables;
141 | var staticVariables:Object = new Object();
142 | result.staticVariables = staticVariables;
143 | for each (var variableX:XML in clsV..variable)
144 | {
145 | isstatic = variableX.parent().name()!="factory";
146 | targetObj = isstatic ? staticVariables : variables;
147 | targetObj[variableX.@name] = makeValue(isstatic ? cls : obj, variableX.@name.toString(), currentDepth);
148 | }
149 | //
150 | // dynamic values
151 | // - It can sometimes fail if we are looking at proxy object which havnt extended nextNameIndex, nextName, etc.
152 | var dynamicVariables:Object = new Object();
153 | result.dynamicVariables = dynamicVariables;
154 | try
155 | {
156 | for (var X:* in obj)
157 | {
158 | dynamicVariables[X] = makeValue(obj, X, currentDepth);
159 | }
160 | }
161 | catch(e : Error)
162 | {
163 | result.dynamicVariables = e.message;
164 | }
165 |
166 | return result;
167 | }
168 |
169 | private function makeValue(obj:*, prop:*, currentDepth:uint):String
170 | {
171 | try
172 | {
173 | var v:* = obj[prop];
174 | }
175 | catch(err:Error)
176 | {
177 | return ""+err.toString()+"";
178 | }
179 | var string:String = console.refs.makeString(v, null, true);
180 | if(currentDepth < referencesDepth)
181 | {
182 | currentDepth++;
183 | processRefIdsFromLine(string, currentDepth);
184 | }
185 | return string;
186 | }
187 |
188 | }
189 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/addons/htmlexport/ConsoleHtmlExportAddon.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2011 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | * REQUIRES Flash Player 11.0 OR com.adobe.serialization.json.JSON
25 | */
26 | package com.junkbyte.console.addons.htmlexport
27 | {
28 | import com.junkbyte.console.Cc;
29 | import com.junkbyte.console.Console;
30 | import com.junkbyte.console.ConsoleConfig;
31 | import com.junkbyte.console.ConsoleStyle;
32 | import com.junkbyte.console.view.MainPanel;
33 | import com.junkbyte.console.vos.Log;
34 |
35 | import flash.net.FileReference;
36 | import flash.utils.ByteArray;
37 | import flash.utils.describeType;
38 | import flash.utils.getDefinitionByName;
39 |
40 | /**
41 | * This addon allows you to export logs from flash console to a HTML file.
42 | *
43 | *
44 | * - Preserves channels and priorities.
45 | * - It also have all those filtering features in HTML page.
46 | * - Add to Console menu by calling ConsoleHtmlExport.addMenuToConsole();
47 | *
48 | *
49 | * REQUIRES Flash Player 11.0 OR com.adobe.serialization.json.JSON library.
50 | */
51 | public class ConsoleHtmlExportAddon
52 | {
53 | [Embed(source = "template.html", mimeType = "application/octet-stream")]
54 | private static var EmbeddedTemplate:Class;
55 |
56 | public static const HTML_REPLACEMENT:String = "{text:'HTML_REPLACEMENT'}";
57 |
58 | public var referencesDepth:uint = 1;
59 |
60 | protected var console:Console;
61 |
62 | /**
63 | * Adding 'export' menu item at the top menu of Console.
64 | *
65 | * @param menuName Name of menu. Default = 'export'
66 | * @param console Instance to Console. You do not need to pass this param if you use Cc.
67 | *
68 | * @return New ConsoleHTMLExport instance created by this method.
69 | */
70 | public static function addToMenu(menuName:String = "export", console:Console = null):ConsoleHtmlExportAddon
71 | {
72 | if (console == null)
73 | {
74 | console = Cc.instance;
75 | }
76 | var exporter:ConsoleHtmlExportAddon;
77 | if (console)
78 | {
79 | exporter = new ConsoleHtmlExportAddon(console);
80 | console.addMenu(menuName, exporter.exportToFile, new Array(), "Export logs to HTML");
81 | }
82 | return exporter;
83 | }
84 |
85 | public function ConsoleHtmlExportAddon(console:Console):void
86 | {
87 | if (console == null)
88 | {
89 | console = Cc.instance;
90 | }
91 | this.console = console;
92 | }
93 |
94 | /**
95 | * Trigger 'save to file' dialogue to save console logs in HTML file.
96 | *
97 | * @param fileName Initial file name to use in save dialogue.
98 | */
99 | public function exportToFile(fileName:String = null):void
100 | {
101 | if (fileName == null)
102 | {
103 | fileName = generateFileName();
104 | }
105 |
106 | var file:FileReference = new FileReference();
107 | try
108 | {
109 | var html:String = exportHTMLString();
110 | file['save'](html, fileName); // flash player 10+
111 | }
112 | catch (err:Error)
113 | {
114 | console.report("Failed to save to file: " + err, 8);
115 | }
116 | }
117 |
118 | protected function generateFileName():String
119 | {
120 | var date:Date = new Date();
121 | var fileName:String = "log@" + date.getFullYear() + "." + (date.getMonth() + 1) + "." + (date.getDate() + 1);
122 | fileName += "_" + date.hours + "." + date.minutes;
123 | fileName += ".html";
124 | return fileName;
125 | }
126 |
127 | /**
128 | * Generate HTML String of Console logs.
129 | */
130 | public function exportHTMLString():String
131 | {
132 | var html:String = String(new EmbeddedTemplate() as ByteArray);
133 | html = html.replace(HTML_REPLACEMENT, exportJSON());
134 | return html;
135 | }
136 |
137 | protected function exportJSON():String
138 | {
139 | var object:Object = exportObject();
140 | try
141 | {
142 | var nativeJSON:Class = getDefinitionByName("JSON") as Class;
143 | return nativeJSON["stringify"](object);
144 | }
145 | catch (error:Error)
146 | {
147 | // native json not found. pre flash player 11.
148 | }
149 | var libJSON:Class = getDefinitionByName("com.adobe.serialization.json.JSON") as Class;
150 | return libJSON["encode"](object);
151 | }
152 |
153 | protected function exportObject():Object
154 | {
155 | var data:Object = new Object();
156 |
157 | data.config = getConfigToEncode();
158 |
159 | data.ui = getUIDataToEncode();
160 |
161 | data.logs = getLogsToEncode();
162 |
163 | var refs:ConsoleHTMLRefsGen = new ConsoleHTMLRefsGen(console, referencesDepth);
164 | refs.fillData(data);
165 |
166 | return data;
167 | }
168 |
169 | protected function getConfigToEncode():Object
170 | {
171 | var config:ConsoleConfig = console.config;
172 | var object:Object = convertTypeToObject(config);
173 | object.style = getStyleToEncode();
174 | return object;
175 | }
176 |
177 | protected function getStyleToEncode():Object
178 | {
179 | var style:ConsoleStyle = console.config.style;
180 | /*if(!preserveStyle)
181 | {
182 | style = new ConsoleStyle();
183 | style.updateStyleSheet();
184 | }*/
185 |
186 | var object:Object = convertTypeToObject(style);
187 | object.styleSheet = getStyleSheetToEncode(style);
188 |
189 | return object;
190 | }
191 |
192 | protected function getStyleSheetToEncode(style:ConsoleStyle):Object
193 | {
194 | var object:Object = new Object();
195 | for each (var styleName:String in style.styleSheet.styleNames)
196 | {
197 | object[styleName] = style.styleSheet.getStyle(styleName);
198 | }
199 | return object;
200 | }
201 |
202 | protected function getUIDataToEncode():Object
203 | {
204 | var object:Object = new Object();
205 |
206 | var mainPanel:MainPanel = console.panels.mainPanel;
207 | object.viewingPriority = mainPanel.priority;
208 | object.viewingChannels = mainPanel.viewingChannels;
209 | object.ignoredChannels = mainPanel.ignoredChannels;
210 |
211 | return object;
212 | }
213 |
214 | protected function getLogsToEncode():Object
215 | {
216 | var lines:Array = new Array();
217 | var line:Log = console.logs.last;
218 | while (line)
219 | {
220 | var obj:Object = convertTypeToObject(line);
221 | delete obj.next;
222 | delete obj.prev;
223 | lines.push(obj);
224 | line = line.prev;
225 | }
226 | lines = lines.reverse();
227 | return lines;
228 | }
229 |
230 | protected function convertTypeToObject(typedObject:Object):Object
231 | {
232 | var object:Object = new Object();
233 | var desc:XML = describeType(typedObject);
234 | for each (var varXML:XML in desc.variable)
235 | {
236 | var key:String = varXML.@name;
237 | object[key] = typedObject[key];
238 | }
239 | return object;
240 | }
241 | }
242 | }
243 |
--------------------------------------------------------------------------------
/src/com/junkbyte/console/addons/memoryRecorder/MemoryRecorder.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.addons.memoryRecorder
26 | {
27 | import flash.display.Sprite;
28 | import flash.events.Event;
29 | import flash.events.EventDispatcher;
30 | import flash.sampler.NewObjectSample;
31 | import flash.sampler.Sample;
32 | import flash.sampler.clearSamples;
33 | import flash.sampler.getSamples;
34 | import flash.sampler.pauseSampling;
35 | import flash.sampler.startSampling;
36 | import flash.system.System;
37 | import flash.utils.getDefinitionByName;
38 | import flash.utils.getQualifiedClassName;
39 | import flash.utils.getTimer;
40 |
41 | public class MemoryRecorder extends EventDispatcher
42 | {
43 | public static var instance:MemoryRecorder = new MemoryRecorder();
44 |
45 | private var _interestedClassExpressions:Array = new Array();
46 | private var _ignoredClassExpressions:Array = new Array();
47 |
48 | private var _started:Boolean;
49 |
50 | private var startMemory:uint;
51 | private var endMemory:uint;
52 | private var startTimer:int;
53 | private var endTimer:int;
54 |
55 | private var ticker:Sprite;
56 |
57 | public var reportCallback:Function;
58 |
59 | public function get ignoredClassExpressions():Array
60 | {
61 | return _ignoredClassExpressions;
62 | }
63 |
64 | public function addIgnoredClassExpression(expression:*):void
65 | {
66 | _ignoredClassExpressions.push(expression);
67 | }
68 |
69 | public function get interestedClassExpressions():Array
70 | {
71 | return _interestedClassExpressions;
72 | }
73 |
74 | public function addInterestedClassExpression(expression:*):void
75 | {
76 | _interestedClassExpressions.push(expression);
77 | }
78 |
79 | public function get running():Boolean
80 | {
81 | return _started || ticker != null;
82 | }
83 |
84 | public function start():void
85 | {
86 | if (running)
87 | {
88 | return;
89 | }
90 |
91 | _started = true;
92 |
93 | startMemory = System.totalMemory;
94 | startTimer = getTimer();
95 |
96 | startSampling();
97 | clearSamples();
98 | }
99 |
100 | public function end():void
101 | {
102 | if (!_started || ticker != null)
103 | {
104 | return;
105 | }
106 |
107 | pauseSampling();
108 | endMemory = System.totalMemory;
109 | endTimer = getTimer();
110 |
111 | System.gc();
112 | ticker = new Sprite();
113 | ticker.addEventListener(Event.ENTER_FRAME, onEndingEnterFrame);
114 | }
115 |
116 | private function onEndingEnterFrame(event:Event):void
117 | {
118 | ticker.removeEventListener(Event.ENTER_FRAME, onEndingEnterFrame);
119 | ticker = null;
120 | System.gc();
121 | endSampling();
122 | dispatchEvent(new Event(Event.COMPLETE));
123 | }
124 |
125 | private function endSampling():void
126 | {
127 | var newCount:uint;
128 | var liveCount:uint;
129 | var lastMicroTime:Number = 0;
130 |
131 | report("MemoryRecorder...");
132 | report("Objects still alive: >>>");
133 |
134 | var objectsMap:Object = new Object();
135 | for each (var sample:Sample in getSamples())
136 | {
137 | if (sample is NewObjectSample)
138 | {
139 | var newSample:NewObjectSample = NewObjectSample(sample);
140 | if (shouldPrintClass(newSample.type))
141 | {
142 | newCount++;
143 | if (newSample.object !== undefined)
144 | {
145 | liveCount++;
146 | reportNewSample(newSample);
147 | }
148 | }
149 | }
150 | /*
151 | else if (sample is DeleteObjectSample)
152 | {
153 | //var delSample:DeleteObjectSample = DeleteObjectSample(s);
154 | }
155 | else
156 | {
157 |
158 | }*/
159 | }
160 |
161 | var timerTaken:uint = endTimer - startTimer;
162 |
163 | report("<<<", liveCount, "object(s).");
164 | report("New objects:", newCount);
165 | report("Time taken:", timerTaken + "ms.");
166 | report("Memory change:", roundMem(startMemory) + "mb to", roundMem(endMemory) + "mb (" + roundMem(endMemory - startMemory) + "mb)");
167 |
168 | _started = false;
169 | clearSamples();
170 | }
171 |
172 | private function roundMem(num:int):Number
173 | {
174 | return Math.round(num / 10485.76) / 100;
175 | }
176 |
177 | private function reportNewSample(sample:NewObjectSample):void
178 | {
179 | var className:String = getQualifiedClassName(sample.type);
180 | try
181 | {
182 | if (sample.type == String)
183 | {
184 | reportNewStringSample(sample, className);
185 | }
186 | else
187 | {
188 | report(sample.id, className, getSampleSize(sample), sample.object, getSampleStack(sample));
189 | }
190 | }
191 | catch (err:Error)
192 | {
193 | report(sample.id, getSampleSize(sample), className, getSampleStack(sample));
194 | }
195 | }
196 |
197 | private function reportNewStringSample(sample:NewObjectSample, className:String):void
198 | {
199 | var output:String = "";
200 | var masterStringFunction:Function = getDefinitionByName("flash.sampler.getMasterString") as Function; // only supported post flash 10.1
201 |
202 | var str:String = sample.object;
203 | if (masterStringFunction != null)
204 | {
205 | while (str)
206 | {
207 | output += "\"" + str + "\" > ";
208 | str = masterStringFunction(str);
209 | }
210 | }
211 | report(sample.id, className, getSampleSize(sample), output, getSampleStack(sample));
212 | }
213 |
214 | private function getSampleStack(sample:Sample):String
215 | {
216 | var output:String = "";
217 | for each (var stack:String in sample.stack)
218 | {
219 | stack = stack.replace(/.*?\:\:/, "");
220 | stack = stack.replace(/\[.*?\:([0-9]+)\]/, ":$1");
221 | output += stack + "; ";
222 | }
223 | return output;
224 | }
225 |
226 | private function getSampleSize(sample:Sample):String
227 | {
228 | if ("size" in sample)
229 | {
230 | return sample['size'];
231 | }
232 | return "";
233 | }
234 |
235 | private function report(... args:Array):void
236 | {
237 | var call:Function = reportCallback != null ? reportCallback : trace;
238 | call.apply(this, args);
239 | }
240 |
241 | private function shouldPrintClass(type:Class):Boolean
242 | {
243 | return !isClassInIgnoredList(type) && isClassInInterestedList(type);
244 | }
245 |
246 | private function isClassInInterestedList(type:Class):Boolean
247 | {
248 | if (_interestedClassExpressions.length == 0)
249 | {
250 | return true;
251 | }
252 | return classMatchesExpressionList(type, _interestedClassExpressions);
253 | }
254 |
255 | private function isClassInIgnoredList(type:Class):Boolean
256 | {
257 | return classMatchesExpressionList(type, _ignoredClassExpressions);
258 | }
259 |
260 | private function classMatchesExpressionList(type:Class, list:Array):Boolean
261 | {
262 | var className:String = getQualifiedClassName(type);
263 | for each (var expression:* in list)
264 | {
265 | if (className.search(expression) == 0)
266 | {
267 | return true;
268 | }
269 | }
270 | return false;
271 | }
272 | }
273 | }
274 |
--------------------------------------------------------------------------------
/src/com/junkbyte/console/addons/memoryRecorder/MemoryRecorderAddon.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.addons.memoryRecorder
26 | {
27 | import com.junkbyte.console.Console;
28 | import com.junkbyte.console.KeyBind;
29 |
30 | public class MemoryRecorderAddon
31 | {
32 |
33 | public static function registerToConsole(console:Console, key:String = "r"):void
34 | {
35 | MemoryRecorder.instance.reportCallback = function(... args:Array):void
36 | {
37 | args.unshift("R");
38 | console.infoch.apply(null, args);
39 | }
40 |
41 | var onMemoryRecorderStart:Function = function():void
42 | {
43 | if (MemoryRecorder.instance.running == false)
44 | {
45 | MemoryRecorder.instance.start();
46 | }
47 | }
48 |
49 | var onMemoryRecorderEnd:Function = function():void
50 | {
51 | if (MemoryRecorder.instance.running)
52 | {
53 | console.clear("R");
54 | MemoryRecorder.instance.end();
55 | }
56 | }
57 |
58 | console.bindKey(new KeyBind(key), onMemoryRecorderStart);
59 | console.bindKey(new KeyBind(key, false, false, false, true), onMemoryRecorderEnd);
60 | }
61 |
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/com/junkbyte/console/core/ConsoleCore.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.core
26 | {
27 | import com.junkbyte.console.Console;
28 | import com.junkbyte.console.ConsoleConfig;
29 |
30 | import flash.events.EventDispatcher;
31 |
32 | /**
33 | * @private
34 | */
35 | public class ConsoleCore extends EventDispatcher
36 | {
37 | protected var console:Console;
38 | protected var config:ConsoleConfig;
39 |
40 | public function ConsoleCore(c:Console)
41 | {
42 | console = c;
43 | config = console.config;
44 | }
45 |
46 | protected function get remoter():Remoting
47 | {
48 | return console.remoter;
49 | }
50 |
51 | protected function report(obj:* = "", priority:int = 0, skipSafe:Boolean = true, ch:String = null):void
52 | {
53 | console.report(obj, priority, skipSafe, ch);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/com/junkbyte/console/core/ConsoleTools.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.core
26 | {
27 | import flash.utils.ByteArray;
28 | import flash.utils.describeType;
29 | import com.junkbyte.console.Cc;
30 | import flash.utils.getQualifiedClassName;
31 | import com.junkbyte.console.Console;
32 |
33 | import flash.display.DisplayObject;
34 | import flash.display.DisplayObjectContainer;
35 |
36 | /**
37 | * @private
38 | */
39 | public class ConsoleTools extends ConsoleCore{
40 |
41 | public function ConsoleTools(console:Console) {
42 | super(console);
43 | }
44 | public function map(base:DisplayObjectContainer, maxstep:uint = 0, ch:String = null):void{
45 | if(!base){
46 | report("Not a DisplayObjectContainer.", 10, true, ch);
47 | return;
48 | }
49 |
50 | var steps:int = 0;
51 | var wasHiding:Boolean;
52 | var index:int = 0;
53 | var lastmcDO:DisplayObject = null;
54 | var list:Array = new Array();
55 | list.push(base);
56 | while(index0){
77 | steps--;
78 | }
79 | if((lastmcDO as DisplayObjectContainer).contains(mcDO)){
80 | steps++;
81 | break;
82 | }
83 | }
84 | }
85 | }
86 | }
87 | var str:String = "";
88 | for(i=0;i"+n+"";
96 | if(mcDO is DisplayObjectContainer){
97 | n = ""+n+"";
98 | }else{
99 | n = ""+n+"";
100 | }
101 | str += n+" "+console.refs.makeRefTyped(mcDO);
102 | report(str,mcDO is DisplayObjectContainer?5:2, true, ch);
103 | }else if(!wasHiding){
104 | wasHiding = true;
105 | report(str+"...",5, true, ch);
106 | }
107 | lastmcDO = mcDO;
108 | }
109 | report(base.name + ":" + console.refs.makeRefTyped(base) + " has " + (list.length - 1) + " children/sub-children.", 9, true, ch);
110 | if (config.commandLineAllowed) report("Click on the child display's name to set scope.", -2, true, ch);
111 | }
112 |
113 |
114 | public function explode(obj:Object, depth:int = 3, p:int = 9):String{
115 | var t:String = typeof obj;
116 | if(obj == null){
117 | // could be null, undefined, NaN, 0, etc. all should be printed as is
118 | return ""+obj+"";
119 | }else if(obj is String){
120 | return '"'+LogReferences.EscHTML(obj as String)+'"';
121 | }else if(t != "object" || depth == 0 || obj is ByteArray){
122 | return console.refs.makeString(obj);
123 | }
124 | if(p<0) p = 0;
125 | var V:XML = describeType(obj);
126 | var nodes:XMLList, n:String;
127 | var list:Array = [];
128 | //
129 | nodes = V["accessor"];
130 | for each (var accessorX:XML in nodes) {
131 | n = accessorX.@name;
132 | if(accessorX.@access!="writeonly"){
133 | try{
134 | list.push(stepExp(obj, n, depth, p));
135 | }catch(e:Error){}
136 | }else{
137 | list.push(n);
138 | }
139 | }
140 | //
141 | nodes = V["variable"];
142 | for each (var variableX:XML in nodes) {
143 | n = variableX.@name;
144 | list.push(stepExp(obj, n, depth, p));
145 | }
146 | //
147 | try{
148 | for (var X:String in obj) {
149 | list.push(stepExp(obj, X, depth, p));
150 | }
151 | }catch(e:Error){}
152 | return "{"+LogReferences.ShortClassName(obj)+"
"+list.join(", ")+"}
";
153 | }
154 | private function stepExp(o:*, n:String, d:int, p:int):String{
155 | return n+":"+explode(o[n], d-1, p-1);
156 | }
157 |
158 | public function getStack(depth:int, priority:int):String{
159 | var e:Error = new Error();
160 | var str:String = e.hasOwnProperty("getStackTrace")?e.getStackTrace():null;
161 | if(!str) return "";
162 | var txt:String = "";
163 | var lines:Array = str.split(/\n\sat\s/);
164 | var len:int = lines.length;
165 | var reg:RegExp = new RegExp("Function|"+getQualifiedClassName(Console)+"|"+getQualifiedClassName(Cc));
166 | var found:Boolean = false;
167 | for (var i:int = 2; i < len; i++){
168 | if(!found && (lines[i].search(reg) != 0)){
169 | found = true;
170 | }
171 | if(found){
172 | txt += "\n @ "+lines[i]+"
";
173 | if(priority>0) priority--;
174 | depth--;
175 | if(depth<=0){
176 | break;
177 | }
178 | }
179 | }
180 | return txt;
181 | }
182 | }
183 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/core/Graphing.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.core {
26 | import flash.utils.ByteArray;
27 | import com.junkbyte.console.Console;
28 | import flash.system.System;
29 | import flash.utils.getTimer;
30 |
31 | import com.junkbyte.console.vos.GraphInterest;
32 | import com.junkbyte.console.vos.GraphGroup;
33 |
34 | import flash.geom.Rectangle;
35 |
36 | /**
37 | * @private
38 | */
39 | public class Graphing extends ConsoleCore{
40 |
41 | private var _groups:Array = [];
42 | private var _map:Object = {};
43 |
44 | private var _fpsGroup:GraphGroup;
45 | private var _memGroup:GraphGroup;
46 |
47 | private var _hadGraph:Boolean;
48 | private var _previousTime:Number = -1;
49 |
50 | public function Graphing(m:Console){
51 | super(m);
52 | remoter.registerCallback("fps", function(bytes:ByteArray):void{
53 | fpsMonitor = bytes.readBoolean();
54 | });
55 | remoter.registerCallback("mem", function(bytes:ByteArray):void{
56 | memoryMonitor = bytes.readBoolean();
57 | });
58 | remoter.registerCallback("removeGroup", function(bytes:ByteArray):void{
59 | removeGroup(bytes.readUTF());
60 | });
61 | remoter.registerCallback("graph", handleRemoteGraph, true);
62 |
63 | }
64 | public function add(n:String, obj:Object, prop:String, col:Number = -1, key:String = null, rect:Rectangle = null, inverse:Boolean = false):void{
65 | if(obj == null) {
66 | report("ERROR: Graph ["+n+"] received a null object to graph property ["+prop+"].", 10);
67 | return;
68 | }
69 | var group:GraphGroup = _map[n];
70 | var newGroup:Boolean;
71 | if(!group) {
72 | newGroup = true;
73 | group = new GraphGroup(n);
74 | }
75 | var interests:Array = group.interests;
76 | if (isNaN(col) || col < 0) {
77 | if (interests.length <= 5) col = config.style["priority"+ (10-interests.length*2)];
78 | else col = Math.random()*0xFFFFFF;
79 | }
80 | if(key == null) key = prop;
81 | for each(var i:GraphInterest in interests){
82 | if(i.key == key){
83 | report("Graph with key ["+key+"] already exists in ["+n+"]", 10);
84 | return;
85 | }
86 | }
87 | if(rect) group.rect = rect;
88 | if(inverse) group.inv = inverse;
89 | var interest:GraphInterest = new GraphInterest(key, col);
90 | var v:Number = NaN;
91 | try{
92 | v = interest.setObject(obj, prop);
93 | }catch (e:Error){
94 | report("Error with graph value for ["+key+"] in ["+n+"]. "+e, 10);
95 | return;
96 | }
97 | if(isNaN(v)){
98 | report("Graph value for key ["+key+"] in ["+n+"] is not a number (NaN).", 10);
99 | }else{
100 | group.interests.push(interest);
101 | if(newGroup){
102 | _map[n] = group;
103 | _groups.push(group);
104 | }
105 | }
106 | }
107 |
108 | public function fixRange(n:String, low:Number = NaN, high:Number = NaN):void{
109 | var group:GraphGroup = _map[n];
110 | if(!group) return;
111 | group.low = low;
112 | group.hi = high;
113 | group.fixed = !(isNaN(low)||isNaN(high));
114 | }
115 | public function remove(n:String, obj:Object = null, prop:String = null):void{
116 | if(obj==null&&prop==null){
117 | removeGroup(n);
118 | }else if(_map[n]){
119 | var interests:Array = _map[n].interests;
120 | for(var i:int = interests.length-1;i>=0;i--){
121 | var interest:GraphInterest = interests[i];
122 | if((obj == null || interest.obj == obj) && (prop == null || interest.prop == prop)){
123 | interests.splice(i, 1);
124 | }
125 | }
126 | if(interests.length==0){
127 | removeGroup(n);
128 | }
129 | }
130 | }
131 | private function removeGroup(n:String):void{
132 | if(remoter.remoting == Remoting.RECIEVER) {
133 | var bytes:ByteArray = new ByteArray();
134 | bytes.writeUTF(n);
135 | remoter.send("removeGroup", bytes);
136 | }else{
137 | var g:GraphGroup = _map[n];
138 | var index:int = _groups.indexOf(g);
139 | if(index>=0) _groups.splice(index, 1);
140 | delete _map[n];
141 | }
142 | }
143 | public function get fpsMonitor():Boolean{
144 | if(remoter.remoting == Remoting.RECIEVER) return console.panels.fpsMonitor;
145 | return _fpsGroup!=null;
146 | }
147 | public function set fpsMonitor(b:Boolean):void{
148 | if(remoter.remoting == Remoting.RECIEVER) {
149 | var bytes:ByteArray = new ByteArray();
150 | bytes.writeBoolean(b);
151 | remoter.send("fps", bytes);
152 | }else if(b != fpsMonitor){
153 | if(b) {
154 | _fpsGroup = addSpecialGroup(GraphGroup.FPS);
155 | _fpsGroup.low = 0;
156 | _fpsGroup.fixed = true;
157 | _fpsGroup.averaging = 30;
158 | } else{
159 | _previousTime = -1;
160 | var index:int = _groups.indexOf(_fpsGroup);
161 | if(index>=0) _groups.splice(index, 1);
162 | _fpsGroup = null;
163 | }
164 | console.panels.mainPanel.updateMenu();
165 | }
166 | }
167 | //
168 | public function get memoryMonitor():Boolean{
169 | if(remoter.remoting == Remoting.RECIEVER) return console.panels.memoryMonitor;
170 | return _memGroup!=null;
171 | }
172 | public function set memoryMonitor(b:Boolean):void{
173 | if(remoter.remoting == Remoting.RECIEVER) {
174 | var bytes:ByteArray = new ByteArray();
175 | bytes.writeBoolean(b);
176 | remoter.send("mem", bytes);
177 | }else if(b != memoryMonitor){
178 | if(b) {
179 | _memGroup = addSpecialGroup(GraphGroup.MEM);
180 | _memGroup.freq = 20;
181 | } else{
182 | var index:int = _groups.indexOf(_memGroup);
183 | if(index>=0) _groups.splice(index, 1);
184 | _memGroup = null;
185 | }
186 | console.panels.mainPanel.updateMenu();
187 | }
188 | }
189 | private function addSpecialGroup(type:int):GraphGroup{
190 | var group:GraphGroup = new GraphGroup("special");
191 | group.type = type;
192 | _groups.push(group);
193 | var graph:GraphInterest = new GraphInterest("special");
194 | if(type == GraphGroup.FPS) {
195 | graph.col = 0xFF3333;
196 | }else{
197 | graph.col = 0x5060FF;
198 | }
199 | group.interests.push(graph);
200 | return group;
201 | }
202 | public function update(fps:Number = 0):Array{
203 | var interest:GraphInterest;
204 | var v:Number;
205 | for each(var group:GraphGroup in _groups){
206 | var ok:Boolean = true;
207 | if(group.freq>1){
208 | group.idle++;
209 | if(group.idle= 0){
224 | var mspf:Number = time-_previousTime;
225 | v = 1000/mspf;
226 | interest.setValue(v, averaging);
227 | }
228 | _previousTime = time;
229 | }else if(typ == GraphGroup.MEM){
230 | interest = interests[0];
231 | v = Math.round(System.totalMemory/10485.76)/100;
232 | group.updateMinMax(v);
233 | interest.setValue(v, averaging);
234 | }else{
235 | updateExternalGraphGroup(group);
236 | }
237 | }
238 | }
239 | if(remoter.canSend && (_hadGraph || _groups.length)){
240 | var len:uint = _groups.length;
241 | var ga:ByteArray = new ByteArray();
242 | for(var j:uint = 0; j0;
247 | }
248 | return _groups;
249 | }
250 |
251 | private function updateExternalGraphGroup(group:GraphGroup):void
252 | {
253 | for each(var i:GraphInterest in group.interests){
254 | try{
255 | var v:Number = i.getCurrentValue();
256 | i.setValue(v, group.averaging);
257 | }catch(e:Error){
258 | report("Error with graph value for key ["+i.key+"] in ["+group.name+"]. "+e, 10);
259 | remove(group.name, i.obj, i.prop);
260 | }
261 | group.updateMinMax(v);
262 | }
263 | }
264 |
265 | private function handleRemoteGraph(bytes:ByteArray = null):void{
266 | if(bytes && bytes.length){
267 | bytes.position = 0;
268 | var a:Array = new Array();
269 | while(bytes.bytesAvailable){
270 | a.push(GraphGroup.FromBytes(bytes));
271 | }
272 | console.panels.updateGraphs(a);
273 | }else{
274 | console.panels.updateGraphs(new Array());
275 | }
276 | }
277 | }
278 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/core/KeyBinder.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.core
26 | {
27 | import flash.text.TextFieldType;
28 | import flash.text.TextField;
29 | import com.junkbyte.console.Console;
30 | import com.junkbyte.console.KeyBind;
31 |
32 | import flash.events.KeyboardEvent;
33 |
34 | /**
35 | * @private
36 | *
37 | * Suppse this could be 'view' ?
38 | */
39 | public class KeyBinder extends ConsoleCore{
40 |
41 | private var _passInd:int;
42 | private var _binds:Object = {};
43 |
44 | private var _warns:uint;
45 |
46 | public function KeyBinder(console:Console) {
47 | super(console);
48 |
49 | console.cl.addCLCmd("keybinds", printBinds, "List all keybinds used");
50 | }
51 | public function bindKey(key:KeyBind, fun:Function ,args:Array = null):void{
52 | if(config.keystrokePassword && (!key.useKeyCode && key.key.charAt(0) == config.keystrokePassword.charAt(0))){
53 | report("Error: KeyBind ["+key.key+"] is conflicting with Console password.",9);
54 | return;
55 | }
56 | if(fun == null){
57 | delete _binds[key.key];
58 | //if(!config.quiet) report("Unbined key "+key.key+".", -1);
59 | }else{
60 | _binds[key.key] = [fun, args];
61 | //if(!config.quiet) report("Bined key "+key.key+" to a function."+(config.keyBindsEnabled?"":" (will not trigger while key binding is disabled in config)"), -1);
62 | }
63 | }
64 | public function keyDownHandler(e:KeyboardEvent):void{
65 | handleKeyEvent(e, false);
66 | }
67 | public function keyUpHandler(e:KeyboardEvent):void{
68 | handleKeyEvent(e, true);
69 | }
70 |
71 | private function handleKeyEvent(e:KeyboardEvent, isKeyUp:Boolean):void
72 | {
73 | var char:String = String.fromCharCode(e.charCode);
74 | if(isKeyUp && config.keystrokePassword != null && char && char == config.keystrokePassword.substring(_passInd,_passInd+1)){
75 | _passInd++;
76 | if(_passInd >= config.keystrokePassword.length){
77 | _passInd = 0;
78 | if(canTrigger()){
79 | if(console.visible && !console.panels.mainPanel.visible){
80 | console.panels.mainPanel.visible = true;
81 | }else {
82 | console.visible = !console.visible;
83 | }
84 | if(console.visible && console.panels.mainPanel.visible){
85 | console.panels.mainPanel.visible = true;
86 | console.panels.mainPanel.moveBackSafePosition();
87 | }
88 | }else if(_warns < 3){
89 | _warns++;
90 | report("Password did not trigger because you have focus on an input TextField.", 8);
91 | }
92 | }
93 | }
94 | else
95 | {
96 | if(isKeyUp) _passInd = 0;
97 | var bind:KeyBind = new KeyBind(e.keyCode, e.shiftKey, e.ctrlKey, e.altKey, isKeyUp);
98 | tryRunKey(bind.key);
99 | if(char){
100 | bind = new KeyBind(char, e.shiftKey, e.ctrlKey, e.altKey, isKeyUp);
101 | tryRunKey(bind.key);
102 | }
103 | }
104 | }
105 | private function printBinds(...args:Array):void{
106 | report("Key binds:", -2);
107 | var i:uint = 0;
108 | for (var X:String in _binds){
109 | i++;
110 | report(X, -2);
111 | }
112 | report("--- Found "+i, -2);
113 | }
114 | private function tryRunKey(key:String):void
115 | {
116 | var a:Array = _binds[key];
117 | if(config.keyBindsEnabled && a){
118 | if(canTrigger()){
119 | (a[0] as Function).apply(null, a[1]);
120 | }else if(_warns < 3){
121 | _warns++;
122 | report("Key bind ["+key+"] did not trigger because you have focus on an input TextField.", 8);
123 | }
124 | }
125 | }
126 | private function canTrigger():Boolean{
127 | // in try catch block incase the textfield is in another domain and we wont be able to access the type... (i think)
128 | try {
129 | if(console.stage && console.stage.focus is TextField){
130 | var txt:TextField = console.stage.focus as TextField;
131 | if(txt.type == TextFieldType.INPUT) {
132 | return false;
133 | }
134 | }
135 | }catch(err:Error) { }
136 | return true;
137 | }
138 | }
139 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/core/Logs.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.core
26 | {
27 | import flash.utils.ByteArray;
28 | import flash.events.Event;
29 | import com.junkbyte.console.Console;
30 | import com.junkbyte.console.vos.Log;
31 |
32 | /**
33 | * @private
34 | */
35 | public class Logs extends ConsoleCore{
36 |
37 | private var _channels:Object;
38 | private var _repeating:uint;
39 | private var _lastRepeat:Log;
40 | private var _newRepeat:Log;
41 | private var _timer:uint;
42 |
43 | public var hasNewLog:Boolean;
44 | public var first:Log;
45 | public var last:Log;
46 |
47 | private var _length:uint;
48 | private var _lines:uint; // number of lines since start.
49 |
50 | public function Logs(console:Console){
51 | super(console);
52 | _channels = new Object();
53 | remoter.addEventListener(Event.CONNECT, onRemoteConnection);
54 | remoter.registerCallback("log", function(bytes:ByteArray):void{
55 | registerLog(Log.FromBytes(bytes));
56 | });
57 | }
58 |
59 | private function onRemoteConnection(e:Event):void{
60 | var log:Log = first;
61 | while(log){
62 | send2Remote(log);
63 | log = log.next;
64 | }
65 | }
66 |
67 | private function send2Remote(line:Log):void{
68 | if(remoter.canSend) {
69 | var bytes:ByteArray = new ByteArray();
70 | line.toBytes(bytes);
71 | remoter.send("log", bytes);
72 | }
73 | }
74 |
75 | public function update(time:uint):void{
76 | _timer = time;
77 | if(_repeating > 0) _repeating--;
78 | if(_newRepeat){
79 | if(_lastRepeat) remove(_lastRepeat);
80 | _lastRepeat = _newRepeat;
81 | _newRepeat = null;
82 | push(_lastRepeat);
83 | }
84 | }
85 |
86 | public function add(line:Log):void{
87 | _lines++;
88 | line.line = _lines;
89 | line.time = _timer;
90 |
91 | registerLog(line);
92 | }
93 |
94 | private function registerLog(line:Log):void{
95 | hasNewLog = true;
96 | addChannel(line.ch);
97 |
98 | line.lineStr = line.line +" ";
99 | line.chStr = "["+line.ch+"] ";
100 | line.timeStr = config.timeStampFormatter(line.time) + " ";
101 |
102 | send2Remote(line);
103 | if (line.repeat) {
104 | if(_repeating > 0 && _lastRepeat){
105 | line.line = _lastRepeat.line;
106 | _newRepeat = line;
107 | return;
108 | }else{
109 | _repeating = config.maxRepeats;
110 | _lastRepeat = line;
111 | }
112 | }
113 | //
114 | push(line);
115 | while(_length > config.maxLines && config.maxLines > 0){
116 | remove(first);
117 | }
118 | //
119 | if ( config.tracing && config.traceCall != null) {
120 | config.traceCall(line.ch, line.plainText(), line.priority);
121 | }
122 | }
123 |
124 | public function clear(channel:String = null):void{
125 | if(channel){
126 | var line:Log = first;
127 | while(line){
128 | if(line.ch == channel){
129 | remove(line);
130 | }
131 | line = line.next;
132 | }
133 | delete _channels[channel];
134 | }else{
135 | first = null;
136 | last = null;
137 | _length = 0;
138 | _channels = new Object();
139 | }
140 | }
141 |
142 | public function getLogsAsString(splitter:String, incChNames:Boolean = true, filter:Function = null):String{
143 | var str:String = "";
144 | var line:Log = first;
145 | while(line){
146 | if(filter == null || filter(line)){
147 | if(first != line) str += splitter;
148 | str += incChNames?line.toString():line.plainText();
149 | }
150 | line = line.next;
151 | }
152 | return str;
153 | }
154 |
155 | public function getChannels():Array{
156 | var arr:Array = new Array(Console.GLOBAL_CHANNEL);
157 | addIfexist(Console.DEFAULT_CHANNEL, arr);
158 | addIfexist(Console.FILTER_CHANNEL, arr);
159 | addIfexist(LogReferences.INSPECTING_CHANNEL, arr);
160 | addIfexist(Console.CONSOLE_CHANNEL, arr);
161 | var others:Array = new Array();
162 | for(var X:String in _channels){
163 | if(arr.indexOf(X)<0) others.push(X);
164 | }
165 | return arr.concat(others.sort(Array.CASEINSENSITIVE));
166 | }
167 |
168 | private function addIfexist(n:String, arr:Array):void{
169 | if(_channels.hasOwnProperty(n)) arr.push(n);
170 | }
171 |
172 | public function cleanChannels():void{
173 | _channels = new Object();
174 | var line:Log = first;
175 | while(line){
176 | addChannel(line.ch);
177 | line = line.next;
178 | }
179 | }
180 |
181 | public function addChannel(n:String):void{
182 | _channels[n] = null;
183 | }
184 | //
185 | // Log chain controls
186 | //
187 | private function push(v:Log):void{
188 | if(last==null) {
189 | first = v;
190 | }else{
191 | last.next = v;
192 | v.prev = last;
193 | }
194 | last = v;
195 | _length++;
196 | }
197 | /*
198 | //Made code for these function part of another function to save compile size.
199 | private function pop():void{
200 | if(last) {
201 | if(last == _lastRepeat) _lastRepeat = null;
202 | last = last.prev;
203 | last.next = null;
204 | _length--;
205 | }
206 | }
207 | private function shift(count:uint = 1):void{
208 | while(first != null && count>0){
209 | if(first == _lastRepeat) _lastRepeat = null;
210 | first = first.next;
211 | first.prev = null;
212 | count--;
213 | _length--;
214 | }
215 | }*/
216 | private function remove(log:Log):void{
217 | if(first == log) first = log.next;
218 | if(last == log) last = log.prev;
219 | if(log == _lastRepeat) _lastRepeat = null;
220 | if(log == _newRepeat) _newRepeat = null;
221 | if(log.next != null) log.next.prev = log.prev;
222 | if(log.prev != null) log.prev.next = log.next;
223 | _length--;
224 | }
225 | }
226 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/core/MemoryMonitor.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.core
26 | {
27 | import com.junkbyte.console.Console;
28 |
29 | import flash.system.System;
30 | import flash.utils.Dictionary;
31 | import flash.utils.getQualifiedClassName;
32 | import flash.utils.getTimer;
33 |
34 | /**
35 | * @private
36 | */
37 | public class MemoryMonitor extends ConsoleCore{
38 |
39 | private var _namesList:Object;
40 | private var _objectsList:Dictionary;
41 | private var _count:uint;
42 | //
43 | //
44 | public function MemoryMonitor(m:Console) {
45 | super(m);
46 | _namesList = new Object();
47 | _objectsList = new Dictionary(true);
48 |
49 | console.remoter.registerCallback("gc", gc);
50 | }
51 | public function watch(obj:Object, n:String):String{
52 | var className:String = getQualifiedClassName(obj);
53 | if(!n) n = className+"@"+getTimer();
54 |
55 | if(_objectsList[obj]){
56 | if(_namesList[_objectsList[obj]]){
57 | unwatch(_objectsList[obj]);
58 | }
59 | }
60 | if(_namesList[n]){
61 | if(_objectsList[obj] == n){
62 | _count--;
63 | }else{
64 | n = n+"@"+getTimer()+"_"+Math.floor(Math.random()*100);
65 | }
66 | }
67 | _namesList[n] = true;
68 | _count++;
69 | _objectsList[obj] = n;
70 | //if(!config.quiet) report("Watching "+className+" as "+ n +".",-1);
71 | return n;
72 | }
73 | public function unwatch(n:String):void{
74 | for (var X:Object in _objectsList) {
75 | if(_objectsList[X] == n){
76 | delete _objectsList[X];
77 | }
78 | }
79 | if(_namesList[n])
80 | {
81 | delete _namesList[n];
82 | _count--;
83 | }
84 | }
85 | //
86 | //
87 | //
88 | public function update():void {
89 | if(_count == 0) return;
90 | var arr:Array = new Array();
91 | var o:Object = new Object();
92 | for (var X:Object in _objectsList) {
93 | o[_objectsList[X]] = true;
94 | }
95 | for(var Y:String in _namesList){
96 | if(!o[Y]){
97 | arr.push(Y);
98 | delete _namesList[Y];
99 | _count--;
100 | }
101 | }
102 | if(arr.length) report("GARBAGE COLLECTED "+arr.length+" item(s): "+arr.join(", "),-2);
103 | }
104 |
105 | public function get count():uint{
106 | return _count;
107 | }
108 |
109 | public function gc():void {
110 | if(remoter.remoting == Remoting.RECIEVER){
111 | try{
112 | //report("Sending garbage collection request to client",-1);
113 | remoter.send("gc");
114 | }catch(e:Error){
115 | report(e,10);
116 | }
117 | }else{
118 | var ok:Boolean;
119 | try{
120 | // have to put in brackes cause some compilers will complain.
121 | if(System["gc"] != null){
122 | System["gc"]();
123 | ok = true;
124 | }
125 | }catch(e:Error){ }
126 |
127 | var str:String = "Manual garbage collection "+(ok?"successful.":"FAILED. You need debugger version of flash player.");
128 | report(str,(ok?-1:10));
129 | }
130 | }
131 | }
132 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/view/ChannelsPanel.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.view {
26 | import com.junkbyte.console.Console;
27 |
28 | import flash.events.TextEvent;
29 | import flash.text.TextFieldAutoSize;
30 |
31 | /**
32 | * @private
33 | */
34 | public class ChannelsPanel extends ConsolePanel{
35 |
36 | public static const NAME:String = "channelsPanel";
37 |
38 | public function ChannelsPanel(m:Console) {
39 | super(m);
40 | name = NAME;
41 | init(10,10,false);
42 | txtField = makeTF("channelsField");
43 | txtField.wordWrap = true;
44 | txtField.width = 160;
45 | txtField.multiline = true;
46 | txtField.autoSize = TextFieldAutoSize.LEFT;
47 | registerTFRoller(txtField, onMenuRollOver, linkHandler);
48 | registerDragger(txtField);
49 | addChild(txtField);
50 | }
51 | public function update():void{
52 | txtField.wordWrap = false;
53 | txtField.width = 80;
54 | var str:String = " "+ console.panels.mainPanel.getChannelsLink();
55 | txtField.htmlText = str+"";
56 | if(txtField.width>160){
57 | txtField.wordWrap = true;
58 | txtField.width = 160;
59 | }
60 | width = txtField.width+4;
61 | height = txtField.height;
62 | }
63 | private function onMenuRollOver(e:TextEvent):void{
64 | console.panels.mainPanel.onMenuRollOver(e, this);
65 | }
66 | protected function linkHandler(e:TextEvent):void{
67 | txtField.setSelection(0, 0);
68 | if(e.text == "close"){
69 | console.panels.channelsPanel = false;
70 | }else if(e.text.substring(0,8) == "channel_"){
71 | console.panels.mainPanel.onChannelPressed(e.text.substring(8));
72 | }
73 | txtField.setSelection(0, 0);
74 | e.stopPropagation();
75 | }
76 | }
77 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/view/GraphingPanel.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.view {
26 | import com.junkbyte.console.Console;
27 | import com.junkbyte.console.vos.GraphGroup;
28 | import com.junkbyte.console.vos.GraphInterest;
29 |
30 | import flash.display.Graphics;
31 | import flash.display.Shape;
32 | import flash.events.TextEvent;
33 | import flash.text.TextField;
34 | import flash.text.TextFormat;
35 |
36 | /**
37 | * @private
38 | */
39 | public class GraphingPanel extends ConsolePanel {
40 | //
41 | public static const FPS:String = "fpsPanel";
42 | public static const MEM:String = "memoryPanel";
43 | //
44 | private var _group:GraphGroup;
45 | private var _interest:GraphInterest;
46 | private var _infoMap:Object = new Object();
47 |
48 | private var _menuString:String;
49 | //
50 | private var _type:String;
51 | //
52 | private var _needRedraw:Boolean;
53 | //
54 | private var underlay:Shape;
55 | private var graph:Shape;
56 | private var lowTxt:TextField;
57 | private var highTxt:TextField;
58 | //
59 | public var startOffset:int = 5;
60 | //
61 | public function GraphingPanel(m:Console, W:int, H:int, type:String = null) {
62 | super(m);
63 | _type = type;
64 | registerDragger(bg);
65 | minWidth = 32;
66 | minHeight = 26;
67 | //
68 | var textFormat:TextFormat = new TextFormat();
69 | var lowStyle:Object = style.styleSheet.getStyle("low");
70 | textFormat.font = lowStyle.fontFamily;
71 | textFormat.size = lowStyle.fontSize;
72 | textFormat.color = style.lowColor;
73 |
74 | lowTxt = new TextField();
75 | lowTxt.name = "lowestField";
76 | lowTxt.defaultTextFormat = textFormat;
77 | lowTxt.mouseEnabled = false;
78 | lowTxt.height = style.menuFontSize+2;
79 | addChild(lowTxt);
80 |
81 | highTxt = new TextField();
82 | highTxt.name = "highestField";
83 | highTxt.defaultTextFormat = textFormat;
84 | highTxt.mouseEnabled = false;
85 | highTxt.height = style.menuFontSize+2;
86 | highTxt.y = style.menuFontSize-4;
87 | addChild(highTxt);
88 | //
89 | txtField = makeTF("menuField");
90 | txtField.height = style.menuFontSize+4;
91 | txtField.y = -3;
92 | registerTFRoller(txtField, onMenuRollOver, linkHandler);
93 | registerDragger(txtField); // so that we can still drag from textfield
94 | addChild(txtField);
95 | //
96 | underlay = new Shape();
97 | addChild(underlay);
98 | //
99 | graph = new Shape();
100 | graph.name = "graph";
101 | graph.y = style.menuFontSize;
102 | addChild(graph);
103 | //
104 |
105 | _menuString = "";
110 |
111 | //
112 | init(W,H,true);
113 | }
114 | private function stop():void {
115 | if(_group) console.graphing.remove(_group.name);
116 | }
117 | public function get group():GraphGroup{
118 | return _group;
119 | }
120 | public function reset():void{
121 | _infoMap = {};
122 | graph.graphics.clear();
123 | if(!_group.fixed)
124 | {
125 | _group.low = NaN;
126 | _group.hi = NaN;
127 | }
128 | }
129 | /*public function set showKeyText(b:Boolean):void{
130 | keyTxt.visible = b;
131 | }
132 | public function get showKeyText():Boolean{
133 | return keyTxt.visible;
134 | }
135 | public function set showBoundsText(b:Boolean):void{
136 | lowTxt.visible = b;
137 | highTxt.visible = b;
138 | }
139 | public function get showBoundsText():Boolean{
140 | return lowTxt.visible;
141 | }*/
142 | override public function set height(n:Number):void{
143 | super.height = n;
144 | lowTxt.y = n-style.menuFontSize;
145 | _needRedraw = true;
146 |
147 | var g:Graphics = underlay.graphics;
148 | g.clear();
149 | g.lineStyle(1,style.controlColor, 0.6);
150 | g.moveTo(0, graph.y);
151 | g.lineTo(width-startOffset, graph.y);
152 | g.lineTo(width-startOffset, n);
153 | }
154 | override public function set width(n:Number):void{
155 | super.width = n;
156 | lowTxt.width = n;
157 | highTxt.width = n;
158 | txtField.width = n;
159 | txtField.scrollH = txtField.maxScrollH;
160 | graph.graphics.clear();
161 | _needRedraw = true;
162 | }
163 | //
164 | //
165 | //
166 | public function update(group:GraphGroup, draw:Boolean):void{
167 | _group = group;
168 | var push:int = 1; // 0 = no push, 1 = 1 push, 2 = push all
169 | if(group.idle>0){
170 | push = 0;
171 | if(!_needRedraw) return;
172 | }
173 | if(_needRedraw) draw = true;
174 | _needRedraw = false;
175 | var interests:Array = group.interests;
176 | var W:int = width-startOffset;
177 | var H:int = height-graph.y;
178 | var lowest:Number = group.low;
179 | var highest:Number = group.hi;
180 | var diffGraph:Number = highest-lowest;
181 | var listchanged:Boolean = false;
182 | if(draw) {
183 | TextField(group.inv?highTxt:lowTxt).text = String(group.low);
184 | TextField(group.inv?lowTxt:highTxt).text = String(group.hi);
185 | graph.graphics.clear();
186 | }
187 | var interest:GraphInterest;
188 | for each(interest in interests){
189 | _interest = interest;
190 | var n:String = _interest.key;
191 | var info:Array = _infoMap[n];
192 | if(info == null){
193 | listchanged = true;
194 | // used to use InterestInfo
195 | info = new Array(_interest.col.toString(16), new Array());
196 | _infoMap[n] = info;
197 | }
198 | var history:Array = info[1];
199 | if(push == 1) {
200 | // special case for FPS, because it needs to fill some frames for lagged 1s...
201 | if(group.type == GraphGroup.FPS){
202 | var frames:int = Math.floor(group.hi/_interest.v);
203 | if(frames>30) frames = 30; // Don't add too many lagged frames
204 | while(frames>0){
205 | history.push(_interest.v);
206 | frames--;
207 | }
208 | }else{
209 | history.push(_interest.v);
210 | }
211 | }
212 | var maxLen:int = Math.floor(W)+10;
213 | while(history.length > maxLen)
214 | {
215 | history.shift();
216 | }
217 | if(draw) {
218 | var len:int = history.length;
219 | graph.graphics.lineStyle(1, _interest.col);
220 | var maxi:int = W>len?len:W;
221 | for(var i:int = 1; iH)Y=H;
226 | if(i==1){
227 | graph.graphics.moveTo(width, Y);
228 | }
229 | graph.graphics.lineTo((W-i), Y);
230 | }
231 | if(isNaN(_interest.avg) && diffGraph){
232 | Y = ((_interest.avg-lowest)/diffGraph)*H;
233 | if(!group.inv) Y = H-Y;
234 | if(Y<0)Y=0;
235 | if(Y>H)Y=H;
236 | graph.graphics.lineStyle(1,_interest.col, 0.3);
237 | graph.graphics.moveTo(0, Y);
238 | graph.graphics.lineTo(W, Y);
239 | }
240 | }
241 | }
242 | for(var X:String in _infoMap){
243 | var found:Boolean;
244 | for each(interest in interests){
245 | if(interest.key == X)
246 | {
247 | found = true;
248 | }
249 | }
250 | if(!found){
251 | listchanged = true;
252 | delete _infoMap[X];
253 | }
254 | }
255 | if(draw && (listchanged || _type)) updateKeyText();
256 | }
257 |
258 | public function updateKeyText():void{
259 | var str:String = "";
260 | if(_type){
261 | if(isNaN(_interest.v)){
262 | str += "no input";
263 | }else if(_type == FPS){
264 | str += _interest.avg.toFixed(1);
265 | }else{
266 | str += _interest.v+"mb";
267 | }
268 | }else{
269 | for(var X:String in _infoMap){
270 | str += " "+X+"";
271 | }
272 | str += " |";
273 | }
274 | txtField.htmlText = str+_menuString;
275 | txtField.scrollH = txtField.maxScrollH;
276 | }
277 |
278 |
279 | protected function linkHandler(e:TextEvent):void{
280 | TextField(e.currentTarget).setSelection(0, 0);
281 | if(e.text == "reset"){
282 | reset();
283 | }else if(e.text == "close"){
284 | if(_type == FPS) console.fpsMonitor = false;
285 | else if(_type == MEM) console.memoryMonitor = false;
286 | else stop();
287 | console.panels.removeGraph(_group);
288 | }else if(e.text == "gc"){
289 | console.gc();
290 | }
291 | e.stopPropagation();
292 | }
293 | protected function onMenuRollOver(e:TextEvent):void{
294 | var txt:String = e.text?e.text.replace("event:",""):null;
295 | if(txt == "gc"){
296 | txt = "Garbage collect::Requires debugger version of flash player";
297 | }
298 | console.panels.tooltip(txt, this);
299 | }
300 | }
301 | }
302 | /*
303 | Stopped using this to save 0.5kb! - wow
304 | class InterestInfo{
305 | public var col:Number;
306 | public var history:Array = [];
307 | public function InterestInfo(c:Number){
308 | col = c;
309 | }
310 | }*/
--------------------------------------------------------------------------------
/src/com/junkbyte/console/view/PanelsManager.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.view
26 | {
27 | import com.junkbyte.console.Console;
28 | import com.junkbyte.console.vos.GraphGroup;
29 |
30 | import flash.events.Event;
31 | import flash.geom.Rectangle;
32 | import flash.text.TextField;
33 | import flash.text.TextFieldAutoSize;
34 |
35 | public class PanelsManager{
36 |
37 | private var console:Console;
38 | private var _mainPanel:MainPanel;
39 | private var _ruler:Ruler;
40 |
41 | private var _chsPanel:ChannelsPanel;
42 | private var _fpsPanel:GraphingPanel;
43 | private var _memPanel:GraphingPanel;
44 | private var _graphsMap:Object = {};
45 | private var _graphPlaced:uint = 0;
46 |
47 | private var _tooltipField:TextField;
48 | private var _canDraw:Boolean;
49 |
50 | public function PanelsManager(master:Console) {
51 | console = master;
52 | _mainPanel = new MainPanel(console);
53 | _tooltipField = mainPanel.makeTF("tooltip", true);
54 | _tooltipField.mouseEnabled = false;
55 | _tooltipField.autoSize = TextFieldAutoSize.CENTER;
56 | _tooltipField.multiline = true;
57 | addPanel(_mainPanel);
58 | }
59 | public function addPanel(panel:ConsolePanel):void{
60 | if(console.contains(_tooltipField)){
61 | console.addChildAt(panel, console.getChildIndex(_tooltipField));
62 | }else{
63 | console.addChild(panel);
64 | }
65 | panel.addEventListener(ConsolePanel.DRAGGING_STARTED, onPanelStartDragScale, false,0, true);
66 | panel.addEventListener(ConsolePanel.SCALING_STARTED, onPanelStartDragScale, false,0, true);
67 | }
68 | public function removePanel(n:String):void{
69 | var panel:ConsolePanel = console.getChildByName(n) as ConsolePanel;
70 | if(panel){
71 | // this removes it self from parent. this way each individual panel can clean up before closing.
72 | panel.close();
73 | }
74 | }
75 | public function getPanel(n:String):ConsolePanel{
76 | return console.getChildByName(n) as ConsolePanel;
77 | }
78 | public function get mainPanel():MainPanel{
79 | return _mainPanel;
80 | }
81 | public function panelExists(n:String):Boolean{
82 | return (console.getChildByName(n) as ConsolePanel)?true:false;
83 | }
84 | /**
85 | * Set panel position and size.
86 | *
87 | * See panel names in Console.NAME, FPSPanel.NAME, MemoryPanel.NAME, RollerPanel.NAME, RollerPanel.NAME, etc...
88 | * No effect if panel of that name doesn't exist.
89 | *
90 | * @param Name of panel to set
91 | * @param Rectangle area for panel size and position. Leave any property value zero to keep as is.
92 | * For example, if you don't want to change the height of the panel, pass rect.height = 0;
93 | */
94 | public function setPanelArea(panelname:String, rect:Rectangle):void{
95 | var panel:ConsolePanel = getPanel(panelname);
96 | if(panel){
97 | panel.x = rect.x;
98 | panel.y = rect.y;
99 | if(rect.width) panel.width = rect.width;
100 | if(rect.height) panel.height = rect.height;
101 | }
102 | }
103 | /**
104 | * @private
105 | */
106 | public function updateMenu():void{
107 | _mainPanel.updateMenu();
108 | var chpanel:ChannelsPanel = getPanel(ChannelsPanel.NAME) as ChannelsPanel;
109 | if(chpanel) chpanel.update();
110 | }
111 | /**
112 | * @private
113 | */
114 | public function update(paused:Boolean, lineAdded:Boolean):void{
115 | _canDraw = !paused;
116 | _mainPanel.update(!paused && lineAdded);
117 | if(!paused) {
118 | if(lineAdded && _chsPanel!=null){
119 | _chsPanel.update();
120 | }
121 | }
122 | }
123 | /**
124 | * @private
125 | */
126 | public function updateGraphs(graphs:Array):void{
127 | var usedMap:Object;
128 | var fpsGroup:GraphGroup;
129 | var memGroup:GraphGroup;
130 | _graphPlaced = 0;
131 | for each(var group:GraphGroup in graphs){
132 | if(group.type == GraphGroup.FPS) {
133 | fpsGroup = group;
134 | }else if(group.type == GraphGroup.MEM) {
135 | memGroup = group;
136 | }else{
137 | var n:String = group.name;
138 | var panel:GraphingPanel = _graphsMap[n] as GraphingPanel;
139 | if(!panel){
140 | var rect:Rectangle = group.rect;
141 | if(rect == null) rect = new Rectangle(NaN,NaN, 0, 0);
142 | var size:Number = 100;
143 | if(isNaN(rect.x) || isNaN(rect.y)){
144 | if(_mainPanel.width < 150){
145 | size = 50;
146 | }
147 | var maxX:Number = Math.floor(_mainPanel.width/size)-1;
148 | if(maxX <=1) maxX = 2;
149 | var ix:int = _graphPlaced%maxX;
150 | var iy:int = Math.floor(_graphPlaced/maxX);
151 | rect.x = _mainPanel.x+size+(ix*size);
152 | rect.y = _mainPanel.y+(size*0.6)+(iy*size);
153 | _graphPlaced++;
154 | }
155 | if(rect.width<=0 || isNaN(rect.width)) rect.width = size;
156 | if(rect.height<=0 || isNaN(rect.height)) rect.height = size;
157 | panel = new GraphingPanel(console, rect.width,rect.height);
158 | panel.x = rect.x;
159 | panel.y = rect.y;
160 | panel.name = "graph_"+n;
161 | _graphsMap[n] = panel;
162 | addPanel(panel);
163 | }
164 | if(usedMap == null)
165 | {
166 | usedMap = {};
167 | }
168 | usedMap[n] = true;
169 | panel.update(group, _canDraw);
170 | }
171 | }
172 |
173 | for(var X:String in _graphsMap){
174 | if(usedMap == null || !usedMap[X]){
175 | _graphsMap[X].close();
176 | delete _graphsMap[X];
177 | }
178 | }
179 | //
180 | //
181 | if(fpsGroup != null){
182 | if (_fpsPanel == null) {
183 | _fpsPanel = new GraphingPanel(console, 80 ,40, GraphingPanel.FPS);
184 | _fpsPanel.name = GraphingPanel.FPS;
185 | _fpsPanel.x = _mainPanel.x+_mainPanel.width-160;
186 | _fpsPanel.y = _mainPanel.y+15;
187 | addPanel(_fpsPanel);
188 | _mainPanel.updateMenu();
189 | }
190 | _fpsPanel.update(fpsGroup, _canDraw);
191 | }else if(_fpsPanel!=null){
192 | removePanel(GraphingPanel.FPS);
193 | _fpsPanel = null;
194 | }
195 | //
196 | //
197 | if(memGroup != null){
198 | if(_memPanel == null){
199 | _memPanel = new GraphingPanel(console, 80 ,40, GraphingPanel.MEM);
200 | _memPanel.name = GraphingPanel.MEM;
201 | _memPanel.x = _mainPanel.x+_mainPanel.width-80;
202 | _memPanel.y = _mainPanel.y+15;
203 | addPanel(_memPanel);
204 | _mainPanel.updateMenu();
205 | }
206 | _memPanel.update(memGroup, _canDraw);
207 | }else if(_memPanel!=null){
208 | removePanel(GraphingPanel.MEM);
209 | _memPanel = null;
210 | }
211 | _canDraw = false;
212 | }
213 | /**
214 | * @private
215 | */
216 | public function removeGraph(group:GraphGroup):void
217 | {
218 | if(_fpsPanel && group == _fpsPanel.group){
219 | _fpsPanel.close();
220 | _fpsPanel = null;
221 | }else if(_memPanel && group == _memPanel.group){
222 | _memPanel.close();
223 | _memPanel = null;
224 | }else{
225 | var graph:GraphingPanel = _graphsMap[group.name];
226 | if(graph){
227 | graph.close();
228 | delete _graphsMap[group.name];
229 | }
230 | }
231 | }
232 | //
233 | //
234 | //
235 | /**
236 | * @private
237 | */
238 | public function get displayRoller():Boolean{
239 | return (getPanel(RollerPanel.NAME) as RollerPanel)?true:false;
240 | }
241 | public function set displayRoller(n:Boolean):void{
242 | if(displayRoller != n){
243 | if(n){
244 | if(console.config.displayRollerEnabled){
245 | var roller:RollerPanel = new RollerPanel(console);
246 | roller.x = _mainPanel.x+_mainPanel.width-180;
247 | roller.y = _mainPanel.y+55;
248 | addPanel(roller);
249 | }else{
250 | console.report("Display roller is disabled in config.", 9);
251 | }
252 | }else{
253 | removePanel(RollerPanel.NAME);
254 | }
255 | _mainPanel.updateMenu();
256 | }
257 | }
258 | //
259 | //
260 | //
261 | public function get channelsPanel():Boolean{
262 | return _chsPanel!=null;
263 | }
264 | public function set channelsPanel(b:Boolean):void{
265 | if(channelsPanel != b){
266 | console.logs.cleanChannels();
267 | if(b){
268 | _chsPanel = new ChannelsPanel(console);
269 | _chsPanel.x = _mainPanel.x+_mainPanel.width-332;
270 | _chsPanel.y = _mainPanel.y-2;
271 | addPanel(_chsPanel);
272 | _chsPanel.update();
273 | updateMenu();
274 | }else {
275 | removePanel(ChannelsPanel.NAME);
276 | _chsPanel = null;
277 | }
278 | updateMenu();
279 | }
280 | }
281 | //
282 | //
283 | //
284 | /**
285 | * @private
286 | */
287 | public function get memoryMonitor():Boolean{
288 | return _memPanel!=null;
289 | }
290 | /**
291 | * @private
292 | */
293 | public function get fpsMonitor():Boolean{
294 | return _fpsPanel!=null;
295 | }
296 | //
297 | //
298 | //
299 | /**
300 | * @private
301 | */
302 | public function tooltip(str:String = null, panel:ConsolePanel = null):void{
303 | if(str && !rulerActive){
304 | var split:Array = str.split("::");
305 | str = split[0];
306 | if(split.length > 1) str += "
"+split[1]+"";
307 | console.addChild(_tooltipField);
308 | _tooltipField.wordWrap = false;
309 | _tooltipField.htmlText = ""+str+"";
310 | if(_tooltipField.width>120){
311 | _tooltipField.width = 120;
312 | _tooltipField.wordWrap = true;
313 | }
314 | _tooltipField.x = console.mouseX-(_tooltipField.width/2);
315 | _tooltipField.y = console.mouseY+20;
316 | if(panel){
317 | var txtRect:Rectangle = _tooltipField.getBounds(console);
318 | var panRect:Rectangle = new Rectangle(panel.x,panel.y,panel.width,panel.height);
319 | var doff:Number = txtRect.bottom - panRect.bottom;
320 | if(doff>0){
321 | if((_tooltipField.y - doff)>(console.mouseY+15)){
322 | _tooltipField.y -= doff;
323 | }else if(panRect.y<(console.mouseY-24) && txtRect.y>panRect.bottom){
324 | _tooltipField.y = console.mouseY-_tooltipField.height-15;
325 | }
326 | }
327 | var loff:Number = txtRect.left - panRect.left;
328 | var roff:Number = txtRect.right - panRect.right;
329 | if(loff<0){
330 | _tooltipField.x -= loff;
331 | }else if(roff>0){
332 | _tooltipField.x -= roff;
333 | }
334 | }
335 | }else if(console.contains(_tooltipField)){
336 | console.removeChild(_tooltipField);
337 | }
338 | }
339 | //
340 | //
341 | //
342 | public function startRuler():void{
343 | if(rulerActive){
344 | return;
345 | }
346 | _ruler = new Ruler(console);
347 | _ruler.addEventListener(Event.COMPLETE, onRulerExit, false, 0, true);
348 | console.addChild(_ruler);
349 | _mainPanel.updateMenu();
350 | }
351 | public function get rulerActive():Boolean{
352 | return (_ruler && console.contains(_ruler))?true:false;
353 | }
354 | private function onRulerExit(e:Event):void{
355 | if(_ruler && console.contains(_ruler)){
356 | console.removeChild(_ruler);
357 | }
358 | _ruler = null;
359 | _mainPanel.updateMenu();
360 | }
361 | //
362 | //
363 | //
364 | private function onPanelStartDragScale(e:Event):void{
365 | var target:ConsolePanel = e.currentTarget as ConsolePanel;
366 | if(console.config.style.panelSnapping) {
367 | var X:Array = [0];
368 | var Y:Array = [0];
369 | if(console.stage){
370 | // this will only work if stage size is not changed or top left aligned
371 | X.push(console.stage.stageWidth);
372 | Y.push(console.stage.stageHeight);
373 | }
374 | var numchildren:int = console.numChildren;
375 | for(var i:int = 0;icancel ]";
76 | }else{
77 | txtField.htmlText = ""+getMapString(false)+"";
78 | txtField.autoSize = TextFieldAutoSize.LEFT;
79 | txtField.setSelection(0, 0);
80 | }
81 | width = txtField.width+4;
82 | height = txtField.height;
83 | }
84 | public function getMapString(dolink:Boolean):String{
85 | var stg:Stage = console.stage;
86 | var str:String = "";
87 | if(!dolink){
88 | var key:String = console.rollerCaptureKey?console.rollerCaptureKey.key:"unassigned";
89 | str = " Capture key:
";
90 | }
91 | var p:Point = new Point(stg.mouseX, stg.mouseY);
92 | if(stg.areInaccessibleObjectsUnderPoint(p)){
93 | str += "Inaccessible objects detected
";
94 | }
95 | var objs:Array = stg.getObjectsUnderPoint(p);
96 |
97 | var stepMap:Dictionary = new Dictionary(true);
98 | if(objs.length == 0){
99 | objs.push(stg);// if nothing at least have stage.
100 | }
101 | for each(var child:DisplayObject in objs){
102 | var chain:Array = new Array(child);
103 | var par:DisplayObjectContainer = child.parent;
104 | while(par){
105 | chain.unshift(par);
106 | par = par.parent;
107 | }
108 | var len:uint = chain.length;
109 | for (var i:uint=0; i0;j--){
114 | str += j==1?" ∟":" -";
115 | }
116 |
117 | var n:String = obj.name;
118 | var ind:uint;
119 | if(dolink && console.config.useObjectLinking) {
120 | ind = console.refs.setLogRef(obj);
121 | n = ""+n+" "+console.refs.makeRefTyped(obj);
122 | }
123 | else n = n+" ("+LogReferences.ShortClassName(obj)+")";
124 |
125 | if(obj == stg){
126 | ind = console.refs.setLogRef(stg);
127 | if(ind) str += "Stage ";
128 | else str += "Stage ";
129 | str += "["+stg.mouseX+","+stg.mouseY+"]
";
130 | }else if(i == len-1){
131 | str += ""+n+"
";
132 | }else {
133 | str += ""+n+"
";
134 | }
135 | }
136 | }
137 | }
138 | return str;
139 | }
140 | public override function close():void {
141 | cancelCaptureKeySet();
142 | removeListeners();
143 | super.close();
144 | console.panels.updateMenu(); // should be black boxed :/
145 | }
146 | private function onMenuRollOver(e:TextEvent):void{
147 | var txt:String = e.text?e.text.replace("event:",""):"";
148 | if(txt == "close"){
149 | txt = "Close";
150 | }else if(txt == "capture"){
151 | var key:KeyBind = console.rollerCaptureKey;
152 | if(key){
153 | txt = "Unassign key ::"+key.key;
154 | }else{
155 | txt = "Assign key";
156 | }
157 | }else if(txt == "cancel"){
158 | txt = "Cancel assign key";
159 | }else{
160 | txt = null;
161 | }
162 | console.panels.tooltip(txt, this);
163 | }
164 | protected function linkHandler(e:TextEvent):void{
165 | TextField(e.currentTarget).setSelection(0, 0);
166 | if(e.text == "close"){
167 | close();
168 | }else if(e.text == "capture"){
169 | if(console.rollerCaptureKey){
170 | console.setRollerCaptureKey(null);
171 | }else{
172 | _settingKey = true;
173 | stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, false, 0, true);
174 | }
175 | console.panels.tooltip(null);
176 | }else if(e.text == "cancel"){
177 | cancelCaptureKeySet();
178 | console.panels.tooltip(null);
179 | }
180 | e.stopPropagation();
181 | }
182 | private function cancelCaptureKeySet():void{
183 | _settingKey = false;
184 | if(stage) stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
185 | }
186 | private function keyDownHandler(e:KeyboardEvent):void{
187 | if(!e.charCode) return;
188 | var char:String = String.fromCharCode(e.charCode);
189 | cancelCaptureKeySet();
190 | console.setRollerCaptureKey(char, e.shiftKey, e.ctrlKey, e.altKey);
191 | console.panels.tooltip(null);
192 | }
193 | }
194 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/view/Ruler.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.view {
26 | import flash.geom.Matrix;
27 | import flash.display.BitmapData;
28 | import flash.display.Bitmap;
29 | import com.junkbyte.console.ConsoleConfig;
30 | import com.junkbyte.console.ConsoleStyle;
31 | import com.junkbyte.console.Console;
32 |
33 | import flash.display.BlendMode;
34 | import flash.display.Graphics;
35 | import flash.display.Shape;
36 | import flash.display.Sprite;
37 | import flash.events.Event;
38 | import flash.events.MouseEvent;
39 | import flash.geom.Point;
40 | import flash.geom.Rectangle;
41 | import flash.text.TextField;
42 | import flash.text.TextFieldAutoSize;
43 | import flash.text.TextFormat;
44 | import flash.text.TextFormatAlign;
45 | import flash.ui.Mouse;
46 |
47 | /**
48 | * @private
49 | */
50 | public class Ruler extends Sprite{
51 |
52 | private var _master:Console;
53 | private var _config : ConsoleConfig;
54 |
55 | private var _area:Rectangle;
56 | private var _pointer:Shape;
57 |
58 | private var _posTxt:TextField;
59 | private var _zoom:Bitmap;
60 |
61 | private var _points:Array;
62 |
63 | public function Ruler(console:Console) {
64 | _master = console;
65 | _config = console.config;
66 | buttonMode = true;
67 | _points = new Array();
68 | _pointer = new Shape();
69 | addChild(_pointer);
70 | var p:Point = new Point();
71 | p = globalToLocal(p);
72 | _area = new Rectangle(-console.stage.stageWidth*1.5+p.x, -console.stage.stageHeight*1.5+p.y, console.stage.stageWidth*3, console.stage.stageHeight*3);
73 | graphics.beginFill(_config.style.backgroundColor, 0.2);
74 | graphics.drawRect(_area.x, _area.y, _area.width, _area.height);
75 | graphics.endFill();
76 | //
77 | _posTxt = _master.panels.mainPanel.makeTF("positionText", true);
78 | _posTxt.autoSize = TextFieldAutoSize.LEFT;
79 | addChild(_posTxt);
80 | //
81 | _zoom = new Bitmap();
82 | _zoom.scaleY = _zoom.scaleX = 2;
83 | addChild(_zoom);
84 | //
85 | addEventListener(MouseEvent.CLICK, onMouseClick, false, 0, true);
86 | addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove, false, 0, true);
87 | onMouseMove();
88 | if(_config.rulerHidesMouse) Mouse.hide();
89 | _master.report("Ruler started. Click on two locations to measure.", -1);
90 | }
91 | private function onMouseMove(e:MouseEvent = null):void{
92 | _pointer.graphics.clear();
93 | _pointer.graphics.lineStyle(1, 0xAACC00, 1);
94 | _pointer.graphics.moveTo(_area.x, mouseY);
95 | _pointer.graphics.lineTo(_area.x+_area.width, mouseY);
96 | _pointer.graphics.moveTo(mouseX, _area.y);
97 | _pointer.graphics.lineTo(mouseX, _area.y+_area.height);
98 | _pointer.blendMode = BlendMode.INVERT;
99 | _posTxt.text = ""+mouseX+","+mouseY+"";
100 | //
101 | var bmd:BitmapData = new BitmapData(30, 30);
102 | try{
103 | var m:Matrix = new Matrix();
104 | m.tx = -stage.mouseX+15;
105 | m.ty = -stage.mouseY+15;
106 | bmd.draw(stage, m);
107 | }catch(err:Error){
108 | bmd = null;
109 | }
110 | _zoom.bitmapData = bmd;
111 | //
112 | var d:int = 10;
113 | _posTxt.x = mouseX-_posTxt.width-d;
114 | _posTxt.y = mouseY-_posTxt.height-d;
115 | _zoom.x = _posTxt.x+_posTxt.width-_zoom.width;
116 | _zoom.y = _posTxt.y-_zoom.height;
117 | if(_posTxt.x < 16){
118 | _posTxt.x = mouseX+d;
119 | _zoom.x = _posTxt.x;
120 | }
121 | if(_posTxt.y < 38){
122 | _posTxt.y = mouseY+d;
123 | _zoom.y = _posTxt.y+_posTxt.height;
124 | }
125 | }
126 | private function onMouseClick(e:MouseEvent):void{
127 | e.stopPropagation();
128 | var p:Point;
129 | var style : ConsoleStyle = _config.style;
130 | if(_points.length==0){
131 | p = new Point(e.localX, e.localY);
132 | graphics.lineStyle(1, 0xFF0000);
133 | graphics.drawCircle(p.x, p.y, 3);
134 | _points.push(p);
135 | }else if(_points.length==1){
136 | _zoom.bitmapData = null;
137 | if(_config.rulerHidesMouse) Mouse.show();
138 | removeChild(_pointer);
139 | removeChild(_posTxt);
140 | removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
141 | p = _points[0];
142 | var p2:Point = new Point(e.localX, e.localY);
143 | _points.push(p2);
144 | graphics.clear();
145 | graphics.beginFill(style.backgroundColor, 0.4);
146 | graphics.drawRect(_area.x, _area.y, _area.width, _area.height);
147 | graphics.endFill();
148 | graphics.lineStyle(1.5, 0xFF0000);
149 | graphics.drawCircle(p.x, p.y, 4);
150 | graphics.lineStyle(1.5, 0xFF9900);
151 | graphics.drawCircle(p2.x, p2.y, 4);
152 | var mp:Point = Point.interpolate(p, p2, 0.5);
153 | graphics.lineStyle(1, 0xAAAAAA);
154 | graphics.drawCircle(mp.x, mp.y, 4);
155 | //
156 | var xmin:Point = p;
157 | var xmax:Point = p2;
158 | if(p.x>p2.x){
159 | xmin = p2;
160 | xmax = p;
161 | }
162 | var ymin:Point = p;
163 | var ymax:Point = p2;
164 | if(p.y>p2.y){
165 | ymin = p2;
166 | ymax = p;
167 | }
168 | //
169 | var w:Number = xmax.x-xmin.x;
170 | var h:Number = ymax.y-ymin.y;
171 | var d:Number = Point.distance(p, p2);
172 | //
173 | var txt:TextField = makeTxtField(style.highColor);
174 | txt.text = round(p.x)+","+ round(p.y);
175 | txt.x = p.x;
176 | txt.y = p.y-(ymin==p?14:0);
177 | addChild(txt);
178 | //
179 | txt = makeTxtField(style.highColor);
180 | txt.text = round(p2.x)+","+ round(p2.y);
181 | txt.x = p2.x;
182 | txt.y = p2.y-(ymin==p2?14:0);;
183 | addChild(txt);
184 | //
185 | if(w>40 || h>25){
186 | txt = makeTxtField(style.lowColor);
187 | txt.text = round(mp.x)+","+ round(mp.y);
188 | txt.x = mp.x;
189 | txt.y = mp.y;
190 | addChild(txt);
191 | }
192 | //
193 | graphics.lineStyle(1, 0xAACC00, 0.5);
194 | graphics.moveTo(_area.x, ymin.y);
195 | graphics.lineTo(_area.x+_area.width, ymin.y);
196 | graphics.moveTo(_area.x, ymax.y);
197 | graphics.lineTo(_area.x+_area.width, ymax.y);
198 | graphics.moveTo(xmin.x, _area.y);
199 | graphics.lineTo(xmin.x, _area.y+_area.height);
200 | graphics.moveTo(xmax.x, _area.y);
201 | graphics.lineTo(xmax.x, _area.y+_area.height);
202 | //
203 | var a1:Number = round(angle(p,p2),100);
204 | var a2:Number = round(angle(p2,p),100);
205 | graphics.lineStyle(1, 0xAA0000, 0.8);
206 | drawCircleSegment(graphics, 10,p, a1, -90);
207 | graphics.lineStyle(1, 0xCC8800, 0.8);
208 | drawCircleSegment(graphics, 10,p2, a2, -90);
209 | //
210 | graphics.lineStyle(2, 0x00FF00, 0.7);
211 | graphics.moveTo(p.x, p.y);
212 | graphics.lineTo(p2.x, p2.y);
213 | //
214 | _master.report("Ruler results: (red) ["+p.x+","+p.y+"] to (orange) ["+p2.x+","+p2.y+"]", -2);
215 | _master.report("Distance: "+round(d,100) +"", -2);
216 | _master.report("Mid point: ["+mp.x+","+mp.y+"]", -2);
217 | _master.report("Width:"+w+", Height: "+h+"", -2);
218 | _master.report("Angle from first point (red): "+a1+"°", -2);
219 | _master.report("Angle from second point (orange): "+a2+"°", -2);
220 | }else{
221 | exit();
222 | }
223 | }
224 | public function exit():void{
225 | _master = null;
226 | dispatchEvent(new Event(Event.COMPLETE));
227 | }
228 | private function makeTxtField(col:Number, b:Boolean = true):TextField{
229 | var format:TextFormat = new TextFormat(_config.style.menuFont, _config.style.menuFontSize, col, b, true, null, null, TextFormatAlign.RIGHT);
230 | var txt:TextField = new TextField();
231 | txt.autoSize = TextFieldAutoSize.RIGHT;
232 | txt.selectable = false;
233 | txt.defaultTextFormat = format;
234 | return txt;
235 | }
236 |
237 |
238 | private function round(n:Number, d:uint = 10):Number{
239 | return Math.round(n*d)/d;
240 | }
241 | private function angle(srcP:Point, point:Point):Number {
242 | var a:Number = Math.atan2(point.y - srcP.y , point.x - srcP.x)/Math.PI * 180;
243 | a +=90;
244 | if(a>180) a -= 360;
245 | return a;
246 | }
247 | private function drawCircleSegment(g : Graphics,radius :Number,pos:Point, deg:Number = 180, startDeg:Number = 0):Point
248 | {
249 | var reversed:Boolean = false;
250 | if(deg<0){
251 | reversed = true;
252 | deg = Math.abs(deg);
253 | }
254 | var rad:Number = (deg*Math.PI)/180;
255 | var rad2:Number = (startDeg*Math.PI)/180;
256 | var p:Point = getPointOnCircle(radius, rad2);
257 | p.offset(pos.x,pos.y);
258 | g.moveTo(p.x,p.y);
259 | var pra:Number = 0;
260 | for (var i:int = 1; i<=(rad+1); i++) {
261 | var ra:Number = i<=rad?i:rad;
262 | var diffr:Number = ra-pra;
263 | var offr:Number = 1+(0.12*diffr*diffr);
264 | var ap:Point = getPointOnCircle(radius*offr, ((ra-(diffr/2))*(reversed?-1:1))+rad2);
265 | ap.offset(pos.x,pos.y);
266 | p = getPointOnCircle(radius, (ra*(reversed?-1:1))+rad2);
267 | p.offset(pos.x,pos.y);
268 | g.curveTo(ap.x,ap.y, p.x,p.y);
269 | pra = ra;
270 | }
271 | return p;
272 | }
273 | private function getPointOnCircle(radius:Number, rad:Number):Point {
274 | return new Point(radius * Math.cos(rad),radius * Math.sin(rad));
275 | }
276 |
277 |
278 |
279 | }
280 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/vos/GraphGroup.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.vos {
26 | import flash.utils.ByteArray;
27 | import flash.geom.Rectangle;
28 |
29 | /**
30 | * @private
31 | */
32 | public class GraphGroup {
33 |
34 | public static const FPS:uint = 1;
35 | public static const MEM:uint = 2;
36 |
37 | public var type:uint;
38 | public var name:String;
39 | public var freq:int = 1; // update every n number of frames.
40 | public var low:Number;
41 | public var hi:Number;
42 | public var fixed:Boolean;
43 | public var averaging:uint;
44 | public var inv:Boolean;
45 | public var interests:Array = [];
46 | public var rect:Rectangle;
47 | //
48 | //
49 | public var idle:int;
50 |
51 | public function GraphGroup(n:String){
52 | name = n;
53 | }
54 | public function updateMinMax(v:Number):void{
55 | if(!isNaN(v) && !fixed){
56 | if(isNaN(low)) {
57 | low = v;
58 | hi = v;
59 | }
60 | if(v > hi) hi = v;
61 | if(v < low) low = v;
62 | }
63 | }
64 | //
65 | //
66 | //
67 | public function toBytes(bytes:ByteArray):void{
68 | bytes.writeUTF(name);
69 | bytes.writeUnsignedInt(type);
70 | bytes.writeUnsignedInt(idle);
71 | bytes.writeDouble(low);
72 | bytes.writeDouble(hi);
73 | bytes.writeBoolean(inv);
74 | bytes.writeUnsignedInt(interests.length);
75 | for each(var gi:GraphInterest in interests) gi.toBytes(bytes);
76 | }
77 | public static function FromBytes(bytes:ByteArray):GraphGroup{
78 | var g:GraphGroup = new GraphGroup(bytes.readUTF());
79 | g.type = bytes.readUnsignedInt();
80 | g.idle = bytes.readUnsignedInt();
81 | g.low = bytes.readDouble();
82 | g.hi = bytes.readDouble();
83 | g.inv = bytes.readBoolean();
84 | var len:uint = bytes.readUnsignedInt();
85 | while(len){
86 | g.interests.push(GraphInterest.FromBytes(bytes));
87 | len--;
88 | }
89 | return g;
90 | }
91 | }
92 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/vos/GraphInterest.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */package com.junkbyte.console.vos {
25 | import flash.utils.ByteArray;
26 | import com.junkbyte.console.core.Executer;
27 | import com.junkbyte.console.vos.WeakRef;
28 |
29 | /**
30 | * @private
31 | */
32 | public class GraphInterest {
33 |
34 | private var _ref:WeakRef;
35 | public var _prop:String;
36 | private var useExec:Boolean;
37 | public var key:String;
38 | public var col:Number;
39 | public var v:Number;
40 | public var avg:Number;
41 |
42 | public function GraphInterest(keystr:String ="", color:Number = 0):void{
43 | col = color;
44 | key = keystr;
45 | }
46 | public function setObject(object:Object, property:String):Number{
47 | _ref = new WeakRef(object);
48 | _prop = property;
49 | useExec = _prop.search(/[^\w\d]/) >= 0;
50 | //
51 | v = getCurrentValue();
52 | avg = v;
53 | return v;
54 | }
55 | public function get obj():Object{
56 | return _ref!=null?_ref.reference:undefined;
57 | }
58 | public function get prop():String{
59 | return _prop;
60 | }
61 | //
62 | //
63 | //
64 | public function getCurrentValue():Number{
65 | return useExec?Executer.Exec(obj, _prop):obj[_prop];
66 | }
67 | public function setValue(val:Number, averaging:uint = 0):void{
68 | v = val;
69 | if(averaging>0)
70 | {
71 | if(isNaN(avg))
72 | {
73 | avg = v;
74 | }
75 | else
76 | {
77 | avg += ((v-avg)/averaging);
78 | }
79 | }
80 | }
81 | //
82 | //
83 | //
84 | public function toBytes(bytes:ByteArray):void{
85 | bytes.writeUTF(key);
86 | bytes.writeUnsignedInt(col);
87 | bytes.writeDouble(v);
88 | bytes.writeDouble(avg);
89 | }
90 | public static function FromBytes(bytes:ByteArray):GraphInterest{
91 | var interest:GraphInterest = new GraphInterest(bytes.readUTF(), bytes.readUnsignedInt());
92 | interest.v = bytes.readDouble();
93 | interest.avg = bytes.readDouble();
94 | return interest;
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/com/junkbyte/console/vos/Log.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.vos {
26 | import flash.utils.ByteArray;
27 |
28 | /**
29 | * @private
30 | */
31 | public class Log{
32 | public var line:uint;
33 | public var text:String;
34 | public var ch:String;
35 | public var priority:int;
36 | public var repeat:Boolean;
37 | public var html:Boolean;
38 | public var time:uint;
39 | //public var stack:String;
40 |
41 | public var timeStr:String;
42 | public var lineStr:String;
43 | public var chStr:String;
44 | //
45 | public var next:Log;
46 | public var prev:Log;
47 | //
48 | public function Log(txt:String, cc:String, pp:int, repeating:Boolean = false, ishtml:Boolean = false){
49 | text = txt;
50 | ch = cc;
51 | priority = pp;
52 | repeat = repeating;
53 | html = ishtml;
54 | }
55 | public function toBytes(bytes:ByteArray):void{
56 | var t:ByteArray = new ByteArray();
57 | t.writeUTFBytes(text);// because writeUTF can't accept more than 65535
58 | bytes.writeUnsignedInt(t.length);
59 | bytes.writeBytes(t);
60 | bytes.writeUTF(ch);
61 | bytes.writeInt(priority);
62 | bytes.writeBoolean(repeat);
63 | }
64 | public static function FromBytes(bytes:ByteArray):Log{
65 | var t:String = bytes.readUTFBytes(bytes.readUnsignedInt());
66 | var c:String = bytes.readUTF();
67 | var p:int = bytes.readInt();
68 | var r:Boolean = bytes.readBoolean();
69 | return new Log(t, c, p, r, true);
70 | }
71 |
72 | public function plainText():String{
73 | return text.replace(/<.*?>/g, "").replace(/</g, "<").replace(/>/g, ">");
74 | }
75 | public function toString():String{
76 | return "["+ch+"] " + plainText();
77 | }
78 |
79 | public function clone():Log{
80 | var l:Log = new Log(text, ch, priority, repeat, html);
81 | l.line = line;
82 | l.time = time;
83 | //l.stack = stack;
84 | return l;
85 | }
86 | }
87 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/vos/WeakObject.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.vos {
26 | import flash.utils.Proxy;
27 | import flash.utils.flash_proxy;
28 |
29 | /**
30 | * @private
31 | */
32 | public dynamic class WeakObject extends Proxy{
33 |
34 | private var _item:Array;
35 | private var _dir:Object;
36 |
37 | public function WeakObject() {
38 | _dir = new Object();
39 | }
40 | public function set(n:String, obj:Object, strong:Boolean = false):void{
41 | if(obj == null) delete _dir[n];
42 | else _dir[n] = new WeakRef(obj, strong);
43 | }
44 | public function get(n:String):*{
45 | var ref:WeakRef = getWeakRef(n);
46 | return ref?ref.reference:undefined;
47 | }
48 | public function getWeakRef(n:String):WeakRef{
49 | return _dir[n] as WeakRef;
50 | }
51 | //
52 | // PROXY
53 | //
54 | override flash_proxy function getProperty(n:*):* {
55 | return get(n);
56 | }
57 | override flash_proxy function callProperty(n:*, ... rest):* {
58 | var o:Object = get(n);
59 | return o.apply(this, rest);
60 | }
61 | override flash_proxy function setProperty(n:*, v:*):void {
62 | set(n,v);
63 | }
64 | override flash_proxy function nextName(index:int):String {
65 | return _item[index - 1];
66 | }
67 | override flash_proxy function nextValue(index:int):* {
68 | return this[flash_proxy::nextName(index)];
69 | }
70 | override flash_proxy function nextNameIndex (index:int):int {
71 | if (index == 0) {
72 | _item = new Array();
73 | for (var x:* in _dir) {
74 | _item.push(x);
75 | }
76 | }
77 | if (index < _item.length) {
78 | return index + 1;
79 | } else {
80 | return 0;
81 | }
82 | }
83 | override flash_proxy function deleteProperty(name:*):Boolean {
84 | return delete _dir[name];
85 | }
86 | public function toString():String{
87 | return "[WeakObject]";
88 | }
89 | }
90 | }
--------------------------------------------------------------------------------
/src/com/junkbyte/console/vos/WeakRef.as:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (c) 2008-2010 Lu Aye Oo
4 | *
5 | * @author Lu Aye Oo
6 | *
7 | * http://code.google.com/p/flash-console/
8 | *
9 | *
10 | * This software is provided 'as-is', without any express or implied
11 | * warranty. In no event will the authors be held liable for any damages
12 | * arising from the use of this software.
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | * 1. The origin of this software must not be misrepresented; you must not
17 | * claim that you wrote the original software. If you use this software
18 | * in a product, an acknowledgment in the product documentation would be
19 | * appreciated but is not required.
20 | * 2. Altered source versions must be plainly marked as such, and must not be
21 | * misrepresented as being the original software.
22 | * 3. This notice may not be removed or altered from any source distribution.
23 | *
24 | */
25 | package com.junkbyte.console.vos {
26 | import flash.utils.Dictionary;
27 |
28 | /**
29 | * @private
30 | */
31 | public class WeakRef{
32 |
33 | private var _val:*;
34 | private var _strong:Boolean; // strong flag
35 |
36 | // Known issue: storing a function reference that's on timeline don't seem to work on next frame. fix = manually store as strong ref.
37 | // There is abilty to use strong reference incase you need to mix -
38 | // weak and strong references together somewhere
39 | public function WeakRef(ref:*, strong:Boolean = false) {
40 | _strong = strong;
41 | reference = ref;
42 | }
43 |
44 | public function get reference():*{
45 | if(_strong){
46 | return _val;
47 | }else{
48 | //there should be only 1 key in it anyway
49 | for(var X:* in _val){
50 | return X;
51 | }
52 | }
53 | return null;
54 | }
55 | public function set reference(ref:*):void{
56 | if(_strong){
57 | _val = ref;
58 | }else{
59 | _val = new Dictionary(true);
60 | _val[ref] = null;
61 | }
62 | }
63 |
64 | public function get strong():Boolean{
65 | return _strong;
66 | }
67 | /*
68 | // Removed to save compile size
69 | public function set strong(b:Boolean):void{
70 | if(_strong != b){
71 | var ref:* = reference;
72 | _strong = b;
73 | reference = ref;
74 | }
75 | }*/
76 | }
77 | }
--------------------------------------------------------------------------------