2010-02-02 77 views

回答

2

讀取SWF文件的前4個字節。前3個字節是讀取(CWS或FWS)的簽名,下一個字節是SWF文件版本。所以你不需要任何庫,只需簡單的文件IO就足夠了。對於動作腳本版本,您需要查找FileAttributes標籤。所以這裏是做這個的僞代碼。 (在SWF文件中的數據是Little Endian,所以請相應地編寫你的readInt或readShort函數)。

signature = read 3 UTF Bytes as String; 
version = read one byte; 
size = read unsigned int; (int is 32 bit) 
if (signature == "CWS") // i.e. SWF is compressed 
    then uncompress the rest of the bytes; //swf uses zlib compression, first 7 bytes are compressed 
rect_byte = read unsigned Byte; 
rect_bits = rect_byte >> 3; //first 5 bits says how many bits are required for one dimensoin of the swf 
total_bits = rect_bits * 4; 
rect_bytes = Math.ceil((total_bits - 3)/ 8); //till here we have information about swf dimension 
read rect_bytes number of bytes; 
read unsigned short as frame rate; 
read unsigned short as frame count; 
while true do { 
    read unsigned short into swf_tag_code_len; 
    tagcode = swf_tag_code_len >>6; // first 6 bits determine the tag code 
    taglen = swf_tag_code_len & 0x3F; // last 10 bits determines the length of tag (if length is less than 63) 
    if (taglen >= 63) { // if tag is bigger than 63 bytes, then next four bytes tell the length 
    taglen = read unsgined int; 
    } 
    if (tagcode == 69) {// here we go, we are looking for this tag (fileattribute) { 
    b = read unsigned byte; 
    if (b & (1 << 3)) { // 4th least significant bit tell about actionscript version 
     it is actionscript version 3; 
    } else { either it is 1.0 or 2.0;} 
    } 
}

+0

如何將SWF文件版本字節轉換爲actionscript版本? – 2010-02-03 22:08:36

+0

只有swf文件使用actionscript版本3.0或更高版本時,才能說明。您需要查找FileAttributes標籤。我用相同的僞代碼編輯了答案。希望能幫助到你。 – bhups 2010-02-04 05:50:25

相關問題