swf文件格式說明書(中文+英文)SWF文件頭
字段 類型 備注
標(biāo)識 8位 標(biāo)識字節(jié):
F代表未壓縮
C代表已壓縮(SWF6以后的版本特有)
標(biāo)識 8位 代表W
標(biāo)識 8位 代表S
版本號 8位 代表SWF文件的版本,比如0x06代表SWF6
文件長度 32位 整個文件的所占的字節(jié)數(shù)
幀大小 RECT 結(jié)構(gòu)SWF場景的大小,單位為1twip(1/20像素) 幀速度 16位 幀數(shù) 16位 影片總的幀數(shù)目 The header begins with a three-byte Signature of either 0x46, 0x57, 0x53 (“FWS”) or 0x46, 0x57, 0x43 (“CWS”). An FWS signature indicates an uncompressed SWF file; CWS indicates that the entire file after the first 8 bytes (that is, after the FileLength field) has been compressed using the open standard ZLIB. The data format used by the ZLIB library is described by Request for Comments (RFCs) documents 1950 to 1952. CWS file compression is only permitted in SWF version 6 or later.
文件頭以三個標(biāo)識符開始,他們不是0x46, 0x57, 0x53 (“FWS”)就是0x46,0x57, 0x43 (“CWS”).一個FWS標(biāo)識表示該文件是未壓縮文件.CWS標(biāo)識表示整個文件,在前八個字節(jié),也就是文件長度字段之后所有的內(nèi)容,都是開放標(biāo)準(zhǔn)ZLIB壓縮過的.用ZLIB庫的數(shù)據(jù)格式,在1950 到1952年的Request for Comments (RFCs)文檔中有所描述.CWS僅在SWF6以后才允許使用.
A one-byte Version number follows the signature. The version number is not an ASCII character,but an 8-bit number. For example, for SWF 4 the version byte is 0x04, not the ASCII character‘4’ (0x35).
在標(biāo)識符之后的一個字節(jié)是版本號.這個版本號不是一個ASCII字符,而是一個8位的數(shù)字.例如,SWF4文件的版本號是0x04,不是ASCII字符”4”(0x35).
The FileLength field is the total length of the SWF file including the header. If this is an uncompressed SWF (FWS signature), the FileLength field should exactly match the file size. If this is a compressed SWF (CWS signature), the FileLength field indicates the total length of the file after decompression, and thus will generally not match the file size. Having the uncompressed size available can make the decompression process more efficient.
文件長度字段代表包括文件頭整個文件的總長度.如果是一個未壓縮的SWF文件(FWS標(biāo)識符),文件長度字段表示文件的精確大?。蝗绻且粋€壓縮的SWF文件(CWS標(biāo)識),文件長度字段表示解壓后文件的大小,這樣一般就不是實際文件的大小了.讓未壓縮(解壓后)的大小可見,則可以使解壓過程更加有效.
The FrameSize field defines the width and height of the movie. This is stored as a RECT structure, meaning that its size may vary according to the number of bits needed to encode the coordinates. The FrameSize RECT always has Xmin and Ymin of 0; the Xmax and Ymax members define the width and height (see Using Bit Values).
幀大小字段表示影片的寬度和高度.它存在一個RECT結(jié)構(gòu)中,表示它的大小可以根據(jù)坐標(biāo)(四個點的坐標(biāo))數(shù)值的變化而變化.文件大小RECT通常是這樣的形式:Xmin和Ymin成員都為0;Xmax和Ymax成員聲明寬度和高度.(參考Using Bit Values一節(jié))
The FrameRate is the desired playback rate in frames per second. This rate is not guaranteed if the SWF file contains streaming sound data, or Flash Player is running on a slow CPU.
幀速率表示理想的每秒播放幀數(shù).如果SWF文件包含聲音流數(shù)據(jù),或者Flash播放器運行在一個慢的CPU上,這個速率是不能保證的.
The FrameCount is the total number of frames in this SWF movie. 幀數(shù)表示SWF影片總的幀數(shù)目. SWF File Structure
SWF文件結(jié)構(gòu)
Following the header is a series of tagged data blocks. All tags share a common format, so any program parsing a SWF file can skip over blocks it does not understand. Data inside the block can point to offsets within the block, but can never point to an offset in another block. This enables tags to be removed, inserted, or modified by tools that process a SWF file.
在文件頭后面的是一些標(biāo)簽化的數(shù)據(jù)塊。所有的標(biāo)簽都是用一種通用格式。所以任何程序在解析一個SWF文件時,都可以跳過那些還不明確的塊。在每個塊中的數(shù)據(jù)可以指向這個塊中的偏移量,但絕不能指向另外一個塊的偏移量。這樣,在用工具處理SWF文件的時候就任意可以刪除、插入和修改(而SWF文件不會被破壞)。
Tag Format
標(biāo)簽格式
Each tag begins with a tag type and a length. There are two tag header formats, short and long. Short tag headers are used for tags with 62 bytes of data or less. Long tag headers can be used for any tag size up to 4GB, far larger than is presently practical.
每個標(biāo)簽都以標(biāo)簽類型和長度開頭。標(biāo)簽頭格式有兩種,短型和長型。短型標(biāo)簽頭用在數(shù)據(jù)不超過62字節(jié)的標(biāo)簽;長型標(biāo)簽頭則可用在比實際用到的大小大得多的4GB之內(nèi)的任何標(biāo)簽中。
標(biāo)簽頭(短型)
字段 類型 備注
TagCodeAndLength(標(biāo)簽類型和長度) 16位 高10位:標(biāo)簽類型 低6位:標(biāo)簽長度
Note: The TagCodeAndLength field is a two-byte word, not a bitfield of 10 bits followed by a bitfield
of 6 bits. The little-endian byte ordering of SWF makes these two layouts different.
The length specified in the TagCodeAndLength field does not include the RECORDHEADER
that starts a tag.
TagCodeAndLength字段是一個占兩字節(jié)的字,而不是一個10位二進(jìn)制字段后面跟著6位二進(jìn)制字段。
If the tag is 63 bytes or longer, it is stored in a long tag header. The long tag header consists of a
short tag header with a length of 0x3f, followed by a 32-bit length.
假如標(biāo)簽是63字節(jié)或者更長,它具有長型標(biāo)簽頭。長型標(biāo)簽頭就好像一個以0x3f開頭的短型標(biāo)簽頭,后面跟著一個32位長度。
標(biāo)簽頭(長型)
字段 類型 備注
TagCodeAndLength(標(biāo)簽類型和長度) 16位 標(biāo)簽類型和標(biāo)簽長度(這兒的標(biāo)簽長度不是真實 的)合起來是0x3f,包裝起來像短型標(biāo)簽頭
長度 32位 標(biāo)簽長度
Definition and Control Tags
定義型標(biāo)簽和控制型標(biāo)簽
There are two categories of tags in SWF:
Definition Tags These tags define the content of the SWF movie – the shapes, text, bitmaps,
sounds, and so on. Each definition tag assigns a unique ID called a character ID to the content it
defines. Flash Player then stores the character in a repository called the dictionary. Definition
tags, by themselves, do not cause anything to be rendered.
Control Tags These tags create and manipulate rendered instances of characters in the
dictionary, and control the flow of the movie.
SWF有兩種類類型的標(biāo)簽:
定義型標(biāo)簽:這類標(biāo)簽定義SWF影片的內(nèi)容,如各種形狀,文字,位圖,聲音等等。每個定義型標(biāo)簽在內(nèi)容被定義都分配了一個唯一的標(biāo)識號給它,這叫做角色標(biāo)識(character ID)。.flash播放器則把這些角色放到一個存儲空間里面,這個存儲空間我們一般叫它字典。用定義型tag是不會繪制任何圖形的,不會產(chǎn)生任何動畫的。
控制型標(biāo)簽:這類標(biāo)簽用來產(chǎn)生和操作字典中的角色實例的渲染,并且控制影片的流程。
Tag Ordering in SWF
SWF標(biāo)簽的排序
Generally speaking, tags in a SWF can occur in any order. However, there are a few rules that
must be observed:
1 A tag should only depend on tags that come before it. A tag should never depend on a tag that
comes later in the file.
2 A definition tag that defines a character must occur before any control tag that refers to that
character.
3 Streaming sound tags must be in order. Out-of-order streaming sound tags will result in the
sound being played out of order.
4 The End tag is always the last tag in the SWF file.
總的來說,標(biāo)簽可以出現(xiàn)任何情況的排序方法,但也不是隨便亂排, 它遵循一些規(guī)則:
1.一個標(biāo)簽只能依靠在它之前的標(biāo)簽,不能依靠在它之后的標(biāo)簽.
2.一個定義了角色的定義型標(biāo)簽必須在引用這個角色的控制型標(biāo)簽之前。
3.流媒體標(biāo)簽必須有順序,沒有順序的流媒體播放起來也是沒有順序的
4.結(jié)束標(biāo)簽(tag)應(yīng)該在SWF文件的最后。
The Dictionary
字典
The dictionary is a repository of characters that have been defined, and are available for use by Control Tags. The process of building and using the dictionary is as follows: 1 A definition tag defines some content, such as a shape, font, bitmap, or sound. 2 A unique CharacterId is assigned to the content by the definition tag. 3 The content is saved in the dictionary under the CharacterId. 4 A control tag retrieves the content from the dictionary using the CharacterId, and performs some action on the content, such as displaying a shape, or playing a sound. Every definition tag must specify a unique ID. Duplicate IDs are not allowed. Typically, the first CharacterId is 1, the second CharacterId is 2, and so on. Character zero is special and considered a null character. Control tags are not the only tags that reference the dictionary. Definition tags can use characters from the dictionary to define more complex characters. For example, the DefineButton and DefineSprite tags refer to other characters to define their contents. The DefineText tag can refer to font characters to select different fonts for the text.
字典是已經(jīng)定義好的所有角色的倉庫,并且可以通過控制型標(biāo)簽來使用它。建立和使用字典的過程是以下這樣的:1.一個定義型標(biāo)簽定義了一些內(nèi)容,如形體,字體,位圖或者聲音。2.定義型標(biāo)簽給該內(nèi)容賦上一個唯一的角色標(biāo)識(CharacterID)。3.依據(jù)角色標(biāo)識把內(nèi)容存到字典中。4. 一個控制型標(biāo)簽根據(jù)角色標(biāo)識從字典中找出相應(yīng)的內(nèi)容,然后給這個內(nèi)容執(zhí)行一些動作,比如顯示一個形體,或者播放一個聲音。每個控制型標(biāo)簽都只指定一個唯一的標(biāo)識。相同的標(biāo)識是不允許的。舉個象征性的例子,第一個角色的標(biāo)識是1,第二個角色的標(biāo)識是2,依次類推。角色標(biāo)識為0的是一個特殊的標(biāo)識,被看作是空角色。控制型標(biāo)簽并不是唯一指向字典的標(biāo)簽。定義型標(biāo)簽也可以指向多個角色來定義一些更復(fù)雜的角色。例如,定義按鈕(DefineButton)和定義精靈(DefineSprite)標(biāo)簽都是根據(jù)其它角色來定義它們的內(nèi)容的。定義文字(DefineText)標(biāo)簽可以指向字體角色來為文字選擇不同的字體。
附:Sprite一般都翻譯為精靈,解釋可以查相關(guān)的書籍,flash ,director等都有這個概念。
The following diagram illustrates a typical interaction between definition tags, control tags and the dictionary:
以下的圖示展示了定義型標(biāo)簽,控制型標(biāo)簽和字典之間的一個象征性的交互:
Processing a SWF File
處理一個SWF文件
Flash Player processes all the tags in a SWF file until a ShowFrame tag is encountered. At this point, the display list is copied to the screen and Flash Player is idle until it is time to process the next frame. The contents of the first frame are the cumulative effect of performing all the control tag operations before the first ShowFrame tag. The contents of the second frame are the cumulative effect of performing all the control tag operations from the beginning of the file to the second ShowFrame tag, and so on.
Flash播放器在一個顯示幀標(biāo)簽到來之前會處理顯示幀標(biāo)簽之前SWF文件的所有標(biāo)簽。在這個時候,播放列表被復(fù)制到屏幕上面,與此同時Flash播放器在處理下一幀之前是空閑的。第一幀所顯示的內(nèi)容,是在第一個顯示幀標(biāo)簽之前的所有控制型標(biāo)簽操作產(chǎn)生的累積效果。第二幀所顯示的內(nèi)容,是從文件開始到第二個顯示幀標(biāo)簽所有控制型標(biāo)簽操作產(chǎn)生的累積效果。以此類推。
File Compression Strategy
文件壓縮策略
Since SWF files are frequently delivered over a network connection, it is important that they be as
compact as possible. There are several techniques that are used to accomplish this. Here are some
things to look out for:
既然SWF文件在網(wǎng)絡(luò)連接中傳輸?shù)梅浅nl繁,那它們當(dāng)然是越緊湊越好。有很多技術(shù)可以實現(xiàn)這點。這是我們選中的幾種有效的策略:
Reuse The structure of the character dictionary makes it very easy to reuse elements in a SWF file. For example, a shape, button, sound, font, or bitmap can be stored in a file once and referenced many times.
重用 角色字典的結(jié)構(gòu)使得重用SWF文件元素非常容易。例如,一個形體、按鈕、聲音、字體或者位圖,可以在文件中只存一次,但用到很多次。
Compression Shapes are compressed using a very efficient delta encoding scheme, often the first coordinate of a line is assumed to be the last coordinate of the previous one. Distances are also often expressed relative to the last position.
壓縮 形體使用了非常有效的差值編碼方法來壓縮,經(jīng)常直線的開始坐標(biāo)是上一條直線的最終坐標(biāo)。距離經(jīng)常由上一個位置的坐標(biāo)來表達(dá)。
Default values Some structures like matrices and color transforms have common fields that are used more often than others. For example, for a matrix, the most common field is the translation field. Scaling and rotation are less common. Therefore if the scaling field is not present, it is assumed to be 100%. If the rotation field is not present, it is assumed that there is no rotation. This use of default values helps to minimize file sizes.
默認(rèn)值 有一些結(jié)構(gòu)像矩陣和色彩變換都有一些共同的屬性用得比其它的多。比如一個矩陣,最常用的屬性就是平移屬性,而縮放與旋轉(zhuǎn)則用得相對少點。因此如果沒有定義縮放屬性,就假定它的值為100%,如果沒有定義旋轉(zhuǎn)屬性,就假定它的值為沒有旋轉(zhuǎn)。使用默認(rèn)值可以使文件大小最小化。
Change Encoding As a rule, SWF files only store the changes between states. This is reflected in shape data structures and in the place/move/remove model used by the display list.
變化編碼 作為一種規(guī)則,SWF文件只存儲兩種狀態(tài)之間的變化。它由形體數(shù)據(jù)結(jié)構(gòu)和播放列表中使用的定位/移動/移除模塊反映出來。
Shape Data Structure The shape data structure uses a unique structure to minimize the size of shapes and to render anti-aliased shapes very efficiently on the screen.
形體數(shù)據(jù)結(jié)構(gòu) 形體數(shù)據(jù)結(jié)構(gòu)使用了一種獨特的結(jié)構(gòu),使得形體的文件大小最小化,并且使得形體在屏幕上的平滑抗鋸齒處理非常有效。
Summary
小結(jié)
A SWF file is made up of a header, followed by a number of tags. There are two types of tags,
Definition Tags and Control Tags. Definition Tags define the objects known as characters,
which are stored in the Dictionary. Control Tags manipulate characters, and control the flow
of the movie.
一個SWF文件是由一個文件頭,跟著一系列的標(biāo)簽組成的。標(biāo)簽類型有兩種:定義型標(biāo)簽和控制型標(biāo)簽。定義型標(biāo)簽把所有物體定義成一個個角色,這些角色存在字典里面??刂菩蜆?biāo)簽操作這些角色,并且控制影片的流程。 分類: flash類 swf文件 |
|