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: Video_step3 動画を使った演出の一例

落ちるかもしれないんで注意
// forked from wonderfl_external_media's Video_step3 動画を使った演出の一例
// forked from hacker_fuxxpyai's Video_step2 動画情報取得とちょっとコントロール
// forked from hacker_fuxxpyai's Video_step1 とりあえず再生
//落ちるかもしれないんで注意

package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.events.NetStatusEvent;
	import flash.geom.ColorTransform;
	import flash.geom.Transform;
	import flash.geom.Matrix;
	import flash.utils.getTimer;
	import flash.utils.Timer;
	import flash.media.Video;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	import flash.system.Security;
	
	public class Main extends Sprite 
	{
		private var _containerMosic:MovieClip=new MovieClip();
		private var _transformBmd:BitmapData 
		private var _bmd:BitmapData;
		private var _bmp:Bitmap;
		private var _rows:int = 20;
		private var _cols:int = 20;
		private var _cellW:Number;
		private var _cellH:Number;
		private var _transformMatrix:Matrix;
		private var _cellAarry:Array = new Array();
		private var _timer:Timer;
		private var _connection:NetConnection;
		private var _stream:NetStream;
		private var _video:Video = new Video;
		private var _canvas:BitmapData;
		private var _matrixArray:Array = [];
		private const SPLIT_NUM:int = 3;
		private var _videoURL:String = "http://www.muraken.biz/wonderfl/construction.mp4";
		
		public function Main():void 
		{
 			Security.loadPolicyFile("http://www.muraken.biz/crossdomain.xml"); 
			_connection = new NetConnection();
			_connection.addEventListener(NetStatusEvent.NET_STATUS, _netStatusHandler);
			_connection.connect(null);
		}
		
		private function _netStatusHandler(e:NetStatusEvent):void {
			if(e.info.code=="NetConnection.Connect.Success")_connectStream();
			else if(e.info.code=="NetStream.Play.Stop")_stream.seek(0);
		}
		
		private function _connectStream():void {
			_stream = new NetStream(_connection);
			_stream.addEventListener(NetStatusEvent.NET_STATUS, _netStatusHandler);
			_stream.client = this;
			_stream.bufferTime = 3;
			_video.attachNetStream(_stream);
            _stream.play(_videoURL);
			addEventListener(Event.ENTER_FRAME, _onEnterFrame);
			_stream.play(_videoURL);
			_createBitmapData();
			_transformData();
			_createCells();
		}
		private function _onEnterFrame(e:Event):void 
		{
			if (!_canvas) return;
			_canvas.fillRect(_canvas.rect, 0x00000000);
			_canvas.draw(_containerMosic);
			var _mtx:Matrix = _matrixArray[Math.floor((getTimer() / 3000) % SPLIT_NUM)];
			_mtx.ty-=1;
			_mtx.ty%=stage.stageHeight;
			graphics.clear();
			graphics.beginBitmapFill(_canvas,_mtx,true,true);
			graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
			graphics.endFill();
		}
		public function onMetaData(info:Object):void {
			if (!_canvas) {
				_canvas = new BitmapData(info.width, info.height, true, 0x00000000);
				var _scale:Number;
				for (var i:int = 0; i < SPLIT_NUM; i++) {
					_scale = stage.stageWidth / (_canvas.width * (i + 1));
					_matrixArray.push(new Matrix(_scale, 0, 0, _scale));
				}
			}
		}
		public function onCuePoint(info:Object):void {}
		public function onXMPData(info:Object):void { }
		

		private function _createBitmapData():void
		{
			_cellW = _video.width / _cols;
			_cellH = _video.height / _rows;
			_bmd = new BitmapData(_video.width, _video.height, false);
			_bmd.draw(_video);
			_bmp = new Bitmap(_bmd, "auto", true);
			
		}
		private function _transformData():void
		{
			_bmp.width = _cols;
			_bmp.height = _rows;
			_transformMatrix = _bmp.transform.matrix;
			_transformBmd= new BitmapData(_cols, _rows, false);
			_transformBmd.draw(_video, _transformMatrix);
		}
		private function _createCells():void
		{
			for (var i:int = 0; i < _cols; ++i)
			{
				for (var j:int = 0; j < _rows; ++j)
				{
					var sp:Sprite = new Sprite()
					_containerMosic.addChild(sp);
					sp.x = i * _cellW;
					sp.y = j * _cellH;
					sp.addChild(new Bitmap(_transformBmd, "auto", true));
					sp.width = _cellW;
					sp.height = _cellH;
					_cellAarry.push(sp);
				}
			} 
			
			_timer = new Timer(1000/40);
            _timer.addEventListener(TimerEvent.TIMER, _update);
            _timer.start();
		} 
		private function _update(evt:TimerEvent):void
		{
			var _num1:Number;
			var _num2:Number;
			var _num3:Number;
			var _num4:Number;
			var _num5:Number;
			_transformBmd.draw(_video, _transformMatrix);
			var _num9:Number = 0;
			for (var i:int = 0; i < _cols; ++i)
			{
				for (var j:int = 0; j < _rows; ++j)
				{
					_num1 = _transformBmd.getPixel(i, j);
					_num2 = _num1 >> 16 & 255;
					_num3 = _num1 >> 8 & 255;
					_num4 = _num1 & 255;
					_num5 = Math.max(Math.max(_num2, _num3), _num4) / 255 * 100;
					var _obj:DisplayObject = _cellAarry[_num9];
					_obj.alpha = _num5;
					var _num7:Transform = new Transform(_obj);
					var _num8:ColorTransform = new ColorTransform(1, 1, 1, 1, _num2, _num3, _num4, 0);
					_num7.colorTransform = _num8;
					++_num9;
				} 
			} 
		} 
	}
}