SWF10翻譯

SWF_FILE_FORMAT_SPEC_V10文檔翻譯

Chapter 1 Basic Data Types

Coordinates and twips

The SWF file format stores all x-y coordinates as integers, usually in a unit of measurement

called a twip. In the SWF format, a twip is 1/20th of a logical pixel. A logical pixel is the same

as a screen pixel when the file is played at 100%that is, without scaling.

座標及twips單位

SWF文件的X,Y座標是以整型格式進行存儲,通常以twips作爲一個量度單位,以SWF格式來說,

一個twip就相當於是一個邏輯像素的1/20,在沒有縮放,即100%比例進行播放時,一個SWF文件

邏輯像素就是一個屏幕像素。

 

Integer types and byte order

The SWF file format uses 8-bit, 16-bit, 32-bit, 64-bit, signed, and unsigned integer types. All

integer values are stored in the SWF file by using little-endian byte order: the least significant

byte is stored first, and the most significant byte is stored last, in the same way as the Intel x86

architecture. The bit order within bytes in the SWF file format is big-endian: the most

significant bit is stored first, and the least significant bit is stored last.

 

整型類型及字節序

SWF文件格式使用8位,16爲,32爲,64位,有符號及無符號整型類型,在SWF文件中,所有以整型

方式存儲的值都是使用little-endian 字節序,即低字節存儲在低位,高字節存儲在高位。Intel x86架構

採用得就是這種方式,而對於一個字節內位順序採用的是big-endian方式,及高位先存儲,然後再存低位。

MATRIX record

The MATRIX record represents a standard 2x3 transformation matrix of the sort commonly

used in 2D graphics. It is used to describe the scale, rotation, and translation of a graphic

object. The MATRIX record must be byte aligned.

MATRIX record表示的是標準的2×3排序變換矩陣,通常應用於2D,用來完成縮放,旋轉及圖形圖像變換

MATRIX record必須是字節對齊的。

Field

Type

Comment

HasScale

UB[1]

Has

NScaleBits If HasScale = 1

UB[5] Bits in each scale value field

NScaleBits If HasScale = 1

ScaleX

If HasScale = 1, FB[NScaleBits] x scale value

ScaleX If HasScale = 1

ScaleY

If HasScale = 1, FB[NScaleBits] y scale value

ScaleY If HasScale = 1

HasRotate

UB[1]

Has rotate and skew values if equal

to 1

NRotateBits

If HasRotate = 1,UB[5] Bits in each rotate value field

NRotateBits If HasRotate = 1

RotateSkew0

If HasRotate = 1,

FB[NRotateBits]

First rotate and skew value

RotateSkew1

If HasRotate = 1,

FB[NRotateBits]

Second rotate and skew value

NTranslateBits

UB[5]

Bits in each translate value field

TranslateX

SB[NTranslateBits]

x translate value in twips

TranslateY

SB[NTranslateBits]

y translate value in twips

 

Chapter 2 SWF Structure Summary

 

The SWF header+SWF file structure

 

SWF File Header

Field             Type    Comment                                            Bytes

Signature         UI8                    Signature byte:                                        1 

                                                “F” indicates uncompressed

                                                “C” indicates compressed (SWF 6 and later only)

Signature         UI8                    Signature byte always “W”                               1

Signature         UI8                    Signature byte always “S”

Version             UI8                    Single byte file version (for example, 0x06 for SWF 6)          1 

FileLength       UI32        Length of entire file in bytes                              4 

FrameSize    RECT    Frame size in twips                                     由表示最大數所需要位來決定

(前五位用來標識用多少位表示,因爲UB[5]

,注意單位是twips,換算成像素,還要除以20)

FrameRate      UI16        Frame delay in 8.8 fixed number of frames per second         2

FrameCount   UI16        Total number of frames in file                             2

 

SWF file structure

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

ability enables tags to be removed, inserted, or modified by tools that process a SWF file.

