I would think that I could load a swf using either URLLoader or
URLStream. As it turns out only my URLStream is returning the correct
data.
Can anyone provide a fix to the following code that makes URLLoader
work correctly ?

            import flash.net.URLLoader;
            import flash.net.URLLoaderDataFormat;
            import flash.net.URLRequest;
            import flash.net.URLStream;

            private var loader:URLLoader;
            private var stream:URLStream;

            private function init():void
            {
                loader = new URLLoader();
                loader.dataFormat = URLLoaderDataFormat.BINARY;
                loader.addEventListener(Event.COMPLETE, loaderComplete);
                loader.load( new URLRequest( "Slide1.swf" ) );

                stream = new URLStream();
                stream.addEventListener(Event.COMPLETE, streamComplete);
                stream.load( new URLRequest( "Slide1.swf" ) );

            }

            private function streamComplete(event:Event):void {

                var rawBytes:ByteArray = new ByteArray();
                stream.readBytes( rawBytes, rawBytes.length );
                trace( "Length: " + rawBytes.length );

                dumpData( rawBytes );
            }

            private function loaderComplete(event:Event):void {

                var rawBytes:ByteArray = new ByteArray();
                rawBytes.writeObject( loader.data );
                trace( "Length: " + rawBytes.length );

                dumpData( rawBytes );
            }

            private function dumpData( ba:ByteArray )
            {
                ba.position = 0;
                var index:int = 0;
                var tracer:int;
                while( ba.position < 5)
                {
                    tracer = ba.readByte();
                    trace( index + ": " + tracer.toString(16));
                    index = index + 1;
                }
            }

Reply via email to