In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

オンラインtrace

//////////////////////////////////////////
wonderfl用traceクラス
safariだと新しいwindowがパカパカ開く
ウザイ
コード作成中も実行可能
参考
http://barmamutha.net/?p=212
http://wonderfl.net/c/j7MQ
//////////////////////////////////////////
Get Adobe Flash player
by barmamutha 04 Jun 2010
/**
 * Copyright barmamutha ( http://wonderfl.net/user/barmamutha )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nGUp
 */

////////////////////////////////////////////
//
//wonderfl用traceクラス
//safariだと新しいwindowがパカパカ開く
//ウザイ
//コード作成中も実行可能
//
//参考
//http://barmamutha.net/?p=212
//http://wonderfl.net/c/j7MQ
//
////////////////////////////////////////////
package {
    import flash.display.Sprite;

    public class LC extends Sprite {
        private var tr: OnlineTrace;
        public function LC() {
			tr = new OnlineTrace("myConnect");

			 //trace用に別ウインドウを開く
			tr.open();

			//trace String
			tr.send("hoge");
			
			//trace 計算式
			tr.send(1+1);
			
			//trace 演算
			var a:uint = 1;
			tr.send(a==1);
			
			//trace Array
			var ar:Array = new Array("1","2","3");
			tr.send(ar);
			
			//trace Object
			var sp:Sprite = new Sprite();
			tr.send(sp);

			tr.send(LC);
		}
    }
}


////////////////////////////////////////////
//
//trace用クラス
//
////////////////////////////////////////////
import jp.nium.utils.ArrayUtil;
import jp.nium.utils.ClassUtil;
import jp.nium.utils.ObjectUtil;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.net.LocalConnection;
import flash.events.StatusEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.system.Security;
class OnlineTrace {
	private var _connect:LocalConnection;
	private var _id:String;
	private var _url:String;
	
	public function get message():* { return _message; }
	public function set message( value:* ):void { _message = value; }
	private var _message:*;
	private var _sendMessage:Array = new Array();
	private var _sendCount:uint = 0;
	private var myTimer:Timer = new Timer(1000, 1);
	private var _connected = false;
	private var _opened = false;
	
	public function OnlineTrace(id:String) {
		_id = "barmamutha.net:" + id;
		_url = "http://barmamutha.net/swf/tracewindow.html?" + id;
		_connect = new LocalConnection();
		_connect.addEventListener(StatusEvent.STATUS,function(event:StatusEvent):void {
			switch (event.level) {
				case "status":
					//接続(ウインドウが開いたか)チェック
					!_connected ? _connected = true : null ;
					break;
				case "error":
					//_trace()
					break;
				case "warning":
					break;
			}
		});
		myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, _trace);
		
	}
	public function open() {
		navigateToURL(new URLRequest(_url), "newwin");
		_opened = true;
	}
	public function send(message:*) {
		this.message = message;
		switch ( true ) {
			case _message is Function								: { setMessage( _message.apply( this ) ); break; }
			case _message is Array									: { setMessage( ArrayUtil.toString( _message as Array ) ); break; }
			case ClassUtil.getClassName( _message ) == "Object"		: { setMessage( ObjectUtil.toString( _message as Object ) ); break; }
			default													: { setMessage( _message ); }
		}
	}
	private function setMessage(message:String):void {
		//trace(message)
		_sendMessage.push(message);
		_trace();
	}
	private function _trace(e:*=null):void {
        myTimer.stop(); 
		if(_connected && _opened){
			while(_sendCount < _sendMessage.length){
				_connect.send(_id, "makeCircle", _sendMessage[_sendCount]);
				_sendCount++;
			}
		}else {
			_connect.send(_id,"connectCheck");
			reTry()
		}
	}
	private function reTry():void {
            //ウインドウオープン時のタイムラグがあるので何度かトライする
            myTimer.start(); 
	}
}