kelvinluck.com

a stroke of luck

Flashr demo


Update

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

This is a small test file which allows you to call different methods of the flickr API through Flashr and see the data structures returned.

You can view the debug information returned from each call in the panel below which is a Luminic Box Flash Inspector. Select the method you want to call from the drop down and then fill in any arguments that are required. Then click the submit button to connect to flickr.com and get the results. Use my documentation to make more sense of the required arguments and returned values.

Warning – I’ve noticed that the Flash Inspector doesn’t work if more than one instance is open at once – make sure you only have one instance of it running while doing this test… If you just see a blank space below check there is no other Flash Inspector running (in another browser or as a panel in the IDE for example) then refresh.

Update – I have made a standalone version of this demo which connects to SOS for improved logging performance (quicker output, horizontal scrollbar and you can copy and paste the logged text). Download it here.

As always, comments and feedback appreciated below or via email…



Flashr 0.2 released


Update 2:

This is a very old page imported from my previous blog. If there is missing content below or anything that doesn’t make sense then please check the page on my old blog.

Update

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

Flashr is the shiny new name for my Flash AS2 wrapper for the Flickr API. Version 0.2 of it has just been released, including support for the new auth scheme and much more.

Prompted by the update of the user authentication system and by getting back from 3 months holiday I have just updated Flashr. The main changes are where authentication is involved but I also made a number of other changes to the code. Certain things became a lot easier with the new system as you now know who the logged in user is.

Unfortunately some of the changes I made will require people using the library to change some of their code. For example, a lot of API functions which return a list of photos now support the “extras” parameter and I have placed this at the start of the parameters list. This is where it falls in the API documentation on flickr.com and I thought that it was more useful to stick with this than to retain backwards compatibility with old code.

However, at this time the code moves out of alpha and into beta so it should be the last time such radical and unbackwardscompatible changes are made to the library. The Flickr API itself is also maturing now and so should become relatively stable.

Go and check out the new library here or if you want to see it in action then jump straight into a demo.



New flickr API demo


Update 2:

This is a very old page imported from my previous blog. If there is missing content below or anything that doesn’t make sense then please check the page on my old blog.

Update:

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

This is a small test file which allows you to call different methods of the flickr API through my flash wrapper class and see the objects that are returned.

You can view the debug information returned from each call in the panel below which is a Luminic Box Flash Inspector. Select the method you want to call from the drop down and then fill in any arguments that are required. Then click the submit button to connect to flickr.com and get the results. Use my documentation to make more sense of the required arguments and returned values.

Warning – I’ve noticed that the Flash Inspector doesn’t work if more than one instance is open at once – make sure you only have one instance of it running while doing this test… If you just see a blank space below check there is no other Flash Inspector running (in another browser or as a panel in the IDE for example) then refresh.

Note – In order to directly connect to flickr.com from a flash file on your domain as I do you will have to speak to the nice people at flickr.com about getting your domain added to their crossdomain.xml file (due to flash’s inbuilt security restrictions).




A couple more notes…

  • When Pablo has done the changes I suggested to the Luminic Flash Inspector then hopefully the output above will be a little more useful.
  • The Flash Inspector is set to a maximum display depth of 4 so when you drill down into objects it may sometimes seem that you have found an empty object within them but this is just because that depth isn’t being displayed…

As always, comments and feedback appreciated below or via email…



A new way to browse Flickr


Update:

This is a very old page imported from my previous blog. If there is missing content below or anything that doesn’t make sense then please check the page on my old blog.

Felix Turner of Airtight Interactive has been playing with the Flickr API and has come up with a cool new way to browse flickr.

Great work and great use of the API… It really inspires me to actually get around to making something :)



Excellent Flash debugging tool


Update 2:

This is a very old page imported from my previous blog. If there is missing content below or anything that doesn’t make sense then please check the page on my old blog.

much more up to date article on debugging from Flash.

The other day I came across the excellent luminicbox.log API for logging from Flash (english machine translation).

This is an API and debugger which will make your life as a Flash developer many many times easier. Rather than using the trace command you can Log messages to a LuminicBox.Log.Logger which will then use an “IPublisher” to output the logged message.

It comes with an IPublisher which outputs to the trace window in the Flash IDE (but pretty prints objects and arrays) as well as the really impressive “Flash Inspector” which allows you to view what the debug messages in a seperate swf. This swf communicates with your swf through a LocalConnection which means that you will be able to debug your application even after it is sitting on the live server. Yay :)

There is one little change that I wanted to make to it though. Whenever I write custom classes I override the default .toString method so that it returns a sensible name for each instance of that class. I wanted to have that displayed for each object that I logged when debugging… This would allow me to see at a glance what was going on in my application. While I’m at it, it would be nice to know how big an array was without having to specifically look at it’s .length.

First I set about adding this functionality to the TracePublisher class. This was easy enough – just change the following line:

txt += "(" + typeOf + ")";
 

to this:

txt += "(";
if (typeOf == "object") txt += o; // o.toString is implicitly called.
else if (typeOf == "array") txt += "array[" + o.length + "]";
else txt += typeOf;
txt += ") ";

