Youtube Data API AS3 – First Tutorial

19 actionscript,as3,flash,webservices,work,youtube  |   February 19, 2008  |     2457

Hi everyone,

In this tutorial I will demonstrate how to use the YouTube Data API AS3 Library to:

  • search for videos using a keywords, categories and tags;
  • demonstrate how to distinguish between feeds returned to you by the API by using the requestId;
  • get information from the result feed, in this case a VideoFeed object. We will get the video, it’s main URL, then go through the different thumbnails available for a specific video.

So let’s get started

So far we’ve defined our class, SearchSample, and two member variables: _ws (which will contain a reference to the YouTubeClient singleton) and _requestId (to store the unique id associated with our specific request).

Next we will get a reference to the YouTubeClient class, listen for the proper event, launch our search request and store the requestId associated with it.

Now on with the event handler, doSearchResults. We will:

  • make sure we are treating the right request, since YouTubeClient is a singleton, this can become important when you have multiple calls being made from different places in your program.
  • get a reference to the VideoFeed object contained inside of the VideoFeedEvent object passed as a parameter to the event handler.
  • create a variable to contain the VideoData objects describing the videos received in the results
  • iterate through the first set of results (since we are getting the first 50 by default
  • see some useful variables such as the Title of the video and it’s author’s name
  • get a reference to the ThumbnailIterator which will give us access to all available thumbnails
  • create a variable to contain ThumbnailData objects which describe each thumbnail available

That’s it folks! The project is now available at Google Code, here:

I could use help with documentation, if anybody feels up to the task, leave your email or contact info in a comment!

  • March 24, 2008 at 6:16 pm

    Gonzalo Geraldo

    Hello, Im trying to play with this great library but i cant make it work on browser…inside flash everything its fine. Its crossdomain working???


  • March 24, 2008 at 6:38 pm

    gonzalo Geraldo

    sorry, sorry, sorry

    i just read the previuos post 🙁 and its working really fine !!!!

    thanks a lot

  • March 29, 2008 at 10:16 am

    Alan Jenkins

    Getting the following error on doLogin:
    ArgumentError: Error #2096: The HTTP request header Authorization cannot be set via ActionScript.

    Can you advise please? Thanks

  • April 23, 2008 at 6:43 am


    when I try to load video.swfUrl on stage, it displays a warning in debug:

    Warning: Domain does not specify a meta-policy. Applying default meta-policy ‘all’. This configuration is deprecated. See to fix this problem.

    Do you can help me?

  • April 25, 2008 at 9:38 am



    I am working on a version which uses a AMFPHP Proxy. This problem you had is caused by the security sandbox from the Flash Player, by using a proxy we have complete freedom. In PHP and most other programming languages you don’t have these (stupid) limitations. I use cURL to make the requests, and return the responses using AMFPHP. It works quite nice. I recently posted on it. The API will be updated shortly.

  • April 25, 2008 at 9:40 am



    this problem is due to the crossdomain.xml policy file found on, over which I have no control. I suggest posting this comment in the google group on the Youtube Data API developer forum.

  • June 25, 2008 at 8:32 am

    dehash » YouTube API Resources «

    […] Youtube Data API AS3 – Tutorial […]

  • June 25, 2008 at 11:00 pm



    Great post! Have you updated API with the fix for policy issue?

  • July 10, 2008 at 9:12 pm



    i really liked this AS3 Classes, but i can´t download from…there is a problem? –

  • July 21, 2008 at 3:03 am


    I’m a AS3 new beginner and I’ve read your sample code in this article. But when I press Ctrl + Enter to test, it show: “Error:5000, it must have sub-class “flash.display.MovieClip”
    Then I import flash.display.MovieClip, but still pop the same error code 5000. Could you kindly give me some suggestions?
    Thanks a lot!!

  • July 26, 2008 at 9:26 am



    I tried to use the method getVideo from YouTubeFeedClient class, but I have the next message:


    The code it is the follow:

    _ws = YouTubeClient.getInstance();
    _ws.addEventListener(VideoFeedEvent.VIDEO_DATA_RECEIVED, doSearchResults);

    _requestId = _ws.getVideos(“uEGPF1be6RM”);

    anyone know, what happend?


  • July 30, 2008 at 4:43 pm

    Tutorials | AS3 and AMFPHP Roundup « Flash Enabled Blog

    […] Youtube Data API AS3 […]

  • October 13, 2008 at 2:18 am

    niklas wörmann

    Impressive work indeed, and its really amazing the kind of interaction with Youtube you can acchieve.

    I am having a really annoying problem though, where amidst all the data can I retrive the URL to the netstream I need to connect my Video player to actually play the stream?

    Niklas Wörmann

  • November 17, 2008 at 8:18 pm

    Flash Tips » AS3 and AMFPHP roundup

    […] Youtube Data API AS3 […]

  • March 11, 2009 at 7:18 am


    Okay…I think I must be a complete idiot, cause I’m really having a hard time getting this. (Though I’m making progress)

    I’m trying to get a the ten most recently uploaded videos from a particular youtube account, and I just can’t seem to make it happen.
    (I think I need to use “VideoFeedEvent.VIDEO_DATA_RECEIVED”, but I’m not sure how to do it…)

    So far, this is the most mack-daddy site that I’ve found for the youtube API. Can somebody please help me? PLEASE!!!

  • March 12, 2009 at 12:27 pm


    Okay…I figured it out. The latest download (0.95) gets a little confused, because the test files and classes are trying to access and it doesn’t exist anymore. (They are now &

    Simply switch it to the most appropriate file and you’ll be golden.

    Now, if I can just figure out how to attach my new content to items on my stage I’ll be crazy happy!

  • March 13, 2009 at 9:24 pm


    Two days later…still trying to figure out the getAt method. ARGH!!!

    I think that’s how I need to call specific lines from the feed.

  • July 17, 2010 at 1:34 pm


    Great work!!! works great in flash builder 4 too

  • July 21, 2014 at 12:02 am


    I found these issues when I am using this api to our project,can any one help me:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at count()


Leave a Reply