读取swf里所有类定义

    public class test1 extends Sprite
    {
        public function test1()
        {
            test();
        }
        private function test():void {
            var loader:URLLoader=new URLLoader();
            loader.dataFormat=URLLoaderDataFormat.BINARY;
            loader.addEventListener(Event.COMPLETE,completeHandler);
            loader.load(new URLRequest("bank.swf"));
        }
        private function completeHandler(event:Event):void {
            var bytes:ByteArray=URLLoader(event.target).data;
            bytes.endian=Endian.LITTLE_ENDIAN;
            bytes.writeBytes(bytes,8);
            bytes.uncompress();
            bytes.position=Math.ceil(((bytes[0]>>>3)*4+5)/8)+4;
            while(bytes.bytesAvailable>2){
                var head:int=bytes.readUnsignedShort();
                var size:int=head&63;
                if (size==63)size=bytes.readInt();
                if (head>>6!=76)bytes.position+=size;
                else {
                    head=bytes.readShort();
                    for(var i:int=0;i<head;i++){
                        bytes.readShort();
                        size=bytes.position;
                        while(bytes.readByte()!=0);
                        size=bytes.position-(bytes.position=size);
                        trace(bytes.readUTFBytes(size));
                    }
                }
            }
        } 
    }

 

posted on 2012-04-24 18:20  防空洞123  阅读(372)  评论(0编辑  收藏  举报

导航