I am wondering if someone can tell me how to force a wait till an asynchronous process finishes.
Following is the code that I'm having trouble with:
private function stage_1_processing(): void
{
var inStream:FileStream = new FileStream();
inStream.open(filein, FileMode.READ);
var ba:ByteArray = new ByteArray();
inStream.readBytes(ba);
inStream.close();
//Transform byteArray to bitmapdata
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, stage_2_processing);
loader.loadBytes(ba); // this is an asynchronous operation!!
}
private function stage_2_processing(evt:Event): void
{
trace("Entering stage 2 processing");
var content:* = loader.content;
var bigBMD:BitmapData = new BitmapData(content.width,content.height,true,0x00000000);
bigBMD.draw(content,null,null,null,null,true);
......
I want to force the program to wait until the loader.loadBytes process is finished before continuing on to the stage_2_processing function.
It seems to 'fall through' to the stage_2_processing logic before the asynchronous loader.loadBytes process is finished.
Any assistance/guidance will be much appreciated.
Cheers from Oz.