Skip to content
Jun 3 / Sidney de Koning

Playing Chromeless YouTube video’s in AS3

Today me and a colleague spend a considerable amount of time looking for a way to show a chrome less YouTube Video in an AS3 project. We finally found a solution after searching the net for 2 hours :)

Below is the code and zip file with the entire project made in FDT 4. (So you can import it directly).

First you instantiate an new YouTubeLoader instance. Once the load is handled you pass the url bit of the movie on youtube.

_youTubeLoader = new YouTubeLoader();
_youTubeLoader.addEventListener(YouTubeLoaderEvent.LOADED, handleVideoLoaded, false, 0, true);
_youTubeLoader.addEventListener(YouTubeLoaderEvent.STATE_CHANGE, handleVideoStateChange, false, 0, true);
_youTubeLoader.create();

function handleVideoStateChange(event : YouTubeLoaderEvent) : void {
    switch(_youTubeLoader.getPlayerState( )) {
        case "0":
            _youTubeLoader.seekTo( 0 );
            break;
        }
}

function handleVideoLoaded(event : YouTubeLoaderEvent) : void {
    // This is the YouTube movie ID
    var id : String = "WbJX4RzfJ8E";

    trace( _youTubeLoader.getPlayerState( ) + "state", toString( ) );
    _youTubeLoader.loadVideoById( id );
    _youTubeLoader.setSize( 511, 383 );
    addChild( _youTubeLoader );
    _youTubeLoader.play();
}

The only thing left now is ta make sure the ExternalInterface communication with JavaScript works as it should. So you add this to your embed tag

    //init the youTubeLoader javascript methods
    SWFID = "application";

Then you complete embed tag becomes the following;




Here is the zip with the complete project.

Please consider to buying me a coffee.

Leave a comment