How to get background color of downloaded SWF file?

I load the swf file into the main application using URLLoader, I want to get the background color of the downloaded SWF file. (I heard that one wold solution reads the byte code of the loaded swf)

+1
source share
2 answers

Yes, you need to learn binary swf data. Here is a brief description of the swf format. And this is a little information about different tags. Your requirement is to recognize the SetBackgroundColor tag (type = 9 tag), which is usually the first or second swf tag.
The bytes in the swf file follow a small order, so you need to be careful when reading data. And basically they will be compressed (the first three bytes will be "CWS"), therefore, starting from the 9th byte (including the 9th), all data must be unpacked (ByteArray.decompress) before processing.
SomeExample code :)

package {
  import flash.display.*;
  import flash.events.*;
  import flash.net.*;
  import flash.utils.*;
  public class Test1 extends Sprite{
    private var stream:URLStream;
    public function Test1():void {
      stream = new URLStream();
      stream.load(new URLRequest("some.swf"));
      stream.addEventListener(Event.COMPLETE, onComplete);
    }
    private function onComplete(e:Event):void {
      var bytes:ByteArray = new ByteArray();
      bytes.endian = Endian.LITTLE_ENDIAN;
      stream.readBytes(bytes, 0, 8);
      var sig:String = bytes.readUTFBytes(3);
      trace("SIG = " + sig);
      trace("ver = " + bytes.readByte());
      trace("size = " + bytes.readUnsignedInt());
      var compBytes:ByteArray = new ByteArray();
      compBytes.endian = Endian.LITTLE_ENDIAN;
      stream.readBytes(compBytes);
      if (sig == "CWS") {
        compBytes.uncompress();
      }
      var fbyte = compBytes.readUnsignedByte();
      var rect_bitlength = fbyte >> 3;
      var total_bits = rect_bitlength * 4;
      var next_bytes =  Math.ceil((total_bits - 3)/ 8);
      for(var i=0; i<next_bytes; i++) {
        compBytes.readUnsignedByte();
      }
      trace("frameRate = " + compBytes.readUnsignedShort());
      trace("frameCount = " + compBytes.readUnsignedShort());

  while(true) {
    var tagcodelen:Number = compBytes.readUnsignedShort();
    var tagcode:Number = tagcodelen >> 6;
    var taglen:Number = tagcodelen & 0x3F;
    trace("tag code = " + tagcode + "\tlen = " + taglen);
    if (taglen >=63) {
      taglen = compBytes.readUnsignedInt();
    }
    if(tagcode == 9) {
      trace("found background color");
      trace("color is: RED=" + compBytes.readUnsignedByte() +", GREEN = " + compBytes.readUnsignedByte() + ", BLUE = " + compBytes.readUnsignedByte());
      break;
    }
    compBytes.readBytes(new ByteArray(), 0, taglen);
    //break;
  }
}

} }

code>
+5
source

To you, the SWF file should transfer it to the web page using JS.

getURL ( "javascript: setColour (" + + ")" );

setColour, , , .

-2

Source: https://habr.com/ru/post/1707767/


All Articles