You Tube Flash AS3 / AS2 Data & Player API

Recently I have been working on something involving the use of video content from You Tube. 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

  1. import com.flashdynamix.services.YouTube;
  2. import com.flashdynamix.events.YouTubeEvent;
  3. //
  4. var yt:YouTube = new YouTube();
  5. yt.clientKey = "ytapi-ShaneMcCartney-flashdynamix-vuj2k916-0";
  6. function onLoaded(e:YouTubeEvent) {
  7. switch (e.method) {
  8. case YouTube.SEARCH :
  9. for each (var video:YouTubeVideo in e.data.list) {
  10. trace(video);
  11. }
  12. break;
  13. }
  14. }
  15. //
  16. yt.addEventListener(YouTubeEvent.COMPLETE, onLoaded);
  17. yt.videosForTag("Top Gear");

AS2 example

  1. import com.FlashDynamix.services.YouTube;
  2. //
  3. var yt:YouTube = new YouTube();
  4. yt.APIKey = "WplekwLy_Nw";
  5. var obj:Object = new Object();
  6. obj.loaded = function(evt:EventArgs) {
  7. switch (evt.type) {
  8. case YouTube.VIDEOSBYTAG :
  9. var videos = evt.value.video;
  10. break;
  11. }
  12. };
  13. //
  14. yt.addListeners(obj);
  15. 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.

Download the source from the following SVN details
SVN: http://youtubeas3.googlecode.com/svn/trunk/

Don't have an SVN client? I recommend you use Tortoise - get it here or if you're an Eclipse user try Subclipse