Problems loading graphics with Loader class on Windows target

Hi, I’m using the Loader class to fetch and display a picture from an URL. Everything seems to be fine on Flash and HTML5 targets, but on Windows the picture is only loaded if it is a local file, not from Internet. It is also interesting that no events is called from the Loader when this problem happens, like an IO_ERROR one (if loaded from local file, the COMPLETE event is, indeed, called). Can you help me with this?

Here is part of my code:

this._graphic = new Loader();
this.addChild(this._graphic);
#if flash
    // for some reason, the INIT event is only called on Flash target
    this._graphic.contentLoaderInfo.addEventListener(Event.INIT, onInit);
#else 
    // the COMPLETE event is called on other targets
    this._graphic.contentLoaderInfo.addEventListener(Event.COMPLETE, onInit);
#end
this._graphic.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHttpStatus);
this._graphic.contentLoaderInfo.addEventListener(Event.UNLOAD, onUnload);
this._graphic.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIoError);
this._graphic.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
this._graphic.load(new URLRequest(url));

Also, as you can see at the code, there are some problems with the events. While loading a PNG file, only the Flash target call the INIT event, while the others just call COMPLETE. The PROGRESS and HTTP_STATUS ones are also only called on Flash. Is this expected?

It sounds like the Loader class needs seem improvement in this area.

You could use a URLLoader to get the bytes, then create a BitmapData from Bytes from there. Hopefully this can be implemented in the Loader class, though, to happen automatically based on the path

Thanks, Joshua!

I used your idea of downloading data from URLLoader. It worked perfectly on HTML5 target with all events being called and image displayed correctly. On Windows, however, the problem persists, but I’m not sure if it is the same or a new one. I’ll explain: on Windows, like on HTML5, all events is correctly called (I even checked and the IO_ERROR one is working if the file is missing). However, the Windows Loader class seems to fail when I use its “loadBytes” method. Here is my code (again, working on HTML5 but not on Windows):

// the urlloader
this._graphicLoader = new URLLoader();
this._graphicLoader.dataFormat = URLLoaderDataFormat.BINARY;
this._graphicLoader.addEventListener(Event.COMPLETE, onULRLoaderComplete);
this._graphicLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHttpStatus);
this._graphicLoader.addEventListener(Event.UNLOAD, onUnload);
this._graphicLoader.addEventListener(IOErrorEvent.IO_ERROR, onIoError);
this._graphicLoader.addEventListener(ProgressEvent.PROGRESS, onProgress);

// loader (complete event set to be called after "loadBytes" processing)
this._graphic = new Loader();
this._graphic.contentLoaderInfo.addEventListener(Event.COMPLETE, onInit);

...

private function onULRLoaderComplete(evt:Event):Void {
    this._graphic.loadBytes(this._graphicLoader.data);
}

I believe a workaround would be import the data loaded from the URLLoader objeto directly into a Bitmap one, but is there a way to convert the downloaded ByteArray into a BitmapData object?

Try this:

#if lime_legacy
var bitmapData = BitmapData.loadFromBytes (bytes);
#else
var bitmapData = BitmapData.fromBytes (bytes);

:smile:

I think we need to make sure to round out the Loader class a bit more, with openfl.Assets it isn’t usually needed, but we should be sure to have the compatibility here

Ok, this is becoming weird! :grin:

Replacing the Loader with Bitmap still won’t work on Windows, but works on HTML5…

The only thing I noticed in common on all my attempts is that it seems to be a problem with picture data download from a URL on Windows, not a local file, no matter what is used to download it (Loader or URLLoader).

Okay, let me find some time to look into this soon.

Can you check the ByteArray length? Is it the same on both?

Thank you Joshua!

In fact I just need the HTML5 output for this project, but since I’m new on OpenFL (coming from Apache Flex), I was just checking the possibilities :wink:

Back to the problem, I can retrieve the loaded ByteArray size at the HTML5 target, 3906. However, when I try to get this info on Windows, I receive a runtime error:

Program:

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Alright, this is on my list of things to check out. Do you have a test URL I can use, so I’m sure to not a server difference? Thanks :slight_smile:

I’ve just made a commit that should help:

Hi, Joshua, you were faster than me - fixed the problem before I get a chance to send you the test URL :wink:

Thank you a lot, it worked like a breeze! I had to update lime as well, was this expected?

I’m migrating my media classes from Apache Flex to recreate my Managana project on OpenFL. I’ll post aroud here when I get some results.

Again, thank you a lot!

1 Like