It is possible to pass bitmapdata from an OpenFL extension to haxe?

Hello all,

After many tries of loading multiple images and causing my app to crash ( I found some workarounds to avoid the crashes but they comes with more of them ), I want to load all my images from a custom OpenFL extension.

Do you guys know if it’s possible to stream assets from Java ( Like using the Loader class in AS3/OpenFL ) and then pass the images back to OpenFL as a ByteArray or something? So that way I can make all this work in a separated thread and my UI thread will be safe.

Thanks!

Fran

That’s not really necessary, although multithreading is only available on certain targets.

For Android (as it looks like you’re targeting) you can use java.vm.Thread to create a managed Thread that executes an asynchronous function that loads your images externally. The callback could be a boolean value representing if the Task failed to execute.

I’ve only done multithreading in C# .NET so I wouldn’t be an expert on what the code would look like, but here is my attempt otherwise (semi-psuedo):

var loadThread:Thread;

function executeThread() {
   loadThread = Thread.create(loadImages);
   while (true)
   {
      var result = Thread.readMessage(false);
      if (Std.is(result, String))
          if (result == "fail" || result == "success")
              break;
      else if (Std.is(result, ImageData))
      {
          addImage(result);
      }
   }
}

function loadImages()
{
    //Get a collection of ImageData and send the message back to the UI thread.
    for (img in someJavaFunction())
    {
        var result:ImageData = img.getBytes();
        if (result != null) loadThread.sendMessage(result);
    }

    loadThread.sendMessage("success");
}

Again, this probably won’t work the first time, and some of those functions are rather random and semi-psuedo, as I mentioned, but it could be a start.

Assets.loadBitmapData is threaded, now. Are you experiencing issues using it?

@singmajesty I’m trying to avoid this issue:

Loading external images crashes on Android

Assets.loadBitmapData loads embedded assets, right? I want to load images from the web using a “for” loop ( It’s possible in AS3 ) so I can make parallel requests instead of sequential ones ( Takes too long to finish loading ) and avoid that crash which is super annoying “__”