Developer Network Home  Help 

YDN Flash Developer Center Creating Badge Kit Services
Flash Developer Center

ASTRA Badge Kit

The Badge Kit is an an XML-based framework for rapid development of small interactive Flash applications. You can learn how to use the Badge Kit very quickly, and most of the usage scenarios require no knowledge of Flash.


Creating Badge Kit Services

Creating services for the Badge Kit is simple if you have a bit of ActionScript knowledge. Since the framework is already there, it's easy for you to plug in your service URLs, tweak the parameters, and be on your way. I'll go over some of the steps you'll want to follow in order to make your service compatible with the Badge Kit.

Creating a Service

First of all, in order to have a common language for the Badge Kit, all services need to have the same API for sending and receiving results. To easily accomplish this, any service must implement the Interface com.yahoo.webapis.IService. All this does is ensure that you've created the same methods for sending and returning results.

The interface IService sets up two methods that you'll need to implement:

  1. send, which sends the service: function send(parameters:Object = null):void;
  2. a getter to access the service results: function get lastResult():Object;

Here's a example of a service that was created for the WTH badge. This service simply downloads an RSS feed of odd news and parses it into an array. I've simplified the source code a bit for readability.

First, we declared the service, implementing IService. We placed this code into an AS file called OddNewsRSSService.as, under that example's source folder. Then we implemented the two necessary methods, send() and get lastResult().

In the send() method, we create a loader to do the downloading of the RSS feed. We set up an event listener so when it's done downloading, it will parse through the results and place them into an array. Using the get lastResult() method, we return this array of items we've parsed out. Now we can access this information from the service's lastResult property in the badge's content.xml.

For more information on this service, see the WTH badge in your Examples folder where you installed the Badge Kit.

For more info on sending and receiving data in Flash, see the LiveDocs article Working with external data.

To see an example of a full service, and for copy-and-paste code that you can use in your own services, check out the source code for the Yahoo! Search Service, included in the Badge Kit source at com/yahoo/webapis/search/SearchService.

Deployment

Finally, when you've tested your service and are ready to deploy it, you'll want to compile it into a SWF that you'll be able to import into your badge. For more information on compiling, see the article Deploying Items to the Badge Kit.