[转][心得] 一个例子获取swf文件头帧频

转载地址:
http://bbs.9ria.com/viewthread.php?tid=64203&extra=page%3D1%26amp;orderby%3Ddateline%26amp;filter%3D86400



主要适用于传媒方面,用AS3写的Swf去加载AS2版本的Swf,通过获取帧频,调整自己做加载容器的帧频,来达到动画的流畅
package 
{
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.net.URLRequest;
        import flash.events.IEventDispatcher;
        import flash.net.URLStream;
        import flash.utils.ByteArray;
       
       
        public class Test extends Sprite
        {
                private var loader:URLStream;
                public function Test()
                {
                        this.addEventListener(Event.ADDED_TO_STAGE, onAddToStage);
                }
                private function onAddToStage(e:Event):void
                {
                        loader = new URLStream();
                         configureListeners(loader);

            var request:URLRequest = new URLRequest("TestAs.swf");
            try {
                loader.load(request);
            } catch (error:Error) {
                trace("Unable to load requested document.");
            }
                }
                private function configureListeners(dispatcher:IEventDispatcher):void {
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
        }
                private function completeHandler(e:Event):void
                {
                        var tmpLoader:URLStream = URLStream(e.currentTarget);
                       
                        var bytes:ByteArray = new ByteArray();
                        tmpLoader.readBytes(bytes)
                        var zlibFlag:String = "F";
                        zlibFlag = bytes.readUTFBytes(1);
                       
                        /*trace(bytes.readUTFBytes(1))
                        trace(bytes.readUTFBytes(1))
                        trace(bytes.readUnsignedByte())//==版本号
                        */
                        if (zlibFlag=="F")
                        {
                                //========没有压缩的swf
                                bytes.position = 17;
                                trace(bytes.readUnsignedShort())//读出帧频
                        }else
                        {
                                //========压缩过的swf,从Flash6就开始有这功能
                                var tmpBytes:ByteArray = new ByteArray();
                                tmpBytes.writeBytes(bytes,  8 );//==把位置8开始读到新的ByteArray
                               
                                tmpBytes.uncompress();//===解压缩
                               
                                tmpBytes.position = 9;//===转到读帧频的位置
                                trace(tmpBytes.readUnsignedShort())//读出帧频
                        }
                       
                }
        }

}
复制代码

你可能感兴趣的:(PHP,.net,F#,Flash,bbs)