1

My LoaderInfo will return the swf itself rather than the image given via the FileReference and Loader. I had problems debugging it, as LoaderInfo.content returns [Object Main] (My document class). After investigation, I discovered LoaderInfo.content is a swf file, according to contentType.

The problem is, the file reference for the image is correct (It is an image, and it is not the swf).

My code:

    private function onAction(e:MouseEvent){
        if(e.currentTarget.name == 0){
            myFileReference = new FileReference();
            myFileReference.browse(getTypes());
            myFileReference.addEventListener(Event.SELECT, loadedImage);
            myFileReference.addEventListener(Event.COMPLETE, loadImage15);
        }
    }
    private function loadedImage(e:Event){
        var imgHolder:ImageHolder = Main.imageHolder;
        while(imgHolder.numChildren > 0){
            imgHolder.removeChild(imgHolder.getChildAt(0));
        }
        myFileReference.load();

    }
    private function loadImage15(e:Event){
        var loader:Loader = new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadImg2);
        loader.loadBytes(myFileReference.data);
        trace(myFileReference.type); // .JPG
    }
    private function loadImg2(e:Event){
        var lInfo:LoaderInfo = (e.target as LoaderInfo); //e.target is indeed LoaderInfo
        lInfo.removeEventListener(Event.COMPLETE, loadImg2);
        trace(loaderInfo.contentType); //application/x-shockwave-flash
        var newSprite:MovieClip = loaderInfo.content as MovieClip;
        Main.imageHolde.addChild(newSprite); //Error as you can't addChild Main to Main
    }
    private function getTypes():Array {
        return [new FileFilter("Images","*.jpg;*.jpeg;*.gif;*.png")];
    }
apscience
  • 7,033
  • 11
  • 55
  • 89

2 Answers2

2

EDIT

I originally had a very complicated answer - which was wrong...

You simply have an error in your program:

// here you reference the Loader's contentLoaderInfo

var lInfo:LoaderInfo = (e.target as LoaderInfo); 
lInfo.removeEventListener(Event.COMPLETE, loadImg2);

// but from here on out, you reference your parent class' "loaderInfo" property!

trace(loaderInfo.contentType);
var newSprite:MovieClip = loaderInfo.content as MovieClip; // <- this is your Main class!
Main.imageHolde.addChild(newSprite); //Error as you can't addChild Main to Main

Change loaderInfo to lInfo, and you should be fine.

weltraumpirat
  • 22,544
  • 5
  • 40
  • 54
0

I ask about this issue before : loading image by Loader.loadBytes(byteArray)

Noone knows :]

If You loadBytes of image with Loader , You will recive :

Loader.content is MovieClip
Loader.content.getChildAt(0) is Bitmap
Community
  • 1
  • 1
turbosqel
  • 1,542
  • 11
  • 20
  • You should delete this answer - it doesn't answer the question at all, and it shows you haven't really read and/or understood the answer you got to your own question. – weltraumpirat Dec 11 '11 at 12:40