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

wonderfl api を試す

Get Adobe Flash player
by naoto5959 04 Oct 2009
/**
 * Copyright naoto5959 ( http://wonderfl.net/user/naoto5959 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/xA9F
 */

package
{
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.text.*;
    
    import com.adobe.serialization.json.*;
    
    public class FlashTest extends Sprite
    {
        public static const API_ENDPOINT:String
            = "http://api.wonderfl.net";
        public static const USER_INFO:String = "/user/";
        
        public static const STATUS_OK:String = "ok";
        
        public static const STATUS_NG:String = "fail";
        
        private var _apiKey:String = "";
        
        private var _tf:TextField;
        
        public function FlashTest()
        {
            if (_apiKey =="") getAPIKey();    
            createTF();
            getUserInfo("naoto5959");
        }
        
        private function getAPIKey():void
        {
            if (loaderInfo.parameters 
                && loaderInfo.parameters.open_api_key is String)
            {
                _apiKey = loaderInfo.parameters.open_api_key;
            }
        }
        
        private function createTF():void
        {
            _tf = new TextField();
            _tf.defaultTextFormat = new TextFormat("_等幅", 12);
            _tf.width = 465;
            _tf.height = 465;
            _tf.multiline = true;
            _tf.wordWrap = true;
            addChild(_tf);
        }
        
        private function getUserInfo(userName:String):void
        {
            var url:String = API_ENDPOINT + USER_INFO;
            url += userName
            url += "?api_key=" + _apiKey;
            
            var urlLoader:URLLoader =new URLLoader();
            urlLoader.addEventListener(Event.COMPLETE, function(event:Event):void {
                urlLoader.removeEventListener(Event.COMPLETE, arguments.callee);
                var json:String = urlLoader.data;
                _tf.appendText(json + "\n\n");
                
                var obj:Object = JSON.decode(json);
                _tf.appendText("getUserInfo result status:" + obj.stat + "\n\n");
                if (obj.stat == STATUS_NG) {
                    return;
                }
                _tf.appendText("user.icon:" + obj.user.icon + "\n\n");
                _tf.appendText("user.external_url:" + obj.user.external_url + "\n\n");
                _tf.appendText("user.name:" + obj.user.name + "\n\n");
                _tf.appendText("user.code_count:" + obj.user.code_count + "\n\n");
                _tf.appendText("user.description:" + obj.user.description + "\n\n");
            });
            urlLoader.load(new URLRequest(url));
        }

    }
}