Flex Code for Searching Youtube Videos

I wrote AS3 code which allows you to search for videos from Youtube and parses the feedback and create objects. YoutubeService is the class which will do the parsing and creation of objects. It’s got three methods. One is the constructor, which will instantiate the HTTPService component. Second is the getVideos() method, this method will take the result handler and the search string as input.

You use these two methods to get the content from the Youtube server. Once the content is received you can send it to the createVideosFromXML() method to create objects of the type YoutubeVideo (AS Class). This method expects the XML response from the Youtube server as input in XML format.

All you have to do is to instantiate the YoutubeService class and call the method to create the YoutubeVideo object from the response as shown below

private function getVideos():void

{

var service:YoutubeService = new YoutubeService();

service.getVideos(handleServerResponse, <string to search for>);

}

private function handleServerResponse(event:ResultEvent):void

{

var responseXml:XML = event.result as XML;

var videos:ArrayCollection = YoutubeService.createVideosFromXML(responseXml);

}

That is all you need to do🙂 download the YoutubeService Class and YoutubeVideo class at the URLs below.

YoutubeService.as and YoutubeVideo.as

Hope this is useful. Please feel free to use it.🙂

3 Responses to Flex Code for Searching Youtube Videos

  1. Ne0 says:

    Sounds pretty good mate. I was trying to to do something similiar but had some problems witht the namespaces within the atom feed. I will ur classes now and thats it🙂

  2. Rakesh says:

    When I try to run my code using your as files , I get the following error .

    A file found in a source-path must have the same package structure ”, as the definition’s package, ‘com.adobe.services’.

    Please help !

  3. Sujit Reddy G says:

    Hi Rakesh,

    As the error clearly says you need to place the source files in same directory location as the package name. This is similar to Java.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: