How do I wait for a responder to return data before continuing

I've just started playing arround with AS3 and I'm trying to retrieve data from mysql
using AMFPHP. I have everthing working OK but something is puzzeling me.
I use netconnection to connect to my gateway and then the responder to handle the data.

I have a caller function that is meant to call all my dataloader functions (ie getFolderData,getFileDate etc etc)
I have placed breakpoints in getFolderData , onFolderResult and getFileData funsction  but it seems like there is some delay before
it reached the onFolderResult function. Basicaly the breakpoint stops in getFolderData skips onFoldersResult and goes directly into
getFileData and then it comes back to onFoldersResult. If I stop before the call to getFileData in loadData the aFolders array is empty.
Should I be using some sort of event handler that would wait for data to be returned from the service call or how would I stop "execution" until aFolders has data populated by responder?

class myclass{
var responder:Responder;
public var aFolders:Array = new Array();

private function makeNetConnection(){
service = new NetConnection();

public function getFolderData():void{
responder = new Responder(onFoldersResult, onFault);"folderservice.getfolderlist", responder);

private function onFoldersResult(responds:Object):void{
var t:Array = responds.serverInfo.initialData;
for (var i:uint=0;i<t.length;i++){

public function getFileData():void{
//get file data

public function loadData()
for (var i:uint=0;i< aFolders.length;i++){
	//here I want to manipulate folder array



Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The event works asynchronously, meaning that it does not block the code.
When you call loadData it actually calls the onFolderResults later when the data has arrived but it finishes running the current function, so you're going to want to transfer all your manipulating code to the onFoldersResult function.
Senocular had a GREAT guide on "asynchronous operations", and perhaps it's of some use to you:

But basically, as Fiassari said, you need to divide it up into a different function which is called once the data is returned.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.