A problem occured while loading the plugin: krl_flickr_photoset -> : Assigning the return value of new by reference is deprecated on line 18
kelvinluck.com: Flashr code example
Get Firefox! creative commons

Flashr code example

Update

For the latest up to date information about Flashr please check out the new Flashr microsite

Update: This example will no longer work as-is – you will need to update your Flashr files as described here.

I’ve put together a very simple example which demonstrates how easy it is to talk to the flickr API using Flashr.

First up, here is the finished product. It basically connects to flickr.com and gets a list of the 16 most recent photos for a given user (me in this case) and displays them all in a nice little grid.

Sorry, you require Flash 7 to view this movie.

The code to create this simple movie is extremely simple… Here it is in it’s entirety:

ActionScript:
/**
* Class: UserRecentPhotos
*
* Author:
* Kelvin Luck
*
* See Also:
* <http://www.kelvinluck.com/projects/flashr-a-flickr-api-wrapper-for-flash>
*/


import com.kelvinluck.flickr.Flickr;
import com.kelvinluck.flickr.FlickrResponseListener;
import com.kelvinluck.flickr.Person;
import com.kelvinluck.flickr.Photo;
import com.kelvinluck.util.LogWrapper;
import com.dynamicflash.utils.Delegate;

class com.kelvinluck.flickr.example.UserRecentPhotos
{
       
        /**
        * Variable: apiKey
        * Your API Key.
        *
        * See Also:
        * <http://www.flickr.com/services/api/misc.api_keys.html>
        **/

        var apiKey:String = "REPLACE_ME";
        /**
        * Variable: userNsid
        * The NSID of the user whose photos you want to get
        **/

        var userNsid:String = "51035610516@N01";
        /**
        * Variable: _target
        * The MovieClip to attach the photo thumbnails to
        **/

        var _target:MovieClip;
       
        /**
        * Function: UserRecentPhotos
        * Constructor
        **/

        function UserRecentPhotos(target:MovieClip)
        {
                Stage.scaleMode = "noScale";
               
                // initalise logging to Flash's output window
                LogWrapper.getInstance().init();
                LogWrapper.getInstance().addTracePublisher();
               
                _target= target;
                var _flickr:Flickr = Flickr.getFlickr();
                _flickr.apiKey = apiKey;
                var _flickrResponseListener:FlickrResponseListener = new FlickrResponseListener();
                _flickrResponseListener.setSuppressOutput(true);
                _flickrResponseListener.onPeopleGetPublicPhotos = Delegate.create(this, onPeopleGetPublicPhotos);
                _flickr.peopleGetPublicPhotos(userNsid, null, 16,1);
        }
        /**
        * Function: onPeopleGetPublicPhotos
        * Called when the _flickrResponseListener hears a response to flikr.people.getPublicPhotos
        *
        * Parameters:
        * p                                        -        The <Person> whose <Photo>s you just got.
        **/

        function onPeopleGetPublicPhotos(p:Person):Void
        {
                var photosArray:Array = p.getPhotos();
                var userNsid:String = p.nsid;
                for (var i:Number=0; i<photosArray.length; i++) {
                        var thisPhoto:Photo = Photo(photosArray[i]);
                       
                        // create a movieclip to load the photo into
                        var mc:MovieClip = _target.createEmptyMovieClip("photo"+i, i);
                       
                        // position the clips so they form a nice grid
                        mc._x = 1 + (i%4) * 76;
                        mc._y = 1 + Math.floor(i/4) * 76;
                        // create a nested movieclip so that our onPress isn't overwritten by the jpg as it loads
                        mc.createEmptyMovieClip("jpgHolder", 1);
                        // and load the jpeg into it
                        mc.jpgHolder.loadMovie(thisPhoto.thumbnailUrl);
                       
                        mc.photo = thisPhoto;
                       
                        // add the onPress to this movieclip to link to the relevant photo on flickr.com
                        mc.onPress = function()
                        {
                                getURL(this["photo"].photoPageUrl, "_blank");
                        };
                }
        }
        /**
        * Function: main
        * Entrypoint to the application.
        **/

