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

Simple: using Wonderfl Api By Code

Get Adobe Flash player
by aobyrne 25 Jul 2011
    Embed
/**
 * Copyright aobyrne ( http://wonderfl.net/user/aobyrne )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/4G98
 */

package  
{
    import com.adobe.serialization.json.JSON;
    import com.bit101.components.TextArea;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.text.TextField;
    import net.wonderfl.data.APICodeData;
    import net.wonderfl.data.CodeData;
    import net.wonderfl.utils.WonderflAPI;
    
    /**
     * ...
     * @author sandcastles
     */
    public class UsingWonderflApiByCode extends Sprite 
    {
        static public const OPEN_API_KEY:String = "a76b80051993a7c6322bf8b4bbc457b44c3d4f5c";
        static public const OPEN_API_KEY_NAME:String = "open_api_key";
        private var textArea:TextField;
        private var d:*;
        
        public function UsingWonderflApiByCode() 
        {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            
            textArea = TextField(addChild(new TextField()));
            textArea.width = 465;
            textArea.height = 725;
            textArea.wordWrap = true;
            textArea.border = true;
            var apiParameters:Object = {};
            apiParameters[OPEN_API_KEY_NAME] = OPEN_API_KEY;
            var wonderflAPI:WonderflAPI = new WonderflAPI( apiParameters );
            cTrace( "Trace.traceObject(wonderflAPI) : " + Trace.traceObject(wonderflAPI) );
            var a:URLRequest = wonderflAPI.apiCode('1WzW');
            cTrace( "Trace.traceObject(a) : " + Trace.traceObject(a) );
            var uRLLoader:URLLoader = new URLLoader();
            uRLLoader.addEventListener(Event.COMPLETE, onComplete);
            uRLLoader.load(a);
        }
        
        private function onComplete(e:Event):void 
        {
            d = JSON.decode(URLLoader(e.target).data);
            addEventListener(Event.ENTER_FRAME,doOneFrameAfter)
            var aPICodeData:APICodeData = new APICodeData(d);
            cTrace( "Trace.traceObject(aPICodeData) : " + Trace.traceObject(aPICodeData) );
            var c:CodeData = aPICodeData.code;
            var t:String = Trace.traceObject(c);
            cTrace( "t : " + t );
            
        }
        
        private function doOneFrameAfter(e:Event):void 
        {
            removeEventListener(Event.ENTER_FRAME, doOneFrameAfter);
            textArea.appendText(Trace.traceObject(d));
            textArea.appendText("---------");
            textArea.scrollV = textArea.maxScrollV;
            
        }
        
        private function cTrace(msg:String):void 
        {
            textArea.appendText('--------------\n');
            textArea.appendText(msg + '\n');
        }
        
    }

}
import flash.utils.describeType;
class Trace 
{
    static private const SEPARATOR:String = "\n";
    static private const VALUE_SEPARATOR:String = ":";
    
    public function Trace() 
    {
        
    }
    
    /**
     * http://www.learnosity.com/techblog/index.cfm/2008/2/6/AS3--Looping-over-properties-of-a-class
     * @param    objArg
     * @return
     */
    public static function traceObject(objArg:Object,separator:String="",valueSeparator:String=""):String 
    {
        separator = separator == ""?SEPARATOR:separator;
        valueSeparator = valueSeparator == ""?VALUE_SEPARATOR:valueSeparator;
        //trace( "objArg : " + objArg );
        var def : XML = describeType(objArg);
        //trace( "def : " + def );
        var output:String = "";
        //Crazy:::::
        var properties : XMLList = def..variable.@name + def..accessor.@name;
        var number:int = 0;
        //trace("accesors and variables:");
        var p:String;
        for each ( var property : String in properties ) 
        {
            p = property + valueSeparator+" " + objArg[property];
            //trace(++number + "." + p);
            output += separator + p;
        }
        
        return output;
    }
    
    public static function traceMethods(objArg:Object):void 
    {
        var v:XMLList = describeType(objArg)..method;
        var name:String;
        var returnType:String;
        trace("methods:");
        var method:Function;
        var value:*;
        for (var j:int = 0; j < v.length(); j++) 
        {
            name = v[j].@name;
            returnType = v[j].@returnType;
            method = objArg[name];
            if (returnType!='void') 
            {
                
                value = method();
            }
            else
            {
                value = "void";
            }
            
            trace((j+1)+"."+name +" : " + value);
            
        }
    }
    
}