Dynamically Resize Yahoo! Map in Flex 2.0 Application

Sunday, November 25th, 2007

The topic around dynamically resizing Yahoo! Maps in Flex came up in the Yahoo! Flash Developer Group last week. At the same time, I had also been trying to solve this problem for a project I’m working on. At first this problem seemed quite mysterious. I could resize the map, but it was always resizing to a 3×2 aspect ratio. If I had a container was not 3×2, the map would pin itself to the top of the container and have white borders to the right and bottom. I tried all possible combinations of properties (height, width, percentHeight, percentWidth, scaleContent) with no luck.

Yahoo! provides an AS3 API for Flex 2.0 developers that includes a SWF (built in AS2.0) and a SWC. The AS3 AstraWebAPI libraries are a set of wrapper tools that facilitate access to Yahoo!’s Web APIs from Flex 2.0 and Flash. This library works quite well, but it only exposes a subset of the API calls that are allowed by the Yahoo! API’s - so as a Flex developer you only have access to the most common calls. Unfortunately the AstraWebAPI swc does not include the setMapSize method that is defined in the as2map.swf file. So how do we access this method?

A little background. as2map.swf is an ActionScript 2 swf that you load into your Flex application when you instantiate a Yahoo Map. The AstraWebAPIs.swc file then provides a set of wrapper classes that uses ExternalInterface to communicate between your Flex application and the as2map.swf. It sounds kind of ugly - and is - but until Yahoo! releases an AS3 version of their mapping tool, this method will have to do.

So how do we make API calls to methods not exposed by AstraWebAPIs.swc file? My solution is to call the ExternalInterfaceBuffer directly from within your Flex application. It’s pretty easy to do…


import com.yahoo.webapis.maps.utils.ExternalInterfaceBuffer;


private function resizeMap(someWidth:int, someHeight:int) : void {
   // SWFDOMID and UNIQUEID are constants set in your existing map code
   var apiCall:String = SWFDOMID + ".setMapSize" + UNIQUEID;
   var EIBuffer:ExternalInterfaceBuffer = ExternalInterfaceBuffer.getInstance();
   EIBuffer.addCall({method:apiCall, data:{w:someWidth, h:someHeight})
}

I have provided an example (with source available here) that you can look at.

Link Dump from my Flex Presentation

Thursday, August 23rd, 2007

Last night I gave a presentation to a group of about 40 web developers/designers in Victoria, British Columbia. I promised you all a link dump of the sites I visited so here it is…

Samples of Rich Internet Applications developed with Flex:

Flex Resources at the Adobe website:

A good way to keep up on Flex and AIR related topics:

During the session we created a Flex application that grabbed my favorite Flickr Images, and placed them into a Display Shelf component. We published the code as a Flex application and an AIR application. You can download the source code for both projects as well as my presentation slides in this zip package. Here are a couple of links to the Flickr API you might find useful if you decide to modify my source:

I hope you enjoyed the presentation as much as I enjoyed presenting! Thanks again for showing up!

Develop a Facebook Platform App with Ruby On Rails

Monday, July 2nd, 2007

Stuart Eccles has a great Tutorial on developing a Facebook platform application with Ruby On Rails that will walk you through the paces of creating a Social Recipe application for Facebook. There is good introductory Rails information as well as very complete information on working with the Facebook Developer’s Platform.

Flex API Posters

Thursday, April 5th, 2007

Flex.org is offering to send you a free set of Flex API posters.  A former colleague had a set of these posters and they are fantastic (and huge)!  There is a catch though, if you want a poster set, you need to put a Flex.org badge on your site, or write a blog post ;-)

JavaScript Wrapper for del.icio.us Bookmarks

Saturday, March 31st, 2007

Dishy is a simple JavaScript wrapper for del.icio.us that helps you integrate your bookmarks onto your website. Dishy makes use of JSON and some simple methods and properties to allow you to easily customize the look and feel of your bookmark list.

Amazon Grid Storage Web Service

Tuesday, March 14th, 2006

Michael Arrington from TechCrunch has a good summary of the new Amazon  Grid Storage Web Service.  In a nutshell this new service from the number one online bookseller, provides web developers with a very inexpensive ($.15/GB of storage) online storage system that can be accessed using both REST and SOAP.  The idea is that Amazon provides the storage, bandwidth and scalablility any you the developer build applications on top of it.

Yahoo! JavaScript Developer Center

Friday, December 16th, 2005

The Yahoo! Developer Network has just added a JavaScript Developer Center with tonnes of great examples on how to consume Yahoo!s Web Services using JavaScript. Most noteable, is the ability to access these API’s using the REST protocol and have the results returned as JSON objects, effectively removing the need for a Web Proxy.

Alexa Web Search Opens Up API

Tuesday, December 13th, 2005

Big announcement on the API/Web Services front today with Alexa completely opening it’s search API and providing access to its search data. The Alexa Web Search Platform is sure to be a mashup programmers heaven allowing users to search and process billions of documents and even create their own search engines using Alexa’s search and publication tools. The service isn’t totally free, but the cost appears to be very reasonable. The first 10,000 requests per month are free then after that, requests cost 15 cents per thousand.

Here is a list of links to the current pulse of the blogosphere on this topic:

The Google Search API

Thursday, November 17th, 2005

The web development weblog has three great tutorials that will show you how to create your own customized search page using SOAP from PHP. The tutorials cover:

Use Google Maps without an API Key

Wednesday, November 9th, 2005

There apparently is a way to Use Google Maps without an API Key.

I fully understand why Google requires developers to apply for and use an API key, and I would certainly do this for any site I was to place on a production website, but a recent project where I was doing some Google Map hacking made it clear to me that the API key policy was a bit restrictive for solely testing purposes. When you apply for an API key, you need to specify a top level domain and the exact path to the location of your Google Map. If you need to change the path, you must reapply for an API key and modify your code accordingly. Needless to say, I found this to be a bit inconvenient as I ended up moving the file a couple of times.