Use the as3flickrlib library to dynamically load Flickr images into a Five3D photo album application.
In this tutorial we looked at creating a 3D photo album. It worked well, but the images were embedded into the SWF file, meaning it had to be recompiled every time a new photo was to be shown. Here we will extend the application to dynamically load the images from Flickr.
For this code to work you will need the as3flickrlib and as3corelib libraries.
ResourceManager.as
The ResourceManager will now load a number of images from Flickr instead of being where we embed static resources. First we need to create a new FlickrService object. This will be our gateway to the Flickr service. [code]
We then attach the onPhotosSearch function to the FlickrResultEvent.PHOTOS_SEARCH event. This will be called when Flickr returns some photos from our search. [code]
Finally we use the Flickr API to search for some photos with a particular tag – sunset in the case. [code]
When Flickr returns the data, onPhotosSearch gets called. We loop through each of the photos, and create the URL that the image itself can be downloaded from. [code]
We then create a new Loader object. [code]
When the Loader has completed its task we set it to store the resulting BitmapData into the Textures collection. [code]
We then ask the loader to grab the Flickr image. [code]
ApplicationManager.as
There are only minor modifications that need to be made to the ApplicationManager from the last tutorial. The first is that we don’t add a new 3D photo to the scene until the ResourceManager has actually loaded an image. [code]
When we know that the ResourceManager has some images to play with, we pull out one at random and use it as the material for the Bitmap3D object whenever we create a new 3D Photo. [code]
FlickrPhotos3D.mxml
We also need to load some security policy files, which allows Flash to load resources from an external domain. [code]
With just a few additional lines of code our original 3D photo album can be modified to display dynamic resources from a site like Flickr. Using this Flash applet for yourself only involves adding your own Flickr API key and changing the call to service.photos.search to find photos that match your own requirements.
Go back to Five3D Tutorials
Using the Bing WebService from Flex
Microsoft has an API for their Bing search engine that is accessible from Flex. This tutorial will show you how to use it.