title: Retrieve Last 2 Results from Service Call in Flex AS3 PHP
body: <p>I'm a Flex newbie and I've searched both StackOverflow and Google'd but can't seem to figure out this (simple) problem with Flex/ActionScript 3 Asynchronous programming. I have a PHP service (Zend) that inserts a row into the table. What I would like to do is be able to call the service twice consecultively with different row values, and get back the new IDs (primary keys) returned by the service. Then I display the new IDs as 2 Alerts.</p>
  
  <p>The problem is when I can the service twice in a row, I only get an Alert.show() for the last and most recent service call. I don't know how to access the result of the first.</p>
  
  <p>I recognize I can reconfigure my Flex code and PHP service to accept an array of objects and just send a single PHP service call for both and receive back an array object with the results, but I'm also trying to get a better understanding in general how AsyncToken is working and how to access old results that I need. Is each use of {serviceResult}.token overwriting my previous result?</p>
  
  <pre><code>&lt;s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009"
  xmlns:s="library://ns.adobe.com/flex/spark"
  xmlns:mx="library://ns.adobe.com/flex/mx"
     // ...
  </code></pre>
  
  <p>Here is my related code where I want to set up 2 default folders for new users "Home" and "temp":</p>
  
  <pre><code> // imports
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.events.CloseEvent;
   import mx.events.FlexEvent;
   import mx.rpc.AsyncToken;
   import mx.rpc.IResponder;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   import mx.rpc.remoting.mxml.RemoteObject;
   import mx.rpc.Responder;
   import spark.events.IndexChangeEvent;
  
  import valueObjects.Folders;
  
  
  // When the user clicks "Save" button, 2 new folders are created for a new user:
  protected function pendingUserSaveButton_clickHandler(event:MouseEvent):void 
  {
         // Create 2 initial user folders: Home and temp-taiwan
         var t1Folders:Folders = new Folders();
  
     t1Folders.users_email = tempUser.email;
     t1Folders.name = t1Folders.description = "Home";
  
     createFoldersFunction( t1Folders ); // assume returns folder ID = 100
  
     var t2Folders:Folders = new Folders();
     t2Folders.users_email = tempUser.email;
     t2Folders.name = t2Folders.description = "temp";
  
     createFoldersFunction( t2Folders ); // assume returns folder ID = 101
  }
  </code></pre>
  
  <p>and here are my event handlers, and I want an Alert box for each new ID to pop up:</p>
  
  <pre><code>protected function createFoldersFunction(item:Folders):void
  {
      createFoldersResult.token = foldersService.createFolders(item);
  }
  
  protected function createFoldersResult_resultHandler(event:ResultEvent):void
  {
      Alert.show("Folder #" + ((event.result as int) as String) + " created");
              // Currently, I only get Alert saying "Folder #101 created".
              // I want to see 2 Alerts - one for #100 and another for #101
  
  }
  </code></pre>
  
  <p>and here are my mx codes for callresponder and service:</p>
  
  <pre><code>&lt;s:CallResponder id="createFoldersResult"
      result="createFoldersResult_resultHandler(event)"/&gt;
  &lt;foldersservice:FoldersService id="foldersService"
      fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
      showBusyCursor="true"/&gt;
  </code></pre>
  
  <p>Only '101' (the result of second service call) is triggering an Alert. Why is this?</p>
  
  <p>Thank you!</p>