解析/读取SWF头
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解析/读取SWF头相关的知识,希望对你有一定的参考价值。
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; }
以上是关于解析/读取SWF头的主要内容,如果未能解决你的问题,请参考以下文章
C++ ifstream ofstream 用法解析(iostreamfstream头文件)(ios::appios::ateios::inios::outios::trunc)(未完)
C++ ifstream ofstream 用法解析(iostreamfstream头文件)(ios::appios::ateios::inios::outios::trunc)(未完)