The FileAttributes tag is only required for SWF 8 and later.

 

|Header | FileAttributes tag | Tag | Tag | Tag | End tag

 

Tag format

Each tag begins with a tag type and a length. The tag-header formats can be either short or

long. Short tag headers are used for tags with 62 bytes of data or less. Long tag headers, with a

signed 32-bit length field, can be used for any tag size up to 2GB, far larger than is presently

practical.

每一個tag都是以tag type+長度方式開始的,tag-header格式可以是 short long 類型。Short

Tag headers 用來表示長度小於等於62字節的tag.Long tag headers是一個有符號的32-bit字段,

最大能存儲2GB長度Tag,這遠比目前實際大得多。

RECORDHEADER (short)

Field

         Type

Comment

TagCodeAndLength

UI16

Upper 10 bits: tag type

Lower 6 bits: tag length

The length specified in the TagCodeAndLength field does not include the

RECORDHEADER that starts a tag.

TagCodeAndLength字段中所標明的標籤的長度是不包含RECORDHEADER部分的,

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.

如果tag63字節或更長,它以long tag header方式來存儲,log tag header由一個shrot tag header+0x3f+32-bit length來組成。

RECORDHEADER (long)

Field

         Type

Comment

TagCodeAndLength

UI16

Tag type and length of 0x3F

Packed together as in short header

Length

SI32

Length of tag

 

 

Definition and control tags

The two categories of tags in a SWF file are as follows:

"Definition tags" And "Control tags"

 

Definition tags -- define the content of the SWF file—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

Definition tags -- 定義SWF文件的內容--形狀,文本,位圖,聲音等等,每一個 definition tag被分配一個唯一

                              ID好來表明一個已定義的內容,之後Flash Player將其存放在一個叫做“字典”的容器中,

                              Definition tag其自身不會被渲染。

 

Control tags -- create and manipulate rendered instances of characters in the dictionary, and

                       control the flow of the file.

Control tags -- 創建並操作字典中已渲染的角色實例,並控制文件數據流。

 

Tag ordering in SWF filesSWF文件中tag規則)

Generally speaking, tags in a SWF can occur in any order. However, you must observe the

following rules:

The FileAttributes tag must be the first tag in the SWF file for SWF 8 and later.

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.

A definition tag that defines a character must occur before any control tag that refers to

that character.

   一個定義了角色的definition tag必須出現在任何與該角色相關control tag之前。

Streaming sound tags must be in order. Out-of-order streaming sound tags result in the

sound being played out of order.

          流聲音tag必須是有序的,無序的流聲音tag會導致播放時無序

The End tag is always the last tag in the SWF file.

 

The dictionary

The dictionary is a repository of characters that are defined, and are available for control tags

to use. The process of building and using the dictionary is as follows:

字典是所有被定義角色容器,爲control tags所用,建立及使用字典步驟如下:

1. The definition tag defines some content, such as a shape, font, bitmap, or sound.

2. The definition tag assigns a unique CharacterId to the content.

3. The content is saved in the dictionary under the CharacterId.

4. A control tag uses the CharacterId to retrieve the content from the dictionary, 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. The number zero (0) is special

and is considered a null character.

每一個定義的 definition tag 必須制定一個唯一的ID, 負責IDs 是不允許的,通常,第一個角色ID1,其次爲2,以此類推。

0用來表明空角色ID標識。

 

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.

不僅僅Control tag能引用字典,definition tags也可以從字典中使用角色來定義更復雜的角色。例如:...

 

Processing a SWF file(SWF文件的處理)

Flash Player processes all of 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 of the control tag operations before the first ShowFrame tag. The contents of the second

frame are the cumulative effect of performing all of the control tag operations from the

beginning of the file to the second ShowFrame tag, and so on.

Flash Player在遇到 ShowFrame tag之前會處理所有的control tag,正因爲如此,顯示列表中的信息會被拷貝到屏幕上同時

