如何获取加载的 swf 文件的背景颜色? [英] How can I get the background color of a loaded swf file?

查看:26
本文介绍了如何获取加载的 swf 文件的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 URLLoader 将 swf 文件加载到我的主应用程序中,我想获取加载的 swf 文件的背景颜色.(我听说一种解决方案是读取加载的 swf 的字节码)

I'm loading an swf file into my main application using URLLoader, I want to get the background color of the loaded swf file. ( I heard that one solution wold be reading the byte code of the loaded swf )

推荐答案

是的,您需要查看二进制 swf 数据.这里是对 swf 格式的简要说明.而this 是关于不同类型标签的一些细节.您的要求是找出SetBackgroundColor 标签(标签类型= 9),它通常是swf 的第一个或第二个标签.
swf 文件中的字节遵循小端顺序,因此在读取数据时需要小心.大多数情况下它们将被压缩(前三个字节将是CWS"),因此从第 9 个字节开始(包括第 9 个字节),所有数据都需要在处理之前进行解压缩(ByteArray.decompress).
一些示例代码 :)

Yes, You need to look into binary swf data. Here is brief description of swf format. And this is a little detail about different kind of tags. Your requirement is to find out SetBackgroundColor tag(tag type = 9), which commonly is either first or second tag of the swf.
Bytes in swf file follows little endian order, so you need to be careful while reading the data. And mostly they will be compressed(first three bytes will be "CWS") so from 9th bytes onwards (including 9th), all data needs to be decompressed (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 + "	len = " + 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;
  }
}

}}

这篇关于如何获取加载的 swf 文件的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