flash on 2013-1-23

by ohisama
import com.adobe.serialization.json.*;
♥0 | Line 66 | Modified 2013-01-23 19:59:36 | MIT License
play

ActionScript3 source code

/**
 * Copyright ohisama ( http://wonderfl.net/user/ohisama )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/dxNF
 */

package
{
    import flash.display.*;
    import flash.events.*;
    import flash.xml.*;
    import flash.net.*;
    import flash.text.*;
    import flash.utils.escapeMultiByte;
    import com.adobe.serialization.json.JSON;
    import flash.system.Security;
    public class test8 extends MovieClip
    {
        private var loader : URLLoader = new URLLoader();
        public function test8() : void 
        {
            Wonderfl.capture(stage);
            //Security.allowDomain("*");
            Security.loadPolicyFile("http://photos.googleapis.com/data/crossdomain.xml");
            loader.load(new URLRequest("http://photos.googleapis.com/data/feed/base/all?alt=json&kind=photo&q=waterdrop&imglic=commercial&max-results=3&imgmax=288"));
            loader.addEventListener(Event.COMPLETE, loadComplete);
            loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, ldr_error);
            //loader.addEventListener(IOErrorEvent.IO_ERROR, ldr_error);
        }
        private function loadComplete(e : Event) : void 
        {
            var json : Object = com.adobe.serialization.json.JSON.decode(e.target.data);
            var tf : TextField = new TextField();
            tf.width = 465; 
            tf.height = 465
            addChild(tf);
            //tf.appendText(e.target.data);
            var res : String;
            pr(json, 0, res);
            tf.appendText(print_r(json, ""));
        }
        private function ldr_error(ev : Event): void
        {
            var tf : TextField = new TextField();
            addChild(tf);
            tf.appendText("sec error");
        }
        private function print_r(obj : *, indent : String) : *
        { 
            if (indent == null) indent = "";
            var out : String = "";
            for (var item : * in obj)
            {    
                if (typeof(obj[item]) == "object") out += indent + "<" + item + ">\n";
                else out += indent + "(" + item + ") = " + obj[item] + "\n";
                out += print_r(obj[item], indent + "   ");
            }
            return out;
        }
        private function pr(obj : *, level : int = 0, output : String = "") : * 
        {
            var tabs : String = "";
            for (var i : int = 0; i < level; i++) tabs += "\t";
            for (var child : * in obj) 
            {
                output += tabs + "[" + child + "] => " + obj[child];
                var childOutput : String = pr(obj[child], level + 1);
                if (childOutput != '') output += ' {\n' + childOutput + tabs + '}';
                output += "\n";
            }
            if (level == 0) trace(output)
            else return output;
         }
    }
}