Flash Player處於閒置狀態,直到遇到下一個ShowFrame tag出現。每個ShowFrame tag中取出的control tag在顯示的時候

呈現疊加效果

 

Summary

A SWF file is made up of a header, followed by a number of tags. The two types of tags are

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 file.

小結:

一個SWF文件由 header+ much more tags 組成,tags有兩種類型:definition tags control tags,

Definition tags定義角色對象,並存儲在字典中,Control tags操作角色,並且控制文件數據流。

 

Chapter 3 The Display List(第三章,顯示列表)

Displaying a frame of a SWF file is a three-stage process:

1. Objects are defined with definition tags such as DefineShape, DefineSprite, and so on.

Each object is given a unique ID called a character, and is stored in a repository called the

dictionary.

2. Selected characters are copied from the dictionary and placed on the display list, which is

the list of the characters that will be displayed in the next frame.

3. Once complete, the contents of the display list are rendered to the screen with ShowFrame.

顯示一個swf 文件的一幀數據需要經歷三個步驟:

1:用definition tags(諸如defineShape, DefineSprite)等對對象進行定義,每一個對象分配一個唯一的ID標識一個角色並存儲在字典中

2:所選擇的角色從字典中拷貝出來並放置在顯示列表中,以方便下一幀顯示

3:完成以後,顯示列表中的信息就會在遇到ShowFrame標籤時進行渲染。

 

A depth value is assigned to each character on the display list. The depth determines the

stacking order of the character. Characters with lower depth values are displayed underneath

characters with higher depth values. A character with a depth value of 1 is displayed at the

bottom of the stack. A character can appear more than once in the display list, but at different

depths. Only one character can be at any given depth.

In SWF 1 and 2, the display list was a flat list of the objects that are present on the screen at

any given time. In SWF 3 and later versions, the display list is a hierarchical list where an

element on the display can have a list of child elements. For more information, see

DefineSprite.

depth 值被分配給顯示列表中的每個角色,這個 depth 值決定角色的棧順序,角色的depth值越小,出現的就越晚。

最小的之爲1,放置在棧底,一個角色可以在顯示列表中出現多次,但是有不同的depths,一個角色對應一個給定的depth

,SWF12版本中,顯示列表是對象平坦列表被展現在屏幕上,SWF3及後續版本改用繼承的方式,詳見DefineSprite.

 

The following six tags are used to control the display list:

PlaceObject Adds a character to the display list.

PlaceObject2 & PlaceObject3 Adds a character to the display list, or modifies the

character at the specified depth.

RemoveObject Removes the specified character from the display list.

RemoveObject2 Removes the character at the specified depth.

ShowFrame Renders the contents of the display list to the display.

NOTE

         The older tags, PlaceObject and RemoveObject, are rarely used in SWF 3 and

         later versions.

 

Clipping layers[裁剪層]

Flash Player supports a special kind of object in the display list called a clipping layer. A

character placed as a clipping layer is not displayed; rather it clips (or masks) the characters

placed above it. The ClipDepth field in PlaceObject2 specifies the top-most depth that the

clipping layer masks.

For example, if a shape was placed at depth 1 with a ClipDepth of 4, all depths above 1, up to

and including depth 4, are masked by the shape placed at depth 1. Characters placed at depths

above 4 are not masked.

Flash Player在顯示列表中提供了一種特殊的對象類型叫裁剪層,一個角色放置在裁剪層中是不會被顯示的,而是裁剪

(或遮蓋)放置在其上的對象,在PlaceObject2就有一個ClipDepth字段用來表明裁剪的最大層級數。

 

Using the display list[顯示列表的使用]

The following procedure creates and displays an animation:

接下來的步驟是創建及顯示一個動畫

1. Define each character with a definition tag.

Each character is given a unique character ID, and added to the dictionary.

