Re: [flexcoders] URLLoader + Binary != URLStream

2009-05-27 Thread Manish Jethani
On Wed, May 27, 2009 at 2:14 AM, Stephen More stephen.m...@gmail.com wrote:
 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 ?

[...]

Why are you calling writeObject() in the case of the URLLoader? You
should call writeBytes() instead. writeObject() is for objects, not
raw bytes

Manish


[flexcoders] URLLoader + Binary != URLStream

2009-05-26 Thread Stephen More
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;
}
}