views:

77

answers:

2

I am looking to embed a YouTube video with the YouTube controls into my Flash website. Is this possible?

http://sandbox.ten90demos.com/silver/#/vision

UPDATED w/ SOLUTION:

var loader:Loader = new Loader();
loader.load(new URLRequest("http://www.youtube.com/v/zIcx_rxTstc"));
addChild(loader);
A: 

It looks like this post will provide you the solution you need:

http://www.actionscript.org/forums/showthread.php3?t=122501

warriorpostman
I'll accept this, because it led me to the correct answer, even though it's hella outdated (AS2 in 2002)
Jeremy White
+1  A: 

Hi

this is a basic Class i made for that. off course you will have to create the buttons. and enable / disable some of its functions. hope it will help shani

package { import flash.system.Security; import flash.display.MovieClip; import flash.display.Loader; import flash.events.*; import flash.net.URLRequest;

public class YouTubeAS3 extends MovieClip {
    private var player:Object;
    private var playBtn:PlayBtn;
    private var pauseBtn:PauseBtn;
    private var stopBtn:StopBtn;

    public function YouTubeAS3 (vidId:String) {

        Security.allowDomain("http://www.youtube.com") ;
                    var loader1:Loader = new Loader();
        loader1.contentLoaderInfo.addEventListener (Event.INIT, onLoaderInit);
        loader1.load (new URLRequest("http://www.youtube.com/apiplayer?version=3"));

        function onLoaderInit (event:Event):void {
            addChild (loader1);
            loader1.content.addEventListener ("onReady", onPlayerReady);
            loader1.content.addEventListener ("onError", onPlayerError);
            loader1.content.addEventListener ("onStateChange", onPlayerStateChange);
            loader1.content.addEventListener ("onPlaybackQualityChange", onVideoPlaybackQualityChange);

            playBtn= new PlayBtn();
            pauseBtn= new PauseBtn();
            stopBtn= new StopBtn();


            playBtn.x = pauseBtn.x = stopBtn.x = 430;
            playBtn.y = 20;
            pauseBtn.y = 50;
            stopBtn.y = 80;



            playBtn.addEventListener (MouseEvent.CLICK,playP);
            pauseBtn.addEventListener (MouseEvent.CLICK,pauseP);
            stopBtn.addEventListener (MouseEvent.CLICK,stopP);
            player.addEventListener (MouseEvent.CLICK,setPsize);

            addChild (playBtn);
            addChild (pauseBtn);
            addChild (stopBtn);
        }

        function onPlayerReady (event:Event):void {
            // Event.data contains the event parameter, which is the Player API ID 
            trace ("player ready:", Object(event).data);

            // to load a particular YouTube video.
            player = loader1.content;
            player.loadVideoById (vidId);
            player.setSize (448, 252);


        }



        function onPlayerError (event:Event):void {
            // Event.data contains the event parameter, which is the error code
            trace ("player error:", Object(event).data);
        }

        function onPlayerStateChange (event:Event):void {
            // Event.data contains the event parameter, which is the new player state
            trace ("player state:", Object(event).data);


            if(Object(event).data==1){
                //if(loading!=null){
                //removeChild(loading);
                //loading=null;
                //}
            }

        }

        function onVideoPlaybackQualityChange (event:Event):void {
            // Event.data contains the event parameter, which is the new video quality
            trace ("video quality:", Object(event).data);
        }
    }
    public function setPsize (evt:MouseEvent):void {
        player.setSize (640, 360);
    }

    public function playP (evt:MouseEvent):void {
        if (player) {

            player.playVideo ();
        }
    }
    public function pauseP (evt:MouseEvent):void {
        if (player) {

            player.pauseVideo ();
        }
    }

    public function stopP (evt:MouseEvent):void {
        if (player) {

            player.stopVideo ();
        }
    }

    public function muteP (evt:MouseEvent):void {
        if (player) {

            player.mute ();
        }

    }

    public function unMuteP (evt:MouseEvent):void {
        if (player) {

            player.unMute ();
        }
    }

    //player.isMuted():Boolean

    //player.setVolume(volume:Number):Void

}

}

shani