爲每一個角色分配一個definition tag,每一個角色分配一個唯一ID,並放置在字典中

2. Add each character to the display list with a PlaceObject2 tag. Each PlaceObject2 tag

specifies the character to be displayed, plus the following attributes:

A depth value, which controls the stacking order of the character being placed. Characters

with lower depth values appear to be underneath characters with higher depth values. A

depth value of 1 means the character is displayed at the bottom of the stack. Only one

character can be at any given depth.

A transformation matrix, which determines the position, scale, factor, and angle of

rotation of the character being placed. The same character can be placed more than once

(at different depths) with a different transformation matrix.

變換矩陣,決定位置,縮放,比例,旋轉角度,同樣的角色可以放置不同的變換矩陣。

An optional color transform, which specifies the color effect applied to the character

being placed. Color effects include transparency and color shifts.

An optional name string, which identifies the character being placed for SetTarget

actions. SetTarget is used to perform actions inside sprite objects.

An optional ClipDepth value, which specifies the top-most depth that will be masked by

the character being placed.

An optional ratio value, which controls how a morph character is displayed when placed.

A ratio of zero displays the character at the start of the morph. A ratio of 65535 displays

the character at the end of the morph.

3. Use a ShowFrame tag to render the contents of the display list to the screen.

4. Use a PlaceObject2 tag to modify each character on the display List.

Each PlaceObject2 assigns a new transformation matrix to the character at a given depth.

The character ID is not specified because each depth can have only one character.

使用PlaceObject2 tag來修改顯示列表中的每一個角色

每一個PlaceObject2分配一個新的變換矩陣給指定depth的角色

角色ID是不能指定的,因爲每一個depth只能對應一個角色。

5. Use a ShowFrame tag to display the characters in their new positions.

Repeat steps 4 and 5 for each frame of the animation.

6. Use a RemoveObject2 tag to Remove each character from the display list.

Only the depth value is required to identify the character being removed.

 

Display list tags

Display list tags are used to add character and character attributes to a display list.

 

PlaceObject2

The PlaceObject2 tag extends the functionality of the PlaceObject tag. The PlaceObject2 tag

can both add a character to the display list, and modify the attributes of a character that is

already on the display list. The PlaceObject2 tag changed slightly from SWF 4 to SWF 5. In

SWF 5, clip actions were added.

The tag begins with a group of flags that indicate which fields are present in the tag. The

optional fields are CharacterId, Matrix, ColorTransform, Ratio, ClipDepth, Name, and

ClipActions. The Depth field is the only field that is always required.

The depth value determines the stacking order of the character. Characters with lower depth

values are displayed underneath characters with higher depth values. A depth value of 1 means

the character is displayed at the bottom of the stack. Any given depth can have only one

character. This means a character that is already on the display list can be identified by its

depth alone (that is, a CharacterId is not required).

The PlaceFlagMove and PlaceFlagHasCharacter tags indicate whether a new character is

being added to the display list, or a character already on the display list is being modified. The

meaning of the flags is as follows:

PlaceFlagMove = 0 and PlaceFlagHasCharacter = 1

A new character (with ID of CharacterId) is placed on the display list at the specified

depth. Other fields set the attributes of this new character.

PlaceFlagMove = 1 and PlaceFlagHasCharacter = 0

PlaceFlagMove = 1 and PlaceFlagHasCharacter = 1

The character at the specified Depth is removed, and a new character (with ID of

CharacterId) is placed at that depth. Other fields set the attributes of this new character.

For example, a character that is moved over a series of frames has PlaceFlagHasCharacter set

in the first frame, and PlaceFlagMove set in subsequent frames. The first frame places the new

character at the desired depth, and sets the initial transformation matrix. Subsequent frames

replace the transformation matrix of the character at the desired depth.

The optional fields in PlaceObject2 have the following meaning:

The CharacterId field specifies the character to be added to the display list. CharacterId is