        public static function main():Void
        {
                var u:UserRecentPhotos = new UserRecentPhotos(_root);
        }
        /**
        * Function: toString
        **/

        public function toString():String
        {
                return "[com.kelvinluck.flickr.example.UserRecentPhotos]";
        }
}

As you can see, an instance of Flickr and an instance of FlickrResponseListener are created. Then _flickr.peopleGetPublicPhotos is called. When a response is returned by flickr.com, _flickrResponseListener.onPeopleGetPublicPhotos is triggered. This function is passed a Person object. We can get this person’s photos with a simple call to Person.getPhotos. We then loop over those photos loading them into movieclips.

And that’s how easy it is! You can download the files used in this demo from here – there is instructions for building with MTASC or the Flash IDE. The file that you will be interested in looking at is com.kelvinluck.flickr.example.UserRecentPhotos.as.

Update:
Petit as written a step by step tutorial showing how to use this code as a basis for a copy of the flickr badge.

  1. I tried the test app, and it doesn’t seem to heave MD5 in it. Any ideas?

    srccomkelvinluckflickrFlickr.as: Line 495: There is no method with the name ‘MD5’.
    return MD5.calculate(signature);

    Total ActionScript Errors: 1 Reported Errors: 1
    — Armin    Sep 30, 05:45    #
  2. Hi,

    You will need to go to the Flashr page and look under requirements…

    Alternatively, yesterday I released a new version via Subversion with a packaged MD5 class – more info on the here – from the Flashr mailing list

    Cheers,
    Kelvin    Sep 30, 10:04    #
  3. I’m on a mac and I can’t get it to work. I installed the ASCrypt extension and tried to preview the files you have here and nothing happens. I’m kind of a n00b at this kind of stuff. Can you do a step-by-step on what exactly I’m supposed to do/install? Thanks!
    james    Oct 20, 19:25    #
  4. Hi,

    How are you trying to preview the files? Are you opening up the fla in Flash? Are you getting any errors?

    Please join the mailing list and ask the question there with a few more details of what you are doing (which file you are opening in what, what happens when you compile it, any errors etc),

    Cheers :)
    Kelvin    Oct 20, 19:32    #
  5. In the new version via Subversion with a packaged MD5 class – you need to change the as code from getUrl() to getURL() as the first syntax is incorrect / doesnt work. Might put off / confuse new flash coders etc.

    I’ve done it many times myself!!!

    Tucking into Flashr as we speak, I am a Flash UI Consultant / Developer!

    Will be in touch.
    Richard Max    Dec 8, 12:55    #
  6. Hi,
    Cheers for the headsup – not sure where the lowercase URL crept in from… I’ll fix it when I get a moment on my machine at home…

    Enjoy Flashr and make sure to let me know what you make with it :)
    Kelvin    Dec 8, 13:26    #
  7. Hi, sorry for being the one asking stupid questions but….
    I’m trying to get your example to work, but I end up with an black swf.. I’m compiling the example using the flash mx2004 interface, I get no errors. But the images are not loading.
    Ed    Jan 5, 13:11    #
  8. Ok so I need to fiddle around with API key and export for the right flash version… It is working now. Great stuff!!
    Ed    Jan 5, 13:21    #
  9. Cool – glad you figured it out so quickly!

    Have fun :)
    Kelvin    Jan 5, 13:29    #
  10. Thanks Kelvin, for a great piece of work! Check out my first little app. at http://pentdego.com
    Keep up the great work.
    Ed    Jan 11, 19:57    #
  11. Hello Kelvin,
    I’m learning and experimenting with your example. But the ony thing which doesn’t work is that when you click on a thumbnail they all go to the last photo in the grid. when i trace(thisPhoto.photoPageUrl);
    in the function:
    onPeopleGetPublicPhotos
    it works well but when i do the same in the onPress function the var thisPhoto is always the last one. Do you know what’s wrong, or isn’t this wrong after all.
    Cheers from Amsterdam,

    Marien
    Marien    Jan 15, 16:47    #
  12. Hi Marien,
    Sorry – my bad! I’ve fixed the problem you found – the new code is above,
    Cheers,
    Kelvin :)
    Kelvin Luck    Jan 15, 20:59    #
  13. Hi Kelvin,

    Newbie here. Trying to get the viewer to work but getting a black screen. I have changed the keys in the .as file and exported using Flash but still no luck.

    Thanks,

    rwg
    — Roger W. Geyer    Jan 22, 22:45    #
  14. Hi Roger,

    Sorry for the slow response… Are you still having issues? I just downloaded the files and exported without any problems… Do you see anything in Flash’s output window? Does it work if you leave my API Key and user id in? What version of Flash are you exporting from?

    If you are still having issues then please join the mailing list where we will be able to help you out…

    Thanks,
    Kelvin Luck    Jan 26, 10:14    #
  15. I also have the MD5 problem…

    *Error* E:DataClassME310FlashFlashrRecentPhotossrccomkelvinluckflickrFlickr.as: Line 495: There is no method with the name ‘MD5’.
    return MD5.calculate(signature);

    Total ActionScript Errors: 1 Reported Errors: 1
    — hiten    Mar 4, 07:53    #
  16. Hi Kelvin,
    I’m really inexperienced with using external actionscript. Could you tell me which folder the files go in? Thanks!
    Nick    Mar 4, 13:07    #
  17. Hi Guys,

    Re. the MD5 problem, this demo was actually made using an old version of Flashr which had a reliance on an extra library to provide MD5 hashing to generate authenticated flickr.com URLs. I have just re-uploaded the zip file and it now uses a library which is included in the zip. Please download and try again.

    Nick – the files can go in any folder, the important thing is that they go in the same folders relative to each other.

    Hope this helps,

    Thanks,
    Kelvin Luck    Mar 4, 14:21    #
  18. Kelvin, when I try to run the file in the zip, these errors occur:

    *Error* C:Documents and SettingsNickMy DocumentsDownloadedFlashrRecentPhotosFlashrRecentPhotossrccomkelvinluckflickrFlickr.as: Line 86: The name of this class, ‘com.kelvinluck.flickr.Flickr’, conflicts with the name of another class that was loaded, ‘com.kelvinluck.flickr.Flickr’.
    class com.kelvinluck.flickr.Flickr {

    *Warning* C:Documents and SettingsNickMy DocumentsDownloadedFlashrRecentPhotosFlashrRecentPhotossrccomkelvinluckflickrFlickrResponseListener.as: Line 53: There is no class or package with the name ‘com.kelvinluck.flickr.Flickr’ found in package ‘com.kelvinluck.flickr’.
    Flickr.getFlickr().addEventListener(“onAPIResponse”, this);

    *Warning* C:Documents and SettingsNickMy DocumentsDownloadedFlashrRecentPhotosFlashrRecentPhotossrccomkelvinluckflickrFlickrResponseListener.as: Line 661: There is no class or package with the name ‘com.kelvinluck.flickr.Flickr’ found in package ‘com.kelvinluck.flickr’.
    LogWrapper.getLog().info(Flickr.getFlickr().authUser);

    *Warning* C:Documents and SettingsNickMy DocumentsDownloadedFlashrRecentPhotosFlashrRecentPhotossrccomkelvinluckflickrFlickrResponseListener.as: Line 1514: There is no class or package with the name ‘com.kelvinluck.flickr.Flickr’ found in package ‘com.kelvinluck.flickr’.
    if (eventObject.status == Flickr.STATUS_OK) {

    *Warning* C:Documents and SettingsNickMy DocumentsDownloadedFlashrRecentPhotosFlashrRecentPhotossrccomkelvinluckflickrPhoto.as: Line 439: There is no class or package with the name ‘com.kelvinluck.flickr.Flickr’ found in package ‘com.kelvinluck.flickr’.
    Flickr.getFlickr().authUser.addTag(thisTag);

    Total ActionScript Errors: 5 Reported Errors: 5

    What does this mean?
    Nick    Mar 4, 16:06    #
  19. Hmm – looks like there may be an issue with your ASO files not being deleted (this can happen when you open files that were created in different time zones). Here is a description of the problem – to fix it grab an the ASO Cache clearing commands and install and run “Clear ASO Cache and Compile”.
    If you have any further problems please ask on the mailing list which is a better place for getting help with Flashr,

    Cheers,
    Kelvin Luck    Mar 4, 16:14    #
  20. Hello Kelvin, weird issue… my .fla will compile and work on a PC (both the .swf in the standalone projector and in browser) but not on a Mac, except for a PC compiled swf in browser. The same .fla will NOT compile on my Mac or run in the standalone! Same code, too… any ideas?

    I get the Mac compile error: *Error* Scene=Scene 1, layer=Layer 1, frame=1:Line 9: The class or interface ‘Flickr’ could not be loaded. var _flickr:Flickr = Flickr.getFlickr(); Total ActionScript Errors: 1 Reported Errors: 1

    thanks,
    Geoff Brown    Mar 27, 22:09    #
  21. How do yo find the users NSID?
    kyle    Mar 28, 02:10    #
  22. Kelvin, I reinstalled OSX and Flash and now everything is all good. Must have been a permissions problem or whatnot. Thanks-gb
    Geoff Brown    Mar 28, 06:21    #
  23. Hi guys, sorry for the slow response – just got back from Holiday :)

    @Geoff – glad it sorted itself out :)

    @Kyle – there are a number of ways… If you want to do it in Flashr then check out peopleFindByEmail or peopleFindByUsername.

    Cheers,

    Kelvin
    Kelvin Luck    Apr 3, 23:08    #
  24. Thank you Kevin, this is really a great example. I used it in my blog and it works!!! Thank you a lot….
    Jialing    Apr 8, 03:01    #
  25. is there any way to getEMail by Username?

    i put some more features of this demo.

    look over here:
    http://data.insnet.de/experiments/flickr/imageByUsername.html


    fabian nöthe    Jun 3, 14:53    #
  26. Hi,

    There isn’t a way to get Email by username. I guess this would be an invasion of Flickr users’ privacy so the guys at Flickr left it out…


    Kelvin Luck    Jun 4, 16:55    #
  27. Hello,
    Thanks a lot for your brilliant work, it’s really helpful and generate a lot of creativity.

    I’m playing with it, and got a few problems:
    I don’t get any picture when swf is online. Even you embed flash on this page is black and empty (pc / mac, firefox / IE Flash player 9) but it works fine when swf generated in Flash. Is it only me or did flickr change something in their API recently ? there anything I can do?

    Also, I’m trying to “loadmovie” into an other swf, and I probably didn’t use the _target thing properly to call the function, as the loaded pics are always on _root.
    I tried manually by changing UserRecentPhotos.as:

    var mc:MovieClip = _target.createEmptyMovieClip(“photo”+i, i);

    to

    var mc:MovieClip = _root.site.theleft.loadpics.createEmptyMovieClip(“photo”+i, i);

    and it worked fine. What is the best way to do this ?

    Thanks a lot
    Jonaie


    joanie    Aug 24, 14:43    #
  28. Hi,

    Glad you like Flashr! I’ve literally just this minute done a post which explains the problem you are having with no images showing up.

    Re. your other problem, I’m not sure I quite understand you – can you clarify a little?

    Cheers,


    Kelvin Luck    Aug 24, 15:28    #
  29. Hi, verry good tool – thank you. greets Sven


    Sven Fischer    Feb 6, 08:36    #
  30. hi,

    I tried making a mod of this viewer and it works great when launched locally. However, when I host it in photobucket for web use, it can seem to load the images.
    please check this link
    http://i26.photobucket.com/albums/c135/schmuck03/gioflickr.swf
    try also to save it and launch locally, should work.

    how do I make it work online??

    thanks


    schmuck    Feb 12, 02:54    #
  31. Hi,
    Did you check out this article? It sounds like it has the solution to your problem,

    Cheers,


    Kelvin Luck    Feb 12, 09:30    #
  32. This still isn’t working for me on my server.
    Changed line 112 in Flickr.as:
    private var _AUTH_ENDPOINT:String = “http://flickr.com/services/auth/”;
    to
    private var _AUTH_ENDPOINT:String = “http://api.flickr.com/services/auth/”;

    and changed line 274 in Flickr.as from:

    _REST_ENDPOINT = “http://www.flickr.com/services/rest/”;
    to
    _REST_ENDPOINT = “http://api.flickr.com/services/rest/”;

    Safari’s activity window states that my doc can’t find crossdomain.xml on the flickr server.

    Any help would be appreciated.

    Thanks


    — J    Feb 12, 20:55    #
  33. Hmm – did you recompile and re-upload your swf after doing the changes? Those changes should definitely fix the problem but when I look at the URL you give above I still see it trying to connect to www.flickr.com…


    Kelvin Luck    Feb 12, 21:31    #
  34. Hello Mr. Luck, I try to work with “UserRecentPhotos” and local all the nice flickr things will work. But nothing will work on a server… By the way, I dont see anything in your example in the top.
    Can you help please? Best from Berlin, Alex


    Alex    Jun 21, 12:50    #
  35. Hi Alex,

    Did you see this link at the top of the page? It should tell you how to fix it!

    Also, the information on this page is based on an old version of Flashr. You should check out the newest versions of Flashr / which are better… It shouldn’t be too much work to change the code here to work with the new version…

    Cheers,

    Kelvin :)


    Kelvin Luck    Jun 23, 13:13    #
  36. I got the flashr to work within flash. I can preview the swf and it looks fine. But when i export it to a folder with all corresponding folders/as files it doesnt work. Any thoughts?


    — Chuck    Jan 4, 19:25    #
  37. Hi Chuck,

    That sounds like a security error of some kind. What version of Flashr are you using? Are you using the files downloaded from this page? If so then you need to take into account this change to the security model.

    I’d recommend getting the latest version of Flashr and checking out the tutorials on the new microsite. If you are still having difficulties then please ask on the flashr mailing list.

    Hope that helps,

    Kelvin :)


    Kelvin Luck    Jan 5, 12:52    #
  38. Is there a way to force a specific photoset with this example?

    I have tried but can’t get it to cooperate :(


    — Nik    Mar 17, 14:03    #
  39. Never mind, I’m tweaking the barcamp example now.

    Great stuff BTW :D


    — Nik    Mar 19, 17:54    #
  40. Hi Nik,

    Sorry for the slow response. And cool that you’ve discovered the barcamp example – that is built on a much newer and better version of Flashr than this…

    If you want to get photos from a specific photoset then you should look at the photosetsGetPhotos function,

    Cheers,

    Kelvin :)


    Kelvin Luck    Mar 20, 12:23    #
  41. Thanks Kelvin :)


    — Nik    Mar 28, 16:00    #
  42. Really nice Tool !


    Micha    May 11, 16:13    #
  43. Thanks Kelvin, for a great piece of work! Best regards


    RL    Jun 11, 00:03    #
  44. Thanks for this usefull Tool.


    Alex    Jun 12, 18:27    #
  45. hi kelvin,
    flashr is great and i’m so impressed with how extensive your documentation is. but i had the same question as Nik about getting the gallery to show only certain sets. i looked at the function you mentioned in the link in response to him, and i tried placing that in my code, but i may need a little more instructions. sorry, i’m really not much of a coder.

    here is what i put in:

    //

    function photosetsGetPhotos(photosetId:String =”72157606185185240”):FlashrRequest

    //

    i know there is probably some more code i need to put in, but i’m not really sure what. if you could explain it a little more, that would be great.

    i have gotten the api key and everything else to work just fine so that it is showing my flickr photos.

    thanks!


    — jearley    Jul 15, 21:56    #
  46. Hi Jearly,

    I’d recommend reading Colin Moock’s EAS2 to learn some more about actionscript 2…

    Basically in the example above I call:

    _flickr.peopleGetPublicPhotos(userNsid, null, 16,1);

    Instead you need to call the photosetsGetPhotos function like so:

    _flickr.photosetsGetPhotos(‘72157606185185240’);

    However, you will also have to set up a listener for the corresponding function (onPhotosetsGetPhotos).

    You should make sure you are using the latest version of Flashr too – the version used on this page is very out of date…

    Hope that helps :)


    Kelvin Luck    Jul 21, 22:33    #