Dead Simple as3flickr, Flickr API Example

I’ve finally had a chance to start messing around with the ActionScript 3 Flickr API, as3flickr. One thing I noted right away is that there aren’t too many dead simple examples of how to use the library. Most of the examples out there dive right into authentication, which isn’t a good place for the newbie to start as it isn’t required for many applictions.

A better place to start, in my option, is to just get a set of photos, and return data about the photos. Extremely useful, dead simple. Here goes.

  1. public static var FLICKR_API_KEY:String         = "whatever your api string is";
  2. public static var FLICKR_API_SECRET:String      = "whatever your api secret is";
  3.  
  4. public var flickrService:FlickrService = new FlickrService(FLICKR_API_KEY);
  5.  
  6.  
  7. private function startFlickr():void
  8. {
  9.        
  10.         flickrService.secret = FLICKR_API_SECRET;
  11.         flickrService.addEventListener( FlickrResultEvent.PHOTOSETS_GET_PHOTOS, onPhotosetGetPhotos);
  12.         flickrService.photosets.getPhotos(‘a set id number goes here’);
  13.        
  14. }
  15.  
  16. private function onPhotosetGetPhotos (event:FlickrResultEvent):void
  17. {
  18.         var photoSet:PhotoSet = event.data.photoSet;   
  19.         photos = new ArrayCollection (photoSet.photos);
  20.  
  21.         for each (var p:Photo in photos)
  22.         {
  23.                 trace(p.title);
  24.                 trace(p.id);
  25.         }
  26. }

Post a Comment

Your email is never published nor shared. Required fields are marked *