used only when a new character is being added. If a character that is already on the display

list is being modified, the CharacterId field is absent.

The Matrix field specifies the position, scale and rotation of the character being added

or modified.

The ColorTransform field specifies the color effect applied to the character being added

or modified.

The Ratio field specifies a morph ratio for the character being added or modified. This

field applies only to characters defined with DefineMorphShape, and controls how far the

morph has progressed. A ratio of zero displays the character at the start of the morph. A

ratio of 65535 displays the character at the end of the morph. For values between zero and

65535 Flash Player interpolates between the start and end shapes, and displays an inbetween

shape.

The ClipDepth field specifies the top-most depth that will be masked by the character

being added. A ClipDepth of zero indicates that this is not a clipping character.

The Name field specifies a name for the character being added or modified. This field is

typically used with sprite characters, and is used to identify the sprite for SetTarget

actions. It allows the main file (or other sprites) to perform actions inside the sprite (see

Sprites and Movie Clips on page 231).

The ClipActions field, which is valid only for placing sprite characters, defines one or

more event handlers to be invoked when certain events occur.

 

Chapter 4  Control  tags

Control tags manage some overall aspects of files, frames, and playback in SWF files.

Control tags是針對SWF文件幀,回放等宏觀,全局的一些方面進行管理

包含的tag如下:

SetBackgroundColor

FrameLabel

Protect

End

ExportAssets  

ImportAssets

EnableDebugger

EnableDebugger2

ScriptLimits

SetTabIndex

FileAttributes

Field

Type

Comment

UseGPU

(see note following

table)

UB[1]

If 1, the SWF file uses GPU compositing

features when drawing graphics, where such

acceleration is available.

If 0, the SWF file will not use hardware

accelerated graphics facilities.

Minimum file version is 10.

ImportAssets2

SymbolClass

Metadata

DefineScalingGrid

DefineSceneAndFrameLabelData

Chapter 5 Actions

Actions are an essential part of an interactive SWF file. Actions allow a file to react to events

such as mouse movements or mouse clicks. The SWF 3 action model and earlier supports a

simple action model. The SWF 4 action model supports a greatly enhanced action model that

includes an expression evaluator, variables, and conditional branching and looping. The

SWF 5 action model adds a JavaScript-style object model, data types, and functions.

行爲對於相與SWF文件進行互動是必須的一部分,行爲允許SWF文件對事件作出反應(如鼠標移動或鼠標點擊事件)SWF 3 action model以及早期版本支持一些簡單的行爲模型,SWF 4 action model支持的行爲模型有了很大增強,包括表達式計算,變量,條件分支及循環,SWF 5 action model 還添加了java script風格的腳本,數據類型及函數

 

SWF 3 action model

The SWF 3 action model consists of eleven instructions for Flash Player:

Instruction

See

Description

Play

ActionPlay

Start playing at the current frame

Stop

ActionStop

Stop playing at the current frame

NextFrame

ActionNextFrame

Go to the next frame

PreviousFrame

ActionPreviousFrame

Go to the previous frame

GotoFrame

ActionGotoFrame

Go to the specified frame

GotoLabel

ActionGoToLabel

Go to the frame with the specified label

WaitForFrame

ActionWaitForFrame

Wait for the specified frame

GetURL

ActionGetURL

Get the specified URL

StopSounds

ActionStopSounds

Stop all sounds playing

ToggleQuality

ActionToggleQuality

Toggle the display between high and low

quality

SetTarget

ActionSetTarget

Change the context of subsequent actions to a

named object

 

An action (or list of actions) can be triggered by a button state transition, or by SWF 3

actions. The action is not executed immediately, but is added to a list of actions to be

processed. The list is executed on a ShowFrame tag, or after the button state has changed. An

action can cause other actions to be triggered, in which case, the action is added to the list of

actions to be processed. Actions are processed until the action list is empty.

