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

because I can :P

Get Adobe Flash player
by makc3d 20 Jun 2014

    Talk

    WLAD at 21 Jun 2014 15:27
    Niiiiiiiiiiice!
    Embed
/**
 * Copyright makc3d ( http://wonderfl.net/user/makc3d )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/pEtv
 */

// forked from makc3d's I am going to get that coub no matter what!
// forked from wh0's Using proxies without crossdomain.xml
package {
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.*;
    import flash.media.*;
    import flash.system.Security;
    import flash.text.TextField;
    public class FlashTest extends Sprite {
        
        // Wrap url in proxy parameter.
        private function proxy(url:String):String {
            return 'http://www.gmodules.com/ig/proxy?url=' + encodeURIComponent(url);
        }
        
        public function FlashTest() {
            // Only the top level movie starts off with stage populated.
            if (stage) {
                // The top level movie is likely included from wonderfl.net and therefore unproxied.
                // All we do in this case is load the proxied version.
                // Allow the proxy domain so wee can access stage on lines 45-46.
                Security.allowDomain('www.gmodules.com');
                var l:Loader = new Loader();
                l.load(new URLRequest(proxy(loaderInfo.url)));
                addChild(l);
                return;
            } else {
                // Allow Wonderfl to take a screen cap.
                Security.allowDomain('swf.wonderfl.net');
                addEventListener(Event.ADDED_TO_STAGE, init);
            }
        }
        
        private function init(e:Event):void {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            
            // Now you write your own code.
            // Since the inner proxied movie is in the proxy's domain, we can request anything.
            var ul:URLLoader = new URLLoader(new URLRequest(proxy('http://coub.com/embed/1cg8ycsu')));
            ul.addEventListener(Event.COMPLETE, complete);
        }
        
        private var ns:NetStream;
        private function complete(e:Event):void {            
            var array:Array = [];
            array = e.target.data.split("\n");
            while ((array.length > 0) && (array.shift() != "<script type='text/json'>")) { /* look for json */ }
            var json:Object = JSON.parse(array.shift());
            
            var size:Array = json.site_w_h;
            if (size[0] > 465) { size[1] *= 465 / size[0]; size[0] = 465; }
            if (size[1] > 465) { size[0] *= 465 / size[1]; size[1] = 465; }
            
            var myVideo:Video = new Video(size[0], size[1]);
            myVideo.x = 0.5 * (465 - size[0]);
            myVideo.y = 0.5 * (465 - size[1]);
            addChild(myVideo);
            var nc:NetConnection = new NetConnection();
            nc.connect(null);
            ns = new NetStream(nc);
            ns.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
            myVideo.attachNetStream(ns);
            ns.play(proxy(json.file_versions.iphone.url));
            
            var sound:Sound = new Sound();
            sound.load(new URLRequest(json.file_versions.mobile.audio_url));
            sound.play(0, int.MAX_VALUE);
            
            // sync problems are left as an exercise to the reader :)
        }
        
        private function onStatus(item:Object):void {
            if (item.info.code == "NetStream.Buffer.Empty") {
                ns.seek(0);
            } else {
                // Buffer.Empty might never come
                if (item.info.code == "NetStream.Play.Stop") {
                    ns.seek(0);
                }
            }
        }
    }
}