COLOURlovers is a really cool community for sharing colors. You can find hundreds of thousands of color palettes and patterns. There's also a nice RSS/XML API (COLOURlovers API) to access the content. I really like those kind of flash-friendly APIs, so I couldn't resist to write some Flash classes. With COLOURlovers API for Flash you can easily use the functions of the XML API in ActionScript.

Examples

Let's start with some examples:

The first examples load a single palette by an id.

The second one shows you a standard feed with twenty palettes. Click the "next" button to move forward.

Same example as before, but with patterns (not palettes).


This examples filters for the creator name (COLOURlover in this case).

This one shows a palette badge.

This one shows a pattern badge.

At a glance

COLOURLovers API for Flash implements all the features of the COLOURLovers API provided by colourlovers.com (only for palettes and patterns at the moment). COLOURLovers API for Flash at a glance:

  • Written in ActionScript 3
  • You can use it with Flash and Flex
  • Load all the available feed types provided by COLOURLovers
  • Access to all properties of the palettes and patterns
  • Filter/Search queries for lovers, colors, etc.
  • Documentation included
  • Under Creative Commons License

Code example

Let me give you a simple example how to load a single palette.

Actionscript:
  1. import com.florianplag.*;
  2.  
  3. // new palettes object
  4. var myPalettes:ColourLoversPalettes = new ColourLoversPalettes();
  5.  
  6. // load single palette by id
  7. myPalettes.loadPalette(173630);
  8.  
  9. // add event listeners for success
  10. myPalettes.addEventListener (Event.COMPLETE, onComplete);
  11.  
  12. function onComplete(evt:Event):void {
  13.        
  14.     trace ("title: " + myPalettes.result[0].title );
  15.    
  16.     trace (myPalettes.result[0].colors[0]);
  17.     trace (myPalettes.result[0].colors[1])
  18.     trace (myPalettes.result[0].colors[2]);
  19.     trace (myPalettes.result[0].colors[3]);
  20.     trace (myPalettes.result[0].colors[4])
  21. }


That's it!

Loading palettes and patterns

Start with a new Object (ColourLoversPalettes or ColourLoversPatterns). There a different methods to load a set of palettes (same for patterns), e.g. loadPalettes, loadPalettesNew, loadPalettesTop and loadPalettesRandom.

To wait for the results, just add an event listener to your object. The Event.COMPLETE is triggered, when the feed from colourlovers.com is completely loaded and successfully parsed. For errors events, have a look in the examples.

The result

The result is always stored in an array called result (for instance myPalettes.result). For each palette/pattern that is delivered, you just have to set the number in the square brackets (e.g. result[0].badgeUrl for the first , result[1].badgeUrl for the second, ...) to access the different palettes/patterns. The number of items in the result can be found out using the method myPalettes.result (e.g. 20, if there are 20 palettes in the feed).

Properties

Each result has the complete set of properties, that is provided by the COLOURlovers API (id, title, description, numView, etc.). For an overview, please have a look in the documentation.

Feedback, Bugs, Improvements

This is the first version. I havent't had the time to check all properties in details. If you find bugs, please leave a comment. The ActionScript could also be improved a little because there's some redundancy between the patterns and palettes code.

Download

Attribution-Noncommercial-Share Alike - http://creativecommons.org/licenses/by-nc-sa/3.0/
If you would like to use the API in ways outside of this license please contact me for permission. Please consider the license of COLOURLovers API, too.

Download: COLOURLovers API for Flash 0.1 (Flash classes, examples, documentation)