Yahoo! Flash Developer Center

The Yahoo! Flash Developer Center is live and open for business!

Check it out at: http://developer.yahoo.com/flash/

The Y! Flash Developer Center aims to be your source for information about using Adobe Flash with Yahoo! Web Services and APIs. We provide you with things like HOWTO Articles, components for use in your Flash applications, and links to other resources on the web where you can find source code and helpful tools. Of course, it’s our new baby and is thus still in it’s infancy. It will no doubt continue to evolve and grow, but we can’t do it without help from people like you (I know that sounds corny, but it’s true).

Additionally, be sure to sign up for the public Yahoo! Flash group at http://tech.groups.yahoo.com/group/ydn-flash/ And if you haven’t already, be sure to read my post on Yahoo! Hack Day.

I wrote a simple article on how to get started using Yahoo! Search APIs in ActionScript 2 or ActionScript 3

There are other interesting articles up there now, including how to:

We’re working on other articles too. Be sure to check out developer.yahoo.com for more info on our public APIs.

FlashForward Austin ‘06

Speaker FlashForward Austin '06 Austin, despite the fact that is centrally located in Texas, one of the most notoriously conservative states, is actually quite a liberal community with a hip, happening night life. East 6th Ave. is populated by upwards of 100 bars and interesting local venues in an area of only a few blocks, and good restaurants are very easy to locate. On top of that, the locals are outgoing, polite, and the Internet industry is thriving there, making Austin a refreshingly fun place to be.

The conference itself was awesome too. I spent time hanging out with some of my favorite people in the industry; people who’s work I have admired for years; people like Branden Hall, Mario Klingemann (a.k.a. Quasimondo), Craig Swann, and Trevor Dodd. It was awesome having a chance to hang out with those guys and discuss whatever interesting subject matter was at hand.

I saw some amazing things there as well. Jared Ficklin from Frog Design did some amazing things with audio visualization. Basically, he took a tube and attached a speaker to one end, and attached a propane canister to the opposite end. He then drilled holes in the tube, turned on and ignited the propane. He then began to play music through the speaker. As a result, you could see the waveform in the actual flame! He then photographed those images and used them in a Flash audio visualization.

Also, Beau Amber of Metaliq showed off some amazing ActionScript 3 projects. Most notable of which was a geo-data visualization in which he plotted a mesh on top of the San Francisco bay area, which represented the wind channels passing through the region. He then simulated wind speed by animating pixels across the wind streams. It was very interesting indeed.

I spent the entire first day at a Flex 2 workshop hosted by Aral Balkan of OSFlash. Flex is definitely a powerful tool. Although without robust skinning capabilities, it is not quite flexible enough to serve a company like Yahoo! as a realistic deployment and development alternative.

Everyone at the conference was really interested in what Yahoo! is doing. I introduced the Yahoo! Developer Network to a lot of developers, many of whom had never heard of it for whatever reason. I was also doing my best to push the public Hack Day, YRB’s Brain Jam, and whatever open Flash positions/internships we have available throughout the company.

My speech itself was well received. The conference room was completely packed, there was standing room only, and no one really left until the end, which I think implies that people were interested. I basically introduced the difference in the approach I had to take in developing the ActionScript 3 version of the Flash Yahoo! Search API as opposed to the ActionScript 2 version. In short, the ActionScript 2 version required me to write several packages of supporting code in order to adhere to sound object oriented programming principles; however, the ActionScript 3 version required exactly none of that. I only had to write the code to accomplish the objective at hand…go figure. I also touched on remoting with AMFPHP and how easy that is to accomplish in ActionScript 3.

All in all, I have to say it was quite fun and interesting, and I think everyone was happy to see Yahoo! taking Flash seriously. It also gave me an opportunity to re-launch caleb.org, so check it out if you have a chance.

AMFPHP in AS3

Remoting in ActionScript 3 is easy to implement, but there are some important things to keep in mind. Most notably, the mx.remoting package is no longer required. There are no additional packages to install, everything you need is built right in to flash.net

This RemotingConnection class extends NetConnection and sets the objectEncoding to AMF:

package
{
import flash.net.NetConnection;
import flash.net.ObjectEncoding;
public class RemotingConnection extends NetConnection
{
public function RemotingConnection( sURL:String )
{
objectEncoding = ObjectEncoding.AMF0;
if (sURL) connect( sURL );
}
}
}

This class employs the above class, and makes a remote service call:


