下載:含原始碼及執行檔的壓縮檔。
ZDebugger
package lin.shinder.mdmzinc { import fl.controls.Button; import fl.controls.ComboBox; import fl.controls.TextArea; import fl.data.DataProvider; import flash.display.SimpleButton; import flash.display.Sprite; import flash.display.Stage; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.events.MouseEvent; import flash.net.LocalConnection; import flash.text.TextField; import flash.text.TextFormat; import mdm.*; /** * @author shinder.lin@gmail.com * @date 2010/06 */ public class ZDebugger extends Sprite { public var info_txt:TextArea; public var clear_btn:Button; public var close_btn:Button; public var size_cb:ComboBox; private var localConnection:LocalConnection; private var textField:TextField; private var myStage:Stage; public function ZDebugger() { mdm.Application.init( this, mdmInit ); } private function mdmInit():void { myStage = this.stage; myStage.scaleMode = StageScaleMode.NO_SCALE; myStage.align = StageAlign.TOP_LEFT; myStage.addEventListener(Event.RESIZE, stageResized); textField = info_txt.textField as TextField; info_txt.setStyle("textFormat", new TextFormat("Arial", 16) ); size_cb.dataProvider = new DataProvider([16, 20, 24, 30, 36, 48, 60]); clear_btn.addEventListener(MouseEvent.CLICK, clear); close_btn.addEventListener(MouseEvent.CLICK, close); size_cb.addEventListener(Event.CHANGE, changeFontFormat); localConnection = new LocalConnection(); localConnection.client = this; textField.text = "Please use this debugger console with [lin.shinder.mdmzinc.ZTracer]\n"; textField.appendText("ex: ZTracer.print( YOUR_MESSAGE )\n"); try { localConnection.connect("ZDebugger"); } catch (error:ArgumentError) { textField.appendText("Can't connect...the connection name 'ZDebugger' is already used by another SWF\n"); } } private function stageResized(event:Event):void { info_txt.width = stage.stageWidth; info_txt.height = stage.stageHeight - info_txt.y; close_btn.x = stage.stageWidth - close_btn.width; } public function print(msg:String):void { textField.appendText(msg +"\n"); info_txt.verticalScrollPosition = info_txt.maxVerticalScrollPosition; info_txt.validateNow(); } public function clear(event:Event=null):void { textField.text = ''; } private function changeFontFormat(event:Event=null):void { var font:String = "Arial"; var size:int = int(size_cb.value); info_txt.setStyle("textFormat", new TextFormat(font, size) ); } private function close(event:MouseEvent):void { var result = mdm.Dialogs.promptModal("Are you sure to close ZDebugger?", "yesno", "alert"); if (result) { mdm.Application.exit(); } } } }ZTracer
package lin.shinder.mdmzinc { import flash.net.LocalConnection; /** * @author shinder.lin@gmail.com * @date 2010/06 */ public class ZTracer { private static var localConnection:LocalConnection; public static function print(msg:String):void { if (! localConnection) { localConnection = new LocalConnection(); } trace(msg); localConnection.send("ZDebugger", "print", msg); } } }Sqlite: 在 MDM Zinc 中, 替 SQLite 除錯的工具
package lin.shinder.mdmzinc { import mdm.*; /** * @author shinder.lin@gmail.com * @date 2010/06 */ public class Sqlite { public static function fetchAssoc(query:String, tableName:String):Array { var i:int, k:int; var data:Array; var obj:Object; var returnData:Array = []; var columnNamesQuery:String = "PRAGMA table_info(" + tableName + ")"; mdm.Database.SQLite.runQuery( columnNamesQuery ); traceError("columnNamesQuery"); var columnNames:Array = []; data = mdm.Database.SQLite.getData(); for (i = 0; i < data.length; i++) { columnNames.push( data[i][1] ); } mdm.Database.SQLite.runQuery( query ); traceError("runQuery"); data = mdm.Database.SQLite.getData(); for (i = 0; i < data.length; i++) { obj = { }; for (k=0; k < data[i].length; k++) { obj[ columnNames[k] ] = data[i][k]; } returnData.push( obj ); } return returnData; } public static function traceError(msg:String=""):void { if ( mdm.Database.SQLite.error() ) { ZTracer.instance.print( msg + ":" + mdm.Database.SQLite.errorDetails() ); } } } }
1 則留言:
許多年前就有人做過, 但自己要用時, 卻想自己弄一個...
張貼留言