0

i like to ask about one thing :

If i create Loader and load external image by URLRequest , ill have result :

loader.content is Bitmap
loader.content.bitmapData is BitmapData

But if I use Loader.loadBytes(ImageBytes) , result is different even if ImageBytes is loader.contentLoaderInfo.bytes :

bytesLoader.content is MovieClip
bytesLoader.content.getChildAt(0) is Bitmap
bytesLoader.content.getChildAt(0).bitmapData is BitmapData

why ?

turbosqel
  • 1,542
  • 11
  • 20

1 Answers1

0

AS3 Loader has internal parsing to try and match datatypes to internal class types. It's pretty handy in most cases, but the syntax is a little weird.

In your example above, you CAN cast the bytesLoader.content as Bitmap if you'd rather.

Edit (in reference to the "how" question):

ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, getImage);

ldr.load ( new URLRequest ( IMAGE_URL ) );

function getImage (e:Event):void {
    var bmp:Bitmap = ldr.content as Bitmap;
    addChild (bmp);
}

You should be able to simply cast it as a Bitmap.

James Tomasino
  • 3,520
  • 1
  • 20
  • 38
  • How ? If loader after load complete set content on its own and for loader.loadBytes content is MovieClip with Bitmap , not Bitmap – turbosqel Nov 13 '11 at 15:29
  • Im not talking about loader.load , but loader.loadBytes method and its result – turbosqel Nov 20 '11 at 10:33
  • I just did a test using loadBytes. I can still cast to Bitmap as well. I'm utilizing this method as part of an old blog post (http://labs.tomasino.org/2010/04/20/as3-duplicate-loaded-swf/). Seems to work just fine. Perhaps there's an issue with the data you're loading into the byte-array? – James Tomasino Nov 20 '11 at 13:58
  • I load img by Loader.load and save its loaderContent.bytes to my project file , than reload project file and loadBytes – turbosqel Nov 21 '11 at 11:06