Cloning Loader to Bitmap : Error 1067: Implicid coercion

Good morning gents and ladies…:hugegrin:

I’m writing a class where I load a image with Loader and then tries to copy it into a Bitmap. This goes all and well when I do this in an event but not when I try to make a function of it.

Some code…

  • class variables :*
    var imgLoader:Loader;

  • From Main : *
    imgLoader = new Loader();
    imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
    imgLoader.load(new URLRequest(fileName));

  • In the loading complete event:*
    function loadComplete(e:Event) {
    var loader:Loader = Loader(;
    var image:Bitmap = Bitmap(loader.content);
    var bm:Bitmap = new Bitmap(image.bitmapData.clone());

So far so good. but when I try to make a function that returns a copy of the previous loaded image (imgLoader) I get the error :

1067: Implicit coercion of a value of type flash.display:displayObject to an unrelated type flash.display:BitmapData.

  • The code looks in the function looks like this : *
    var bm:Bitmap = new Bitmap(imgLoader.content);
    var bmret:Bitmap = new Bitmap(bm.bitmapData.clone());

Why is this? All I can think off is that in the LOAD COMPLETE event i get a reference of the current target (I think this is the way it works), and are not using the class variable defined at the top in the code.

Also… I guess this is some kind of beginners mistake…