In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: forked from: Flaxor

ok, this thing sucks :( but, hey, it loads random Flickr thumbnail
Get Adobe Flash player
by makc3d 07 Mar 2009
// ok, this thing sucks :( but, hey, it loads random Flickr thumbnail
package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.*
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	[SWF(width="465",height="465",backgroundColor = "#000000", frameRate = "50")]
	public class Main extends Sprite
	{
		public var canvas : BitmapData;
		public var random : BitmapData;
		public var sw : int = 465, sh : int = 465, timer:Number = 0;
		public var feed:String = "http://api.flickr.com/services/feeds/photos_public.gne";
		public var image:Loader;
		
		public function Main()
		{
			stage.scaleMode = "noScale";
			stage.align = "TL";

			// get random image thumbnail from flickr
			var loader:URLLoader = new URLLoader;
			loader.addEventListener (Event.COMPLETE, onFeedLoaded);
			loader.load (new URLRequest (feed));
		}

		private function onFeedLoaded (e:Event) : void {
			var loader:URLLoader = URLLoader (e.target);
			loader.removeEventListener (Event.COMPLETE, onFeedLoaded);

			// we need to parse http://whatever_m.jpg out
			var r:RegExp = /(http[^\&]+\_m\.jpg)/g
			var s:String = loader.data.toString ().split ("\n").join ("");
			var a:Array = s.match (r);

			image = new Loader ();
			image.contentLoaderInfo.addEventListener (Event.INIT, init);
			image.load (new URLRequest (a [0])); 
		}
		
		public function init (e:Event) : void
		{
			var info:LoaderInfo = LoaderInfo (e.target);
			// does anyone knows how to deal security here?
			// data = Bitmap (info.content).bitmapData;

			info.removeEventListener (Event.INIT, init);
			image.scaleX = image.scaleY = 465 / image.width; addChild (image);

			canvas = new BitmapData(sw, sh, false);
			// addChild( new Bitmap(canvas) );

			addEventListener("enterFrame", loop);
		}
		
		public function loop (e:Event) : void
		{
			var S:Number = Math.sin (timer); S *= S; S += 1;
			timer += 0.1; if (timer > 6.2831853) timer -= 6.2831853;

			canvas.lock();
			
			for (var xx:int = 0; xx < sw; xx++) {
				var xx2:Number = xx * xx;
				for (var yy:int = 0; yy < sh; yy++)
					canvas.setPixel(xx, yy, (xx2 + yy * yy) * S);
			}
			
			canvas.unlock();

			image.filters = [ new DisplacementMapFilter(canvas, null, 4, 4, 4, 4) ]
		}	
	}
}