Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
Necuima

How To Wait Till An Asynchronous Process Finishes

Recommended Posts

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.

Share this post


Link to post
Share on other sites

Hi HartleySan,

 

Yes, thanks for the tip.

 

What was confusing me was that I had three 'alert' displays in the stage_2_processing function and they were displaying in the reverse order than I was expecting!  I seem to recall that I had come across this once before and was never able to figure out why the alerts were displaying in the reverse order.  But display in the reverse order they do, but the code actually executes in the correct, sequential order!

 

In the end I discovered that the 'bug' in the function was unrelated to the asynchronicity of the loader.loadBytes - embarrassingly I had a simple spelling error!!

 

Many thanks for your assistance.

 

Cheers from Oz.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...