/** * Class: MyTweenedPhotos * * Very simple class that connects to flickr.com using the Flashr library and * get's the last 16 photos for a given user and loads them into position on a * nice grid. * * Compile using MTASC and the provided ANT file (build.xml). You will need to * edit the classpath in the ANT file for this to work. * * Or compile using MTASC and the following commandline (assuming that MTASC is in * your PATH and you have edited the classpath): * * (start code) * mtasc.exe -header 305:305:25:000000 -main -swf ../deploy/UserRecentPhotos.swf -cp "C:\Documents and Settings\kelvinl\Local Settings\Application Data\Macromedia\Flash MX 2004\en\Configuration\Classes" com\kelvinluck\flickr\example\UserRecentPhotos * (end) * * Or by executing the provided .bat file (again assuming that MTASC is in your PATH * and you have edited the classpath). * * Or compile using the Flash IDE by simply loading the provided .fla file and exporting. * * Author: * Kelvin Luck * * See Also: * * * * Changes by Petit: Changed file and class name to MyTweenedPhotos.fla / as and all references within the class * Changed the API key to mine ( not activated ?) and the NSID to mine. * Added Tweens to upscale images in the matrix on mouse roll over */ 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; // Import the Tween class and the easing package import mx.transitions.Tween; import mx.transitions.easing.*; class com.petitpub.flickr.MyTweenedPhotos { /** * Variable: apiKey * Your API Key. * * See Also: * **/ var apiKey:String = "9ee44835b39e2f49deb3c82944ce776c"; //original key : 92502cc96511a84c1cfdbf990b71e8c1 /** * Variable: userNsid * The NSID of the user whose photos you want to get **/ var userNsid:String = "94579227@N00"; // original user: 51035610516@N01 /** * Variable: _target * The MovieClip to attach the photo thumbnails to **/ var _target:MovieClip; /** * Variable: xMax * Max horisontal value for left upper corner of a zoomed image **/ var xMax = 38; /** * Variable: yMax * Max vertical value for left upper corner of a zoomed image **/ var yMax = 76; /** * Variable: xTemp, yTemp * Temporary original x, y position values for images **/ var xOrg:Number; var yOrg:Number; /** * Function: MyTweenedPhotos * Constructor **/ function MyTweenedPhotos(target:MovieClip){ // target is _root here 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, 12,1); // changed from (,,16,) } /** * Function: onPeopleGetPublicPhotos * Called when the _flickrResponseListener hears a response to flikr.people.getPublicPhotos * * Parameters: * p - The whose 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 = (i%3) * 38; // changed i%4 -> i%3 mc._y = Math.floor(i/3) * 38; // changed i/4 -> i/3 -> matrix 3 wide 4 high and distance // 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._xscale=mc._yscale=49; // trying to scale but ought to resample mc.photo = thisPhoto; // We have to set this for every mc for the event handlers mc.xOrg = mc._x; // Original x-posion mc.yOrg = mc._y; // Original y-posion mc.xMax = xMax; // Maximum x-position when zooming mc.yMax = yMax; // Maximum y-position when zooming // Ready to zoom the first image //var zooming:Boolean = false; mc.zooming=false; // The first free depth to lift the zooming image to the top var freeDepth=(_root.getNextHighestDepth()); // add the onPress to this movieclip to link to the relevant photo on flickr.com mc.onPress = function(){ getURL(this["photo"].photoPageUrl, "_blank"); }; // Add the onRollOver event handler to zoom the image mc.onRollOver = function(){ var intv; // Swap this mc to first free depth this.swapDepths(freeDepth); var x = Math.min(this.xOrg, this.xMax); var y = Math.min(this.yOrg, this.yMax); // Tween the MovieClip if not already zooming if(!this.zooming){ this.zooming=true; // We are indeed zooming var obj=this; var mcXPos = new Tween(this, "_x", Regular.easeIn, this.xOrg, x, 0.5, true ); var mcYPos = new Tween(this, "_y", Regular.easeIn, this.yOrg, y, 0.5, true ); var mcXScale = new Tween(this, "_xscale", Regular.easeIn, 49, 100, 0.5, true); var mcYScale = new Tween(this, "_yscale", Regular.easeIn, 49, 100, 0.5, true); mcYScale["onMotionFinished"] = function(){ intv = setInterval(restore, 1000, obj); } } // Restore all positions function restore(mc){ clearInterval(intv); mcXPos.rewind(); mcYPos.rewind(); mcXScale.rewind(); mcYScale.rewind(); mc.zooming=false; // We're ready to zoom again } } } } /** * Function: main * Entrypoint to the application. **/ public static function main():Void { var u:MyTweenedPhotos = new MyTweenedPhotos(_root); } /** * Function: toString **/ public function toString():String { return "[com.petitpub.flickr.MyTweenedPhotos]"; } }