我怎样才能得到一个加载的SWF文件的背景颜色? [英] How can I get the background color of a loaded swf file?

查看:255
本文介绍了我怎样才能得到一个加载的SWF文件的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的URLLoader加载一个SWF文件到我的主要的应用程序,我想加载的SWF文件的背景色。 (我听说一个解决方案沃尔德被读取加载的SWF的字节code)

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格式的简要说明。和是一个小细节对不同种类的标签。您的要求就是找出SetBackgroundColor标签(标签类型= 9),这通常是第一或第二的SWF标签。
字节的swf文件如下little endian的顺序,因此你需要同时读取数据要小心。且多为他们将玉米pressed(前三个字节将是CWS),以便从第九字节起(包括9次),所有数据需要DECOM pressed(ByteArray.decom preSS)之前加工。照片SomeExample code :)

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 + "\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;
  }
}

} }

这篇关于我怎样才能得到一个加载的SWF文件的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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