2 Replies Latest reply on Aug 31, 2010 6:27 AM by daslicht

    Flashbuilder 4 and ZEND AMF

    daslicht Level 2


      i have the following setup:


      This is my ValueObject:

      class PurchasedSongVO
           public $txn_id;
           public $article_id;
           public $song_id; 
           public $songName; 
           public $artistName1; 
           public $songIcon; 
           public $songPreviewFileName; 
           public $fullSongFileName;


      This is my zend_amf index.php (striped it down to the non working service, the others are working fine!):


      $server = new Zend_Amf_Server();
      $server->setClassMap( "PurchasedSongVO"                        , "PurchasedSongVO"   );
      echo($server -> handle());


      In my OrdersService.php I have the following function:

      public function getAllPurchasedSongs_BY_userID( $user_id ) 
           $stmt = mysqli_prepare( $this->connection, 
           "SELECT orderdetails.txn_id,`article_id`,`song_id`, `songName`, `artistName1`, `songIcon`, `songPreviewFileName`, `fullSongFileName`
                          FROM `orderdetails`,`songs`,`orders`
                          WHERE orders.user_id=?
                          AND orderdetails.txn_id=orders.txn_id
                          AND orderdetails.article_id = songs.song_id" );          
           mysqli_stmt_bind_param ($stmt, 'i', $user_id );          
           $rows = array(); //result array
           $row = new PurchasedSongVO();
           while( mysqli_stmt_fetch($stmt) ) 
               $row = new PurchasedSongVO();//stdClass();
               mysqli_stmt_bind_result(     $stmt, 
                      $rows[] = $row;
         return $rows;


      When I call this Service by 'hand' and print_r it I get for example the following:


          [0] => PurchasedSongVO Object
                  [txn_id] => 44L66197L05199028
                  [article_id] => 6
                  [song_id] => 6
                  [songName] => Let's Go A!
                  [artistName1] => Ansolas & Lightrocker
                  [songIcon] => defaultSongIcon_38x38.png
                  [songPreviewFileName] => 
                  [fullSongFileName] => 
          [1] and so on ...


      Here is how I access the service within Flex:

      os.destination ='zend';
      os.addEventListener( FaultEvent.FAULT, faultListener);
      os.getAllPurchasedSongs_BY_userID.addEventListener( ResultEvent.RESULT, getAllPurchasedSongs_BY_userID_result );
      public function _getAllPurchasedSongs_BY_userID( user_id:int ):void
           os.getAllPurchasedSongs_BY_userID( user_id );
           private function getAllPurchasedSongs_BY_userID_result( event:ResultEvent ):void
                var resultArray:Array = new Array();
                resultArray = event.result as Array;
                this._purchasedSongsCollection.source = resultArray;


      Here is my AS3 Value Object:

      package view.user.valueObjects
           public class PurchasedSongVO
                public var txn_id;//:String;
                public var article_id;
                public var song_id; 
                public var songName; 
                public var artistName1; 
                public var songIcon; 
                public var songPreviewFileName; 
                public var fullSongFileName;


      Now when I call ther service the returned type of objects in the Array is just Object and not PurchasedSongVO, here the trace from above:

      orders:[object Object],[object Object],[object Object],[object Object]


      If done it this way for all other services but they all return the right type and not just object.



      Any idea what could be wrong ?

        • 1. Re: Flashbuilder 4 and ZEND AMF
          daslicht Level 2



          the following simple fix is doing the job but the funny think is that its working on my other functions without casting:


          private function getAllPurchasedSongs_BY_userID_result( event:ResultEvent ):void
               var resultArray:Array = new Array();
                   resultArray = event.result as Array;
               if(resultArray != null)
                    var sourceArray:Array = new Array();
                    for( var i:int=0; i<resultArray.length; i++ )
                     sourceArray[i] = resultArray[i] as PurchasedSongVO;
                    this._purchasedSongsCollection.source = sourceArray;


          probably that helps someone with a similar issue

          • 2. HEUREKA!
            daslicht Level 2


            I found the solution  ane I am pleased to share it with you .


            Lets say we have a PHP Sevice which should return an Array of PurchasedSongsVO's,

            You have to add the return Type into a comment above the function.


            * Returns an array of PurchasedSongVO's
            * @return PurchasedSongVO
            public function getAllPurchasedSongs(){
                 <do something here>
                 return $resultArray


            Now the objects are typed and ready to use in Flex


            If anyone of you need help with this, just drop me a line.


            Have a nice day