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

YouTubePlayer API

Get Adobe Flash player
by ProjectNya 13 Sep 2010
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/r5kL
 */

////////////////////////////////////////////////////////////////////////////////
// YouTubePlayer API
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.display.StageAlign;
    import flash.display.Loader;
    import flash.display.DisplayObject;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.system.Security;

    [SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]

    public class Main extends Sprite {
        private var player:Object;
        private var loader:Loader;
        //private static var youtubePath:String = "http://www.youtube.com/cp/ZL5d6vPEhMw?version=3&enablejsapi=1";
        private static var youtubePath:String = "http://www.youtube.com/v/ZL5d6vPEhMw?version=3&enablejsapi=1";
        private static var playerWidth:uint = 352;

        public function Main() {
            //Wonderfl.capture_delay(1);
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            init();
        }

        private function init():void {
            Security.allowDomain("www.youtube.com");
            Security.allowDomain("s.ytimg.com");
            //Security.loadPolicyFile("http://www.youtube.com/crossdomain.xml");
            //Security.loadPolicyFile("http://s.ytimg.com/crossdomain.xml");
            loader = new Loader();
            addChild(loader);
            loader.x = uint((465 - playerWidth)/2);
            loader.y = uint((465 - playerWidth/16*9 - 32)/2);
            loader.contentLoaderInfo.addEventListener(Event.INIT, initialize, false, 0, true);
            loader.load(new URLRequest(youtubePath));
        }
        private function initialize(evt:Event):void {
            loader.content.addEventListener("onReady", ready, false, 0, true);
        }
        private function ready(evt:Event):void {
            player = loader.content;
            player.setSize(playerWidth, playerWidth/16*9+32);
            //player.cueVideoById("ZL5d6vPEhMw", 0, "small");
        }

    }

}