package
{
import flash.net.Responder;
public class AS3RemotingTest
{
public var dataProvider:Array;
public var gateway : RemotingConnection;
public function AS3RemotingTest()
{
this.init();
}
public function init()
{
var gatewayUrl:String = "http://localhost:88/amfphp/gateway.php";
gateway = new RemotingConnection(gatewayUrl);
var responder:Responder = new Responder(onResult, onFault);
var arg:String = 'foo';
gateway.call( "HelloWorld.say", responder, arg);
}
public function onResult( result ) : void
{
trace('onResult invoked');
trace(result);
}
public function onFault( fault : String ) : void
{
trace('onFault invoked');
trace( fault );
}
}
}

(Note: The above code assumes that you have AMFPHP installed and running out of a folder named amfphp on your localhost)

ActionScript Yahoo! Search API – 3 Simple Steps

3 simple steps to performing a Yahoo! search in Flash

Download the YahooAPI class and examples

Yahoo! Developer Network provides developers a diverse offering of free web services. These services enable you to easily integrate feature rich functionality (e.g. web search, spellcheck, and contextual term extraction) with virtually no overhead other than loading an XML document via the native XML object (ActionScript 2) or URLLoader object (ActionScript 3).

Additionally, Yahoo! web services provide the developer an enormous pool of internet accessible resources, such as photos, videos, mp3’s, and data which can add complex dimensions to the already engaging Flash user experience.

These resources, and the developer’s ability to construct with them, can illustrate the multiplicity of advantages offered by applications created with Flash as opposed to more conventional client-side web development paradigms.

This article and the code provided will show you how to easily implement any of the Yahoo! search web services in ActionScript 2 or 3. The scope of this article is simply to demonstrate a sound approach to querying the Yahoo! search REST API from within Flash. It is very easy.

3 simple steps to performing a Yahoo! search in Flash 

1: Get an application id
First, in order to use the Yahoo! Search web services, you will need an application id (get one here). Both the ActionScript 2 and ActionScript? 3 classes use the same syntax for specifying the id.

Once you have an application id, the first thing your application will need to do is register the id with the YahooAPI class, as follows:

YahooAPI.APPLICATION_ID = ‘lkj34988fgjh2398ife923j4kjk234’;

2: Setup an Event Handler
Next, you need to set up an handler Function which will be invoked when the search response is received, as follows:

function onYahooSearchResult(e:com.yahoo.search.YahooSearchResultEvent):Void
{
trace(‘onYahooSearchResult invoked’);
trace(e.length + “ items found: \n”;
var result:YahooSearchResult;
for(var i:Number = 0; i < e.length; i++)
{
result = e.getResult(i);
trace(result.Title);
trace(result.Url + “\n”);
}
}

3: Search!
Once you’ve registered your application id, and created the search result event handler, all you need to do is invoke the static search method on the YahooAPI class, as follows.

Note: It is worth mentioning that the signature for the search method on the YahooAPI class differs between the ActionScript 2 implementation and the ActionScript 3 implementation.

The difference is due in large part to syntactical differences between the two languages and an effort on our part to remain consistent with the existing REST API implementations published by Adobe (com.adobe.webapis.*).

In short, the ActionScript 3 Event model works much better than the ActionScript 2 model. In addition, we take advantage of new functionality, such as the URLLoader class available in ActionScript 3.

ActionScript 2
// This example performs a web search for “monkey” which will return a maximum of 25 results:
YahooAPI.search(this, ‘monkey’, YahooAPI.WEB_SEARCH, 25);

ActionScript 3
// This example performs a web search for “monkey” which will return a maximum of 25 results:
YahooAPI.search(‘monkey’, YahooAPI.WEB_SEARCH, new NameValuePair('results', 25));
// The above call returns a URLLoader. You then subscribe to that objects events as follows:
yahooLoader.addEventListener(YahooAPI.ON_SEARCH_RESULT, onYahooSearchResult);

Specifying additional parameters
Of course you can perform different types of searches, and pass additional search parameters.

The following examples demonstrate doing so:

ActionScript 2
// image search w/ 25 results
YahooAPI.search(this, ‘monkey’, YahooAPI.IMAGE_SEARCH, 25);
// news search, with options (25 results, limited to news.yahoo.com)
YahooAPI.search(this, ‘monkey’, YahooAPI.NEWS_SEARCH, 25, ‘&site=news.yahoo.com’);

ActionScript 3
// news search, with options (25 results, limited to news.yahoo.com)
YahooAPI.search(‘monkey’, YahooAPI.NEWS_SEARCH, new NameValuePair('results', 25), new NameValuePair('site', 'news.yahoo.com'));
// image search w/ 25 results
YahooAPI.search(‘monkey’, YahooAPI.IMAGE_SEARCH, new NameValuePair('results', 25));

Download the YahooAPI class and examples 
Yahoo! API – ActionScript 2
Yahoo! API – ActionScript 3

Summary
That’s it!