views:

241

answers:

1
+1  A: 

Well, a Loader is itself a DisplayObject - so you could just addChild(event.currentTarget) and it'll show up just fine. It extends DisplayObjectContainer just like Sprite does.

If you literally need a Bitmap, then you can do something like:

var bmd:BitmapData = new BitmapData(event.currentTarget.width, event.currentTarget.height);
bmd.draw(event.currentTarget);
bitmap = new Bitmap(bmd);

And do it that way. You might have to tweak that a bit I'm going from memory.

If you're ever having issues with the Display API, this is a very good chart to summarize what lives where and how the various display object children are connected: http://accad.osu.edu/~pgerstma/class/pca/resources/as3API/AS3API-flash.display.png

Myk
thanks, actually when i changed the argument in addChild mathod it worked. But my basic need is to get the BitmapData of this loader object but from another class. So i think i cannot use the code you propose about the bitmapData. Of course now i can get it through the sprite reference i created, but can i get it another way?
Ponty
I'm not sure I understand what you need exactly, but if it helps: anything that extends DisplayObject is drawable by BitmapData. That means that you can convert it directly into a BitmapData object by creating your bitmapData instance and saying "bmd.draw(targetDisplayObject)" - then you have a BitmapData object that contains the pixel data for whatever you're drawing. If this helps, please accept my answer as Hooray pointed out in the comments above. You'll get better help from the community if you accept answers. Cheers!
Myk
Basically, i have a class that loads the image via a Loader. And another class that will manipulate the data of its bitmapData. So, i will use the first class to load various images, and the second class to manipulate their bitmapdata data. So i have to reference to their bitmapdata somehow from an external class not the one that i use to load the images. And basically i ask what is the most appropriate way to transfer this information from the LoadImage class to lets say a Main class.
Ponty
I guess you could create a custom event. Once you have your image loaded in your loader class, and once you've stripped out the bitmap data you need to pass over, do something like this:var imageLoadedEvent:MyCustomImageEvent = new MyCustomImageEvent("MY_EVENT");imageLoadedEvent.bitmapData = myBitmapData;dispatchEvent(imageLoadedEvent);Then in your main class, add a listener:loaderClass.addEventListener("MY_EVENT", handler);function handler(e:MyCustomImageEvent):void {imageProcessorClass.process(e.bitmapData);}Does that make sense?
Myk
ok i'll try it :)
Ponty