By default, Timeline actions such as Stop (see ActionStop), Play (see ActionPlay), and

GoToFrame (see ActionGotoFrame) apply to files that contain them. However, the SetTarget

action (see ActionSetTarget), which is called Tell Target in the Adobe Flash user interface, can

be used to send an action command to another file or sprite (see DefineSprite).

 

行爲(或行爲列表)可以通過按鈕狀態轉換或 SWF 3 actions 進行觸發,行爲不是立即被執行,而是被添加到行爲列表中執行,行爲列表在遇到 ShowFrame tag或按鈕狀態轉換後時執行,這種情況下,被添加到行爲列表中待執行的行爲會被全部處理直到行爲列表爲空爲止,

默認情況下,時間性行會作用於包含他們的文件,如(Stop, Play, GoToFrame等),SetTarget行爲或接口名TellTarget,可以被用來給另一個SWF文件或sprite發送action command.

SWF 3 actions

The actions in this section are available in SWF 3.[行爲僅適用於SWF 3版本]

ActionSetTarget

ActionSetTarget instructs Flash Player to change the context of subsequent actions, so they

apply to a named object (TargetName) rather than the current file.

For example, the SetTarget action can be used to control the Timeline of a sprite object. The

following sequence of actions sends a sprite called "spinner" to the first frame in its

Timeline:

1. SetTarget "spinner"

2. GotoFrame zero

3. SetTarget " " (empty string)

4. End of actions. (Action code = 0)

All actions following SetTarget spinner apply to the spinner object until SetTarget “”,

which sets the action context back to the current file. For a complete discussion of target

names see DefineSprite.

ActionSetTartget 行爲

ActionSetTarget 行爲表明Flash Player要去改變後續actions的上下文,因此比較適合應用於named object(TargetName)而不是當前SWF文件。

例如:他和SetTarget action可以用於控制sprite object 的生命線,一下行爲流程是將一個叫做spinnerSprite發送給他生命線的第一幀上。

 

接着SetTarget spinner”以下的所有行爲都將作用於spinner object直到遇到 Set Target “”,  Set Target “”的作用是將行爲上下文返回當前文件,對於target names 的詳細討論請參見DefineSprite.

 

SWF 4 action model

The SWF 4 file format supports a greatly enhanced action model that includes an expression

evaluator, variables, conditional branching and looping.

Flash Player 4 incorporates a stack machine that interprets and executes SWF 4 actions. The

key SWF 4 action is ActionPush. This action is used to push one or more parameters onto the

stack. Unlike SWF 3 actions, SWF 4 actions do not have parameters embedded in the tag,

rather they push parameters onto the stack, and pop results off the stack.

The expression evaluator is also stack based. Arithmetic operators include ActionAdd,

ActionSubtract, ActionMultiply, and ActionDivide. The Flash authoring tool converts

expressions to a series of stack operations. For example, the expression 1+x*3 is represented as

the following action sequence:

ActionPush "x"

ActionGetVariable

ActionPush "3"

ActionMultiply

ActionPush "1"

ActionAdd

The result of this expression is on the stack.

SWF 4與之前最大的不同就是可以將參數壓入棧,像表達式計算就是基於棧來實現的。

Movie control [移動控制流]

ActionGetProperty

ActionGetProperty does the following:

1. Pops index off the stack.

2. Pops target off the stack.

3. Retrieves the value of the property enumerated as index from the movie clip with target

path target and pushes the value to the stack.

ActionGetProperty按一下方式執行:

1:從棧中彈出索引值

2:從棧中彈出target.

3:根據target path從影片剪輯中以枚舉索引值方式來獲取相關屬性值,並將結果壓入棧中。

The following table lists property index values. The _quality, _xmouse, _ymouse and _rotation 10

properties are available in SWF 5 and later.

以下列表中列出了屬性索引值,像質量,鼠標x,y座標及旋轉。這些在swf5及後續版本中支持。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章