• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

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);
service.call("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

2 Solutions
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now