Reputation: 10837
I'm developing an iPad app using Adobe Air.
I have all my images loaded into BitmapData
objects when the app starts. Then I only need to create Bitmap
objects (which are only containers) to use the pixels that are stored into the BitmapData
objects.
This works fine until I have to create a Bitmap
object with a big image. The app slows down, even freezes, for as much as 1 second.
As AS3 is single threaded, I cannot delegate the Bitmap
creation to a new thread. Also if the UI is frozen, I cannot show a decent spinner to inform the user "something is going on".
How could I solve this problem? Is there a way to create objects in parallel without affecting the UI performance?
Upvotes: 1
Views: 539
Reputation: 10837
Well it seems the answer was a lot simpler, and Adobe already thought of that.
http://help.adobe.com/en_US/as3/dev/WS52621785137562065a8e668112d98c8c4df-8000.html
The problem is that even if the images are loaded into BitmapData
objects, they are stil not decoded. That is why bigger images take a while to be put into Bitmap
objects.
The solution is as simple as using an instruction to force image decoding when the images are loaded, and not when you need them. This is done using ImageDecodingPolicy.ON_LOAD
.
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.imageDecodingPolicy = ImageDecodingPolicy.ON_LOAD;
var loader:Loader = new Loader();
loader.load(new URLRequest("http://www.adobe.com/myimage.png"), loaderContext);
Upvotes: 0
Reputation: 1531
You could use a worker
, its basicaly a background thread for as3, read up on it here ASDocs Worker
Upvotes: 1