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

掲示板的ななにか

MySQLでなにか作ってみたかったのでとりあえず。
* 
* phpからは書き込みがあると古いのから削除している。
* 最新20数件しかMySQLには保持していない。
* なんかトラブルあってもいやだからとりあえず。
*
Get Adobe Flash player
by umhr 28 Jun 2010
    Embed
/**
 * Copyright umhr ( http://wonderfl.net/user/umhr )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/i6eA
 */

/*
 * MySQLでなにか作ってみたかったのでとりあえず。
 * 
 * phpからは書き込みがあると古いのから削除している。
 * 最新20数件しかMySQLには保持していない。
 * なんかトラブルあってもいやだからとりあえず。
 * */
package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLVariables;
    import flash.net.URLRequestMethod;
    import flash.text.TextField;
    
    import com.adobe.serialization.json.JSON;
    import com.bit101.components.PushButton;
    /**
     * ...
     * @author umhr
     */
    public class Main extends Sprite 
    {
        private var _tf:TextField;
        private var _input:TextField;
        public function Main():void 
        {
            //入力エリア
            _input = new TextField();
            _input.width = 350;
            _input.height = 18;
            _input.type = "input";
            _input.border = true;
            this.addChild(_input);
            
            //書き込みボタン
            new PushButton(this, 365, 0, "write", write);
            
            //出力エリア
            _tf = new TextField();
            _tf.y = 20;
            _tf.width = 465;
            _tf.height = 455;
            _tf.wordWrap = true;
            this.addChild(_tf);
            write(null);
        }
        
        public function write(event:Event):void
        {
            var myURLLoader:URLLoader = new URLLoader();
            myURLLoader.addEventListener (Event.COMPLETE, onComp);
            var request:URLRequest = new URLRequest("http://mztm.heteml.jp/umhr/mysql/bridge.php5");
            request.method = URLRequestMethod.POST;
            if(_input.text){
                var variables:URLVariables = new URLVariables();
                variables.title = _input.text;
                request.data = variables;
                _input.text = "";
            }
            myURLLoader.load(request);
        }
        
        private function onComp(event:Event = null):void 
        {
            event.target.removeEventListener(Event.COMPLETE, onComp);
            
            var obj:Object = JSON.decode(event.target.data);
            //Utils.dump(obj);
            
            var str:String = "";
            var n:int = obj.length;
            for (var i:int = 0; i < n; i++) {
                str += obj[i].id + ":";
                str += obj[i].text + ":";
                str += obj[i].timestamp;
                str += "\n";
            }            
            
            _tf.text = str;
        }
    }
}

    //Dump
    import flash.utils.getQualifiedClassName;
    
    class Utils {
        public function Utils():void { };
        //shuffle
        static public function shuffle(num:int):Array {
            var _array:Array = new Array();
            for (var i:int = 0; i < num; i++) {    
                _array[i] = Math.random();
            }
            return _array.sort(Array.RETURNINDEXEDARRAY);
        }
        //Dump
        static public function dump(obj:Object, isTrace:Boolean = true):String {
            var str:String = returnDump(obj)
            if (isTrace) {
                trace(str);
            }
            return str;
        }
        static public function returnDump(obj:Object):String {
            var str:String = _dump(obj);
            if (str.length == 0) {
                str = String(obj);
            }else if (getQualifiedClassName(obj) == "Array") {
                str = "[\n" + str.slice( 0, -2 ) + "\n]";
            }else {
                str = "{\n" + str.slice( 0, -2 ) + "\n}";
            }
            return str;
        }
        
        static public function traceDump(obj:Object):void {
            trace(returnDump(obj));
        }
        
        static private function _dump(obj:Object, indent:int = 0):String {
            var result:String = "";
            
            var da:String = (getQualifiedClassName(obj) == "Array")?'':'"';
            
            var tab:String = "";
            for ( var i:int = 0; i < indent; ++i ) {
                tab += "    ";
            }
            
            for (var key:String in obj) {
                if (typeof obj[key] == "object") {
                    var type:String = getQualifiedClassName(obj[key]);
                    if (type == "Object" || type == "Array") {
                        result += tab + da + key + da + ":"+((type == "Array")?"[":"{");
                        var dump_str:String = _dump(obj[key], indent + 1);
                        if (dump_str.length > 0) {
                            result += "\n" + dump_str.slice(0, -2) + "\n";
                            result += tab;
                        }
                        result += (type == "Array")?"],\n":"},\n";
                    }else {
                        result += tab + '"' + key + '":<' + type + ">,\n";
                    }
                }else if (typeof obj[key] == "function") {
                    result += tab + '"' + key + '":<Function>,\n';
                }else {
                    var dd:String = (typeof obj[key] == "string")?"'":"";
                    result += tab + da + key + da + ":" + dd + obj[key] +dd + ",\n";
                }
            }            
            return result;
        }
    }