/** * Class: MyAutoTweenedPhotos * * 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 MyAutoTweenedPhotos.fla / as * Changed the API key to mine ( not activated ?) and the NSID to mine. * Added Tweens to upscale images in the matrix on setInterval */ 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.MyAutoTweenedPhotos { /** * 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 MyAutoTweenedPhotos(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,) } // end constructor /** * 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; var zooming:Boolean = false; 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 //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"); } // End onPress //select(); } // End for var start = setInterval(select, 3000); var sel:Number; var last:Number; function select(){ // select an image too zoom do{ sel = Math.round(Math.random() * photosArray.length); }while ( sel == last ); last = sel; zoomIt(_root["photo" + sel]); } function zoomIt(obj){ var intv; // Tween the MovieClip if not already tweening if(!zooming){ // Swap this mc to first free depth obj.swapDepths(freeDepth); zooming=true; // We are zooming var x = Math.min(obj.xOrg, obj.xMax); var y = Math.min(obj.yOrg, obj.yMax); var mcXPos = new Tween(obj, "_x", Regular.easeIn, obj.xOrg, x, 0.5, true ); var mcYPos = new Tween(obj, "_y", Regular.easeIn, obj.yOrg, y, 0.5, true ); var mcXScale = new Tween(obj, "_xscale", Regular.easeIn, 49, 100, 0.5, true); var mcYScale = new Tween(obj, "_yscale", Regular.easeIn, 49, 100, 0.5, true); mcYScale["onMotionFinished"] = function(){ intv = setInterval(restore, 2000, obj); } // End omMotion.. } // End if // Restore all positions function restore(mc){ clearInterval(intv); mcYPos.rewind(); mcXPos.rewind(); mcXScale.rewind(); mcYScale.rewind(); // Ready to zoom again zooming=false; }// End restore } // End zoomIt } // End onPeople ... /** * Function: main * Entrypoint to the application. **/ public static function main():Void{ var u:MyAutoTweenedPhotos = new MyAutoTweenedPhotos(_root); } // End main /** * Function: toString **/ public function toString():String { return "[com.petitpub.flickr.MyAutoTweenedPhotos]"; } // end toString } // End class