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

Glitch!!

マウスクリックでリセット
/**
 * Copyright alpicola ( http://wonderfl.net/user/alpicola )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mtGt
 */

// マウスクリックでリセット

package {
	import flash.display.Sprite;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.URLLoader;
	import flash.utils.ByteArray;

	[SWF(backgroundColor="#000", frameRate="10")]
	
	public class Glitch extends Sprite {

		private const HEADER:int = 128;

		private var data:ByteArray;
		private var origin:ByteArray;
		private var display:Loader;

		public function Glitch() {
			//stage.align = "TL";
			stage.scaleMode = "noScale";

			display = new Loader();
			addChild(display);
 
			var loader:URLLoader = new URLLoader();
			loader.dataFormat = "binary";
			loader.addEventListener(Event.COMPLETE, onComplete);
			loader.load(new URLRequest("http://farm4.static.flickr.com/3237/3115234921_ee3e5f90e4.jpg"));
		}

		private function onComplete(e:Event):void {
			origin = e.target.data;
			data = new ByteArray();
			data.writeBytes(origin)
			addEventListener(Event.ENTER_FRAME, loop);
			stage.addEventListener(MouseEvent.MOUSE_DOWN, reset);
		}
  
		private function loop(e:Event):void {
			data.position = Math.floor((data.length - HEADER) * Math.random()) + HEADER;
			data.writeByte(0);
			display.loadBytes(data);
		}

		private function reset(e:Event):void {
			data.clear();
			data.writeBytes(origin);
		}
	}
}