Now when I Log my debug messages I see something like this:

*DEBUG*:(array[2]) {
   1:([Object com.kelvinluck.flickr.Photo - 6895531]) {
      contextThumbUrl:"http://photos7.flickr.com/6895531_23190e6e72_s.jpg"
      contextUrl:"/photos/lifeinpixels/6895531/in/photostream/"
      title:"Almost there"
      secret:"23190e6e72"
      id:"6895531"
   }
   0:([Object com.kelvinluck.flickr.Photo - 6895548]) {
      contextThumbUrl:"http://photos8.flickr.com/6895548_7993732d17_s.jpg"
      contextUrl:"/photos/lifeinpixels/6895548/in/photostream/"
      title:"Drop"
      secret:"7993732d17"
      id:"6895548"
   }
}

Now I want to add this functionality to the “Flash Inspector”. In fact, this is where it would be more useful. Because when you trace an Object or Array it is by default callopsed so it would be good to get a bit more information about the item without having to open it out.

Unfortunately I had a look and it looks like to add this functionality would require some editing in the “Flash Inspector” file which isn’t released with the source code. I suggested this improvement to Pablo (the author of this great tool) and he agreed it would be a good idea and is going to look into implementing it… Yay! In my opinion it would make something that is already really cool into something even more useful!

Anyway – props out to Pablo for writing this cool tool and I’ll update here if he makes the changes I suggested…



Embedding flash in TXP


Update:

This is a very old page imported from my previous blog. If there is missing content below or anything that doesn’t make sense then please check the page on my old blog.

Not only does kml_flashembed make it nice and easy to embed Flash files in your textpattern pages – it also produces validating markup and deals nicely with detecting the Flash Player and displaying a message to the user if it isn’t installed. This is thanks to Geoff Stern’s JavaScript which it uses to embed the Flash files.
But… There was a couple of little problems with the plugin. I have error_reporting set to E_ALL on my system and the plugin was throwing a couple of notices due to unset variables.
So I made a few little changes to the code – here it is in it’s new state:

/**
 * Original code from Michael Bester:
 * http://www.kimili.com/journal/32/textpattern-plugin-kimili-flash-embed
 *
 * Slightly adjusted to work when error_reporting is set to E_ALL
 */

function kml_flashembed($atts) {

    if (is_array($atts)) extract($atts);
    $out = array();
    if (!empty($movie) && !empty($height) && !empty($width)) {
        $fversion     = (!empty($fversion)) ? $fversion : 6;
        $target       = (!empty($target)) ? '"'.$target.'"' : '' ;
        $fvars        = isset($fvars) ? explode(";", $fvars) : array();
        $height       = ($height{strlen($height) - 1} == "%") ? '"'.$height.'"' : $height;
        $width        = ($width{strlen($width) - 1} == "%") ? '"'.$width.'"' : $width;
        $id           = isset($id) ? $id : "fm_".$movie; // if no id is provided then default to the name of the swf being embedded which is hopefully unique
        # Convert any quasi-HTML in alttext back into tags
        $alttext      = preg_replace("/{(.*?)}/i", "< >", isset($alttext) ? $alttext : "");

        $out[] = '';
        $out[] = '<script type="text/javascript">';
        $out[] = '    // < ![CDATA[';
        $out[] = '';
        $out[] = '    var flashObject = new FlashObject("'.$movie.'", "'.$id.'", '.$width.', '.$height.', '.$fversion.', "'.(isset($bgcolor) ? $bgcolor : "").'");';
        if (!empty($alttext))        $out[] = '    flashObject.altTxt = "'.$alttext.'"';
        if (!empty($play))           $out[] = '    flashObject.addParam("play", "'.$play.'");';
        if (!empty($loop))           $out[] = '    flashObject.addParam("loop", "'.$loop.'");';
        if (!empty($menu))           $out[] = '    flashObject.addParam("menu", "'.$menu.'");';
        if (!empty($scale))          $out[] = '    flashObject.addParam("scale", "'.$scale.'");';
        if (!empty($quality))        $out[] = '    flashObject.addParam("quality", "'.$quality.'");';
        if (!empty($wmode))          $out[] = '    flashObject.addParam("wmode", "'.$wmode.'");';
        if (!empty($align))          $out[] = '    flashObject.addParam("align", "'.$align.'");';
        if (!empty($salign))         $out[] = '    flashObject.addParam("salign", "'.$salign.'");';
        // Loop through and add any name/value pairs in the  attribute
        for ($i = 0; $i < count($fvars); $i++) {
            $thispair    = trim($fvars[$i]);
            $nvpair      = explode("=",$thispair);
            $name        = trim($nvpair[0]);
            $value       = trim($nvpair[1]);
            $out[]       = '    flashObject.addVariable("'.$name.'", "'.$value.'");';
        }
        $out[] = '    flashObject.write('.$target.');';
        $out[] = '';
        $out[] = '    // ]]>';
        $out[] = '</script>';
        // Add NoScript content
        if (!empty($noscript)) {
            $out[] = '<noscript>';
            $out[] = '    ' . $noscript;
            $out[] = '</noscript>';
        }
        $out[] = '';
    }
    return join("\n",$out);
}

As you can see, the changes are very simple – just making sure that $fvars, $id, $alttext and $bgcolor are defined before they are used.
Here it is in action – embedding a little Flash movie I wrote which connects to the Flickr API to download the 6 most recent photos uploaded to Flickr. Refresh to see more photos – they are uploaded at an alarming rate!

Once again – props to Geoff Stern for his work on this cool and valid way to embed Flash in a page and to Michael Bester for bringing it to TXP in the form of an easy to use plugin.



Another interface between Flash and Flickr


Update 2:

This is a very old page imported from my previous blog. If there is missing content below or anything that doesn’t make sense then please check the page on my old blog.

Update:

Check out Flashr – that’s what this idea grew into…

This page provides an introduction to an interface I am writing between Flash and the Flickr API. It’s something I’ve been thinking about for a while but which got stuck on the back burner. Seeing inspiring stuff like Flickr graph from Marcos Weskamp has made me decide that I should try and get this out there.
After writing this page I’ve realised that it has ended up much longer than anyone probably wants to read… If you aren’t interested in my motivation then skip down to the example and if it looks like something you might be interested in then you can check out the documentation as well – although that’s maybe even longer.

WHY????
But there are already (at least 2) Flash interfaces to the Flickr API! Why would we need another one?
I started out using flickr api and found it useful. Then I came across a method on the Flickr API which hadn’t yet been implemented in “flickr api”. So I implemented it myself. But doing this I became frustrated and decided there must be an easier way…
I wanted an API which could give me variable type checking on all the things I was passing to Flickr and which would do any necessary XML parsing for me without me having to think about it.
I also wanted it to run in the Flash Player 6 (mamata’s “flickr api” could be fairly easily adjusted for this). And ideally to have things in place like a queue so I didn’t need to worry about waiting for one request to complete before sending the next one.
Another aim was to have good documentation so that someone could sit down with this system and by writing minimal AS2 code could have an application that interfaced with Flickr. The long term aim of all this is to be able to sit down and write some cool applications using the Flickr API… But first things first.

HOW?
So how does my interface work? See the documentation for the gory details. [sidenote - I did the docs with Natural Docs - pretty cool actually!]
Basically there are two core classes: com.kelvinluck.flickr.Flickr and com.kelvinluck.flickr.FlickrResponseListener. The idea is that you create a Flickr object which you can then call methods on. This ensures that type checking can be done when making API calls to Flickr to catch author time errors. You then have an instance of FlickrResponseListener which listens for the responses from the Flickr API. By itself that isn’t much good for you – it just logs some messages (thanks to Colin Moock’s Logger application). But the idea is that you would either subclass FlickrResponseListener or would create an instance and override the methods that you are interested in.
I assume that this approach to this type of problem has been used before and has a name but I’m afraid I don’t know it. It’s kind of like an Java style interface in that I am describing what I expect the function you will write to accept as arguments although the compiler obviously won’t enforce this. You will, however, have the documentation and an argument list for your function so it should make it fairly easy to write the code…

EXAMPLE!
Here is an example of my interface (damn – I need to come up with a more catchy name!) in action. Basically the drop down lets you pick from the functions of the API I have programmed (so far flickr.contacts.*, flickr.people.*, flickr.tags.* and flickr.test.*). Then the two text fields are the two (optional) arguments to the function you are calling. Your call and response are logged to the big TextArea. You can change the severity of the messages logged with the ComboBox at the top of the screen.

The relevant code in this example application is very simple:

// on the first frame
import com.kelvinluck.flickr.Flickr;
import com.kelvinluck.flickr.FlickrResponseListener;
var _flickr:Flickr = Flickr.getFlickr();
_flickrResponseListener = new FlickrResponseListener();
_flickr.apiKey = "YOUR_API_KEY";

// and on the event handler for the "Go" button
_flickr[command_cb.selectedItem.label](arg1.text, arg2.text);
 

You can see that the application takes a lot of the legwork out of talking to Flickr. When you see stuff like “[Object com.kelvinluck.flickr.Person - 51035610516@N01]” in the output that is because the Person.toString method is being called. As you will see if you switch the log level to DEBUG, there is more data stored along with that person…

DOWNLOAD
But where is the code? I’m going to release it when it is a little bit more finished. I wanted to show the docs and example at this stage to try and gather some feedback on the general approach.
Do people think my approach is useful – would you be more likely to use this library than one of the existing ones? What do you think is good/bad about this way of approaching the problem? Have you got any suggestions for a better way of structuring the code given the requirements?
If someone can convince me that another approach to the problem is better then they will save me the time I’ll spend adding the rest of the API calls to the library. If people like the approach it might give me the kick up the arse I need to get round to completing this… So – feedback of any sort appreciated! Use the comments form below or email me – kelvin at kelvinluck dot com :)