Handle VerifyError: Error #1014 when loading swfs using AS3

前端 未结 5 1710
花落未央
花落未央 2021-02-11 07:40

We are making a system that has a main swf for the application, and loads separate tools from separate swfs -- there will be versioning issues in the future since the s

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-11 08:02

    The best way to do this is by using one of the libraries bhups suggested. I used senocular's for the next example. Also, because the senocular's library provides only basic operations for the parsed SWF you may need the SWF Format Spec (adobe.com/devnet/swf/pdf/swf_file_format_spec_v10.pdf) to get the info you want out of the loaded SWF.

    The next example lists all the class names from a loaded SWF:

    package swf
    {
     import flash.events.Event;
     import flash.net.URLRequest;
     import flash.net.URLStream;
     import flash.utils.ByteArray;
     import flash.utils.Endian;
    
     import swf.SWFReader;
    
     public class GetSWFInfo
     {
    
      private var swfInfo:SWFReader;
    
      public function GetSWFInfo()
      {
       var urlRequest:URLRequest = new URLRequest("theswf.swf");
       var loader:URLStream = new URLStream();   
       loader.load(urlRequest);
       loader.addEventListener(Event.COMPLETE, onComplete);
      }
    
    
      public function onComplete(e:Event):void {
       var recivedByteArray :ByteArray = new ByteArray();
       URLStream(e.currentTarget).readBytes(recivedByteArray);
    
    
       //create a new instance of SWFReader
       swfInfo = new SWFReader();
       //readTag it's a callback function that will be called when a tag is read during the SWF parse process.
       //read more on tags in the SWF specification document
       swfInfo.tagCallback =  readTag;
       //start parsing
       swfInfo.parse(recivedByteArray); 
      }
    
    
    
      public function readTag(tag:uint, bytes:ByteArray):void {
    
    
       //76 it's the tag type for SymbolClass tag
       //read more in the SWF specification document
       if (76 == tag) {
    
    
        var classesArray:Array = new Array();
        var symbolsNumber:uint = 0;
        var currentId:uint = 0;
    
        bytes.endian = Endian.LITTLE_ENDIAN;
    
        //read the symbols Number
        //again read more in the SWF specification document
        symbolsNumber = bytes.readShort();
    
        bytes.position = 4;
    
        while (true) {
    
         var i:uint = bytes.position;
    
         //every string name ends with a null byte
         //again read more in the SWF specification document
         while(bytes[i] != 0) i++;
    
         var readAmount:uint = i - bytes.position;
    
         classesArray.push(bytes.readUTFBytes(readAmount));
    
         //the last ID is always the base class Id, and it's 0
         currentId=bytes.readUnsignedShort();
    
         bytes.position++;     
    
         if (currentId==0) {
          break;
         }
        }
    
        //this two should be equal
        trace(classesArray.length + 1);//the number of elements in the classesArray
        trace(symbolsNumber);//the number of classes retrived from the SWF
    
        //list the names
        var name:String;
        for each (name in classesArray) {
         trace(name);
        }
    
        //now you have an array with all the class names that you can use to compare
    
       }
      }
     }
    

    }

提交回复
热议问题