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: Glitch

Glitch
By: Ctrl
Get Adobe Flash player
by gupon 26 Mar 2010
/**
 * Copyright gupon ( http://wonderfl.net/user/gupon )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/pE6M
 */

// forked from Ctrl's Glitch
/*
Glitch
By: Ctrl
*/
package 
{
	import flash.display.Sprite;
	import flash.display.Loader;
	import flash.events.*;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.URLLoader;
	import flash.utils.ByteArray;
	import flash.utils.Timer;

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

		private const HEADER:int = 1000;

		private var data:ByteArray;
		private var origin:ByteArray;
		private var display:Loader;
		private var position:int = 0;

		public function Glitch() 
		{
			Wonderfl.capture_delay(9);
			stage.align = "TL";
			stage.scaleMode = "noScale";
 
			var loader:URLLoader = new URLLoader();
			loader.dataFormat = "binary";
			loader.addEventListener(Event.COMPLETE, onComplete);
			loader.load(new URLRequest("http://1.bp.blogspot.com/_McL0_OWcuUs/SxgDqO96y3I/AAAAAAAAAFY/cpbxb2hfFNQ/s1600/pulp_1-565x581.jpg"));
		       
		    display = new Loader();
			addChild(display);
			display.scaleX = .8;
			display.scaleY = .8;
			
		    var time:Timer = new Timer(1500);
		    time.addEventListener(TimerEvent.TIMER, reset);
		    time.start();
		}

		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 = HEADER + ( position+=256 ) % ( data.length - HEADER );
			data.writeByte(0);
			display.loadBytes(data);
		}

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