« You Tube Flash AS3 / AS2 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

Actionscript:
  1. import com.FlashDynamix.services.YouTube;
  2. import com.FlashDynamix.events.YouTubeEvent;
  3. //
  4. var yt:YouTube = new YouTube();
  5. yt.APIKey = "WplekwLy_Nw";
  6. function onLoaded(e:YouTubeEvent) {
  7.     switch (e.method) {
  8.         case YouTube.VIDEOSBYTAG :
  9.         try {
  10.             for each (var video:XML in data) {
  11.                 trace(video.name() + " : " + video);
  12.             }
  13.             trace("Videos For Tag : " + e.request.tag + " : " + e.data.length());
  14.         } catch (evt:ArgumentError) {
  15.             trace("ERROR : No Videos For Tag");
  16.         }
  17.     }
  18. }
  19. //
  20. yt.addEventListener(YouTubeEvent.COMPLETE, onLoaded);
  21. yt.videosbyTag("Top Gear");

AS2 example

Actionscript:
  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 here