Truveo
Developer Center
Introduction to the Truveo Video Search Flash API
The Truveo Video Search Flash API allows developers to access the Truveo video search engine using Macromedia Flash. Using this API, developers can build a variety of custom applications that feature video search results and functionality. The Truveo Video Search Flash API is designed to work in all versions of Macromedia Flash 6 and above.
Accessing the API
To gain access to the Truveo Video Search Flash API, you must first set up an API account. To create a new API account or view your existing API account, please consult the My API Account page. When you first create a new API account, you will be assigned a unique key, or Application ID. This Application ID is a string that uniquely identifies your organization's application and authorizes it to access the Truveo video search index.
Getting Started Using the Flash API
To enable access to the API in your Flash application, you will first need to import the Flash API ActionScript library into your Flash application. To do this, first download the latest version of the API. Place the TruveoVideoSearch.as file in the same directory as your Flash application (or in a directory that is in your currently set classpath. For more information on setting the classpath in the Flash 8 IDE: setting the classpath). Add the following line to the beginning of the Actions for the first frame of the root timeline:
import TruveoVideoSearch;
If you are invoking the API from a separate class, you can alternatively add the line above to the specific class that is invoking the API.
Instantiating and Initializing the TruveoVideoSearch Object
With the Flash API ActionScript library imported, you can now create an instance of the TruveoVideoSearch object, which is the ActionScript class that defines all of the attributes, methods, data objects and events of the Flash API. To create an instance of this object, its constructor method must be called with a single argument, which is your assigned Application ID value. For example, the following code sample creates a new TruveoVideoSearch object with the Application ID '1x1jhj64466mi12ia' and assigns this object to the variable TVS:
var TVS:TruveoVideoSearch = new TruveoVideoSearch('1x1jhj64466mi12ia');
Before you can begin using the methods of the TruveoVideoSearch object, you must first initialize this object. This can be done by calling the 'initialize' method of the object as follows:
TVS.initialize();
This initialization method will initialize the state of the Flash API, and in some cases, it will send an asynchronous request to the Truveo video search service to see if the current user is logged in to your application. When these initialization steps are complete, the TruveoVideoSearch object will fire the 'onload' event. Therefore, if you intend to invoke other methods of the TruveoVideoSearch object as soon as initialization is complete, it is best to do this after the 'onload' event has fired. To detect the 'onload' event of the TruveoVideoSearch object, a handler can be attached to this event as follows:
TVS.addEventListener("onload", handleVSLoad);
In this case, the function 'handleVSLoad' has been attached to the the 'onload' event of the TruveoVideoSearch object, and it will be called when the initialization of this object is complete. Note that this handler should be attached before the 'initialize' method is called so that it will successfully be able to catch the 'onload' event of the TruveoVideoSearch object. With these changes, the ActionScript code on the root timeline will look like:
var TVS:TruveoVideoSearch = new TruveoVideoSearch('1x1jhj64466mi12ia');
TVS.addEventListener("onload", handleVSLoad);
TVS.initialize();
Retrieving and Displaying Video Search Results
With the TruveoVideoSearch object initialized, all of the methods and features of the Truveo Video Search Flash API are now available for use. For this example, let us assume that you would like to retrieve a set of video search results about the topic 'Madonna' as soon as the TruveoVideoSearch object has been initialized. This can be done by defining a method named 'handleVSLoad' that calls the 'getVideos' method of the TruveoVideoSearch object:
function handleVSLoad() {
        TVS.getVideos('Madonna');
}
When this method is invoked, an asynchronous request will be sent to the Truveo video search service to retrieve videos that match the query term 'Madonna'. Since this request is asynchronous, any code that follows this request will be executed immediately - in some cases before the response is received from the Truveo video search service. When the response is received, the 'onupdate' event of the TruveoVideoSearch object will fire. Therefore, in order to display the search results returned in this response, it is necessary to first handle this 'onupdate' event. As discussed above, a handler can be attached to the 'onupdate' event of the TruveoVideoSearch object using its 'addEventListener' method as follows:
TVS.addEventListener('onupdate', handleUpdate);
In this case, the function 'handleUpdate' has been attached to the 'onupdate' event, and it will be called every time a response is received following a call to the Truveo video search service. To display the search results in the body of your web page, this function should define the necessary logic for formatting the information in the response for presentation in the body of your web page. As a simple example, the code below traces the title of every video returned in the search results:
function handleUpdate() {
        for (var i=0; i < TVS.VideoSet.totalResultsReturned; i++) {
                trace ("VideoSet.Video[" + i + "].title=" + TVS.VideoSet.Video[i].title);
        }
}
As shown above, the title of each video is available in the 'VideoSet.Video[i].title' attribute of the 'VideoSet' data object of the TruveoVideoSearch object. Additionally, the number of search results returned is available in the attribute 'VideoSet.totalResultsReturned'. For a complete list of the data objects and the fields of information supported by these objects, please consult the Flash API reference documentation.
We have now completed the steps required to build a flash application that retrieves the video search results using the Truveo Video Search Flash API. Bringing it all together, the code for this Flash application should now look as follows:
import TruveoVideoSearch;

function handleVSLoad() {
        TVS.getVideos('Madonna');
}

function handleUpdate() {
        for (var i=0; i < TVS.VideoSet.totalResultsReturned; i++) {
                trace ("VideoSet.Video[" + i + "].title=" + TVS.VideoSet.Video[i].title);

        }
}

var TVS:TruveoVideoSearch = new TruveoVideoSearch('1x1jhj64466mi12ia');
TVS.addEventListener("onload", handleVSLoad);
TVS.addEventListener('onupdate', handleUpdate);
TVS.initialize();
Click here to download a functioning version of this simple Flash application. Click here to download a Flash application that shows how to exercise most of the functionality of the Flash API.
You are now ready to get started building applications using the Truveo Video Search Flash API. To view some simple and sophisticated applications built using this API, please check out the application gallery. To see a full list of the methods, attributes, data objects and events supported by this API, please consult the Flash API reference documentation.
Help Company Info Developer Resources Video Publisher Resources
Building Queries About Truveo Developer Center Truveo Director Accounts
Basic Searching Press Truveo API Overview Submitting A Feed Using Media RSS
Using Modifiers Team XML API Director Account FAQ
Using Filters Jobs AJAX API  
Using Sorters Contact Us Flash API  
Advanced Searching Terms of Use Ruby API  
  Privacy Policy Application Gallery  
  Adult FAQ    

Truveo video search lets you search and find videos from across the Web. Use Truveo to find all types of online video including hit television shows, full-length movies, breaking news clips, sports highlights, music videos, or the latest viral videos. If you are looking for a specific video, Truveo video search can help you find exactly the video you want. Truveo can also help you browse through video across the web and discover new videos that you might like.

©2004-2007 Truveo, Inc. All Rights Reserved.