Return to Snippet

Revision: 35440
at November 8, 2010 17:59 by jaredyeo


Initial Code
var xURLLoader : URLLoader = new URLLoader();
var xByte : uint;
var xNBits : int;
var xOffset : int;

pbGet.addEventListener(MouseEvent.CLICK, fOnClick);
xURLLoader.addEventListener(Event.COMPLETE, fOnComplete);
xURLLoader.dataFormat = URLLoaderDataFormat.BINARY;

function fParse(v : ByteArray) : Object
{
	var vFormat : String;
	var vSwfVersion : int;
	var vFileLength : int;
	var vFrameRate : int;
	var vTotalFrames : int;
	var vFrameSize : Rectangle;

	v.endian = Endian.LITTLE_ENDIAN;

	vFormat = v.readUTFBytes(3);
	vSwfVersion = v.readByte();
	vFileLength = v.readUnsignedInt();
	v.readBytes(v);
	v.length -= 8;
	if (vFormat == "CWS")
		v.uncompress();
	v.position = 0;
	vFrameSize = new Rectangle();
	vFrameSize.left = xfReadNBits(v, true) / 20;
	vFrameSize.right = xfReadNBits(v) / 20;
	vFrameSize.top = xfReadNBits(v) / 20;
	vFrameSize.bottom = xfReadNBits(v) / 20;
	vFrameRate = v.readUnsignedByte() / 256 + v.readUnsignedByte();
	vTotalFrames = v.readUnsignedShort();
	return {
		mFormat: vFormat,
		mSwfVersion: vSwfVersion,
		mFileLength: vFileLength,
		mFrameSize: vFrameSize,
		mFrameRate: vFrameRate,
		mTotalFrames: vTotalFrames
	};
}

function xfReadNBits(v : ByteArray, vStart : Boolean = false) : uint
{
	var n : uint;

	if (vStart)
	{
		xByte = v.readUnsignedByte();
		xNBits = xByte >> 3;
		xOffset = 3;
	}

	n = xByte << (32 - xOffset) >> (32 - xNBits);
	xOffset -= xNBits;
	while (xOffset < 0)
	{
		xByte = v.readUnsignedByte();
		n |= (xOffset < -8) ? (xByte << (-xOffset - 8)) : (xByte >> (-xOffset - 8));
		xOffset += 8;
	}
	return n;
}

function fOnClick(e : MouseEvent) : void
{
	xURLLoader.load(new URLRequest("http://" + tfUrl.text));
}

function fOnComplete(e : Event) : void
{
	var i : int;
	var vData : Object;
	
	vData = fParse(xURLLoader.data);
	tfFormat.text = vData.mFormat;
	tfVersion.text = vData.mSwfVersion;
	tfFileLength.text = vData.mFileLength;
	tfWidth.text = vData.mFrameSize.width;
	tfHeight.text = vData.mFrameSize.height;
	tfFrameRate.text = vData.mFrameRate;
	tfTotalFrames.text = vData.mTotalFrames;
}

Initial URL
http://simplistika.com

Initial Description

                                

Initial Title
Parsing / Reading SWF Header

Initial Tags
header

Initial Language
ActionScript 3