Saturday, September 25, 2010

Load A YouTube Video Inside A SWF File

Flash Video Flash Video

The YouTube API

the YouTube AS3 API doesn't require you to download and install a special component for you to be able to play YouTube videos inside your project, instead you directly load a special YouTube file during runtime using the Loader Class and then use that file to play any video you want.

The basic process outline for loading the API and using it is as following:

  1. Configure Domain Security to allow YouTube to communicate with the swf.
  2. Create a variable to hold a reference to the YouTube player (
  3. Use the Loader Class to load the YouTube API file
  4. Create event handlers to control the player once the API file has successfully loaded and got initiated.
  5. Play the YouTube video by the API ID (_OBlgSz8sSM",0).


var my_player:Object;

var my_loader:Loader = new Loader();
my_loader.load(new URLRequest(""));
my_loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);

function onLoaderInit(e:Event):void{
my_player = my_loader.content;
my_player.addEventListener("onReady", onPlayerReady);

function onPlayerReady(e:Event):void{

play_btn.addEventListener(MouseEvent.CLICK, playVid);
function playVid(e:MouseEvent):void {
pause_btn.addEventListener(MouseEvent.CLICK, pauseVid);
function pauseVid(e:MouseEvent):void {

Finding the ID

The ID of the video is the string at the end of a YouTube URL that follows the v=.


youtube url

Player API Youtube API Overview Guide. The YouTube APIs and Tools let you bring the YouTube experience to your webpage, application, or device. The Data API lets you perform most of the operations a normal YouTube user can on the YouTube website. The Player APIs let you control the YouTube player using JavaScript or ActionScript. There is the basic embedded player you are used to seeing as well as the chromeless player that lets you create your own player controls.

Lastly there are the Widgets, and a custom player that you can embed on your webpage, even if you are not a web programmer.

YouTube video player with live preview playlist

youtube player

This player is for YouTube videos, it uses YouTube API batch processing to get video's information, which allows to fetch data for up 50 videos with a single API call.

Only $17 at Activeden


  1. I highly recommend Allavsoft which can directly download YouTube to SWF at

  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Training in Chennai


Related Posts Plugin for WordPress, Blogger...