hey,
Iv been working on an swf file generator following the specification, However i am currently struggling to have my binary output match the binary output of a swf file gengerated by flash CS3. The particular part i am struggling with is the file attributes tag, the specifications for the output are below :

header 10 bits, value always 69
reserved bit, value always 0
useDirectBlit.1 bit value 1 or 0
useGPU 1 bit, value 1 or 0
hasmetadata 1 bit value 1 or 0
actionscript3,1 bit value 1 or 0
supress cross domainc aching 1 bit value 1 or 0
swf relative urls.1 bit value 1 or 0
reserved bits. 2 bits both value 0
use network1 bit value 1 or 0

with that said, the output generated from my program is
10001010 00110000 10000000, or in hex 8A 30 80

Values from swf compiled in flash cs3 with the same settings are

01000100 01000100 01000100. or in hex 44 11 19

Quite a large difference at any rate considering i followed the specification letter for letter, It should be noted i tested adding in 3 extra bits at the left most part of the binary which results in hex output of 11 46 02 which was closer, however i removed it as it was not in the specification.

public String AttributeBuilder()
    {
        StringBuffer str = new StringBuffer();

        str.append(Integer.toBinaryString(0));
        str.append(Integer.toBinaryString(0));//add three reserved bits, removed is 
        str.append(Integer.toBinaryString(0));//further from result, dont know why its needed, not in spec



        str.append(Integer.toBinaryString(69)); // ID 
        str.append(Integer.toBinaryString(0)); //reserved bit
        str.append(Integer.toBinaryString(0)); //use blitting
        str.append(Integer.toBinaryString(0)); //use GPU
        str.append(Integer.toBinaryString(1)); //has meta data
        str.append(Integer.toBinaryString(1)); //has actionscript 3 support
        str.append(Integer.toBinaryString(0)); //domain cacheing
        str.append(Integer.toBinaryString(0)); //relative urls


        for(int i=0;i<2;i++)
        {str.append(Integer.toBinaryString(0));} //insert reserved bits


        int padlength = Integer.toBinaryString(1).length() + str.length() % 8;
        str.append(padOut(Integer.toBinaryString(getUseNetwork()),padlength));
        //pad final part to 8 bits to ensure no underflow prior to reserved bits


        for(int i=0;i<24;i++)
        {str.append(Integer.toBinaryString(0));}
        //insert 24 reserved bits


        String str2 = str.toString();
        //final string

        return str2;

    }

    private String padOut(String s, int len) {
        if (s.length() >= len)
            return s;

        StringBuffer padding = new StringBuffer();
        for (@SuppressWarnings("unused")
        int p = 0; padding.length() + s.length() < len; p++)
            padding.append("0");
        return padding.toString() + s;
    }

Despite the amount of time iv spent fiddling around with the values the closest i get is when i pad 3 0 values to the buffer at the start resulting in binary/hex output of 11 46 02, which is still far from what its meant to be. Any help resolving the difference would be grand :)

You seem to assume that Integer.toBinaryString gives a string of the right length, but that's not true, Eg
Integer.toBinaryString(69) returns a 7 char string, but the spec requires it to be 10 (that's why inserting 3 zeros helps). You need to pad each and every Integer.toBinaryString to the right length before appending them all together

that actually helped a lot but i still cant seem to get it working, I think i might be missing data, since in the example swf file i generated its binary output is :
01000100 00010001 00011001
00010001 01000110 00010000
7 bits set altogether, where as my program even with the corrections i made from your advice only generates six bits set to 1, so it seems the specification has lied :p i seem to be missing something rather important from the output, so no matter how much padding i do and correcting the order, something will still be missing. On a flash forum someone posted.

0x000015 44 11 19 00 00 00       FileAttributes             (tag: 69 data:4) 
1144 hex    00010001.01000100
69 dec      00010001.01
04 dec                 000100 

I cant figure out where this extra bit is coming from. But thanks for your help anyway resolved the 3 bit padding problem :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.