Youtube Flash AS3 / AS2 Data & Player API

Youtube Flash AS3 / AS2 Data & Player API

Recently I have been working on something involving the use of video content from Youtube. With the lack of a good API out there I created my own. Below is a simple example of this working with sample code to download further below.

AS3 example

import com.flashdynamix.services.YouTube;
import com.flashdynamix.events.YouTubeEvent;
//
var yt:YouTube = new YouTube();
yt.clientKey = "ytapi-ShaneMcCartney-flashdynamix-vuj2k916-0";
function onLoaded(e:YouTubeEvent) {
switch (e.method) {
case YouTube.SEARCH :
for each (var video:YouTubeVideo in e.data.list) {
trace(video);
}
break;
}
}
//
yt.addEventListener(YouTubeEvent.COMPLETE, onLoaded);
yt.videosForTag("Top Gear");

AS2 example

import com.FlashDynamix.services.YouTube;
//
var yt:YouTube = new YouTube();
yt.APIKey = "WplekwLy_Nw";
var obj:Object = new Object();
obj.loaded = function(evt:EventArgs) {
switch (evt.type) {
case YouTube.VIDEOSBYTAG :
var videos = evt.value.video;
break;
}
};
//
yt.addListeners(obj);
yt.videosbyTag("Top Gear");

The class I created Youtube.as supports both the legacy and current version of the Youtube API legacy documentation and current documentation.

Related: Export Layers to SWF with JSFL