Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

datetime - Can ActionScript tell when a SWF was published?

I'd like to write a little class that adds a Day/Month box showing the date a SWF was published from Flash.

The company I work for regularly produces many, many SWFs and many versions of each, iterating over the course of months. A version-tracking system we've been using to communicate with our clients is a Day/Month date-box that gives the date the SWF was published. Up until now, we've been filling in the publish date by hand. If there's any way I can do this programatically with ActionScript that'd be fantastic.

Any insight? Basically, all I need is the call that gives me the publish date, or even.. anything about the circumstances under which a SWF was published that I could use to roll into some form of.. automated version identification, unique to this SWF.

So, can ActionScript tell when a SWF was published?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

George is correct. Adobe sneaks an undocumented ProductInfo tag that contains the compilation date in to every compiled swf. The DisplayObject.loaderInfo.bytes contains the the complete uncompressed swf that loaded the Display Object.

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html#loaderInfo

So the quickest way to get the swf's compilation date without external libraries (from a Display Object):

import flash.utils.Endian;
import flash.display.LoaderInfo;
import flash.utils.ByteArray;
...

private function getCompilationDate():Date{
  if(!stage) throw new Error("No stage");

  var swf:ByteArray = stage.loaderInfo.bytes;
  swf.endian = Endian.LITTLE_ENDIAN;
  // Signature + Version + FileLength + FrameSize + FrameRate + FrameCount
  swf.position = 3 + 1 + 4 + (Math.ceil(((swf[8] >> 3) * 4 - 3) / 8) + 1) + 2 + 2;
  while(swf.position != swf.length){
    var tagHeader:uint = swf.readUnsignedShort();
    if(tagHeader >> 6 == 41){
      // ProductID + Edition + MajorVersion + MinorVersion + BuildLow + BuildHigh
      swf.position += 4 + 4 + 1 + 1 + 4 + 4;
      var milli:Number = swf.readUnsignedInt();
      var date:Date = new Date();
      date.setTime(milli + swf.readUnsignedInt() * 4294967296);
      return date; // Sun Oct 31 02:56:28 GMT+0100 2010
    }else
      swf.position += (tagHeader & 63) != 63 ? (tagHeader & 63) : swf.readUnsignedInt() + 4;
  }
  throw new Error("No ProductInfo tag exists");
}

The SWF Specification: http://www.adobe.com/content/dam/Adobe/en/devnet/swf/pdf/swf_file_format_spec_v10.pdf


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...