3 Replies Latest reply on Nov 7, 2010 9:44 AM by tim494

    Zend Amf : mapping a PHP Array to a Flex ArrayCollection

    tim494

      Hi,

       

      I would like to know if it is now possible to  map a PHP Array to a Flex ArrayCollection via Zend Amf, without using  any workaround.

      I have quite the same issue that has been reported  here (about one year ago) :  http://forums.adobe.com/thread/495999?decorator=print&displayFullThread=true

      It seems like it was a bug so I was wondering if it is supposed to work now because i'm still having the problem.

       

      It  works with Gaurav's workaround  (http://forums.adobe.com/message/2267088#2267088) which consists in  sending a Zend_Amf_Value_Messaging_ArrayCollection object instead of an  Array on the server side, but I was hoping I could get rid of the  workaround...

       

      Thanks in advance

       

      Tim

        • 2. Re: Zend Amf : mapping a PHP Array to a Flex ArrayCollection
          AdobeFlex1

          ..try to use ArrayUtil.toArray():

           

          import mx.utils.ArrayUtil;

           

          private var people:ArrayCollection = new ArrayCollection();

           

          protected function getPeopleInMyWorldResult_resultHandler(event:ResultEvent):void {

               people =  new ArrayCollection(ArrayUtil.toArray(event.result));

          }

          • 3. Re: Zend Amf : mapping a PHP Array to a Flex ArrayCollection
            tim494 Level 1

            Hello,

             

            This would surely work but it is not exactly what I need.

            In fact, I send an array from PHP, and since my value object property on the AS3 side is typed to an ArrayCollection, Zend Amf should automatically cast my Array into an ArrayCollection. That's what Zend Amf does, you send a custom object from the server side, it creates the corresponding object on the client side.

             

            My PHP Classes :

             

            class FileSystemItem
             {
                 public $name;        
                 public $parentFullPath;        
                 public $createdOn;            
                 public $lastAccessedOn;    
                 public $lastModifiedOn;
             }
            
            class FolderItem extends FileSystemItem
            {
                public $content = array();
            }
            
            class FileItem extends FileSystemItem
            {
                public $size;
            }
            

             

            The FileSystemItem represents either a folder or a file and initializes the common properties in its constructor.
            The FolderItem represents a Folder. It extends the FileSystemItem class with a "content" property which is an array containing FolderItem objects or FileItem Objects. The FolderItem class has a "loadContent" method to fill the content array.
            The FileItem represents a File. It extends the FileSytemItem class with a "size" property.

             

            Here are the corresponding AS3 classes used by Zend Amf to do the mapping :

             

            package valueObjects
            {
                [RemoteClass(alias="FileSystemItem")]
                [Bindable]
                public class FileSystemItem
                {
                    public var name:String;
                    public var parentFullPath:String;      
                    public var createdOn:String;          
                    public var lastAccessedOn:String;     
                    public var lastModifiedOn:String;
                }
            }
            
            
            package valueObjects
            {
                import mx.collections.ArrayCollection;
            
            
                [RemoteClass(alias="FolderItem")]
                [Bindable]
                public class FolderItem extends FileSystemItem
                {
                    public var content:ArrayCollection = new ArrayCollection();
                }
            }
            
            
            package valueObjects
            {
                [RemoteClass(alias="FileItem")]
                [Bindable]
                public class FileItem extends FileSystemItem
                {
                    public var size:int;
                }
            }
            

             

            I simplified my application to the minimum, it is just calling a service method to get a FolderItem with its content.

             

            protected function init():void
            {
                 var initTreeToken:AsyncToken = FileSystemBrowser.getFolder("C:/", "flexworks");
                 initTreeToken.addResponder(new mx.rpc.Responder(getFolder_initResultHandler, getFolder_faultHandler));
            }
                      
            protected function getFolder_initResultHandler(event:ResultEvent):void
            {
            }
            

             

            It works fine until then :

            network_monitor.JPG

             

            The problem occurs when the event.result property is populated, so I don't even get the chance to create an ArrayCollection from the received Array and put it into my "content" AS3 object property. It throws those errors (btw I wonder why there are four errors and not just one) :

             

            TypeError: Error #1034: Echec de la contrainte de type : conversion de []@7868269 en mx.collections.ArrayCollection impossible.
            TypeError: Error #1034: Echec de la contrainte de type : conversion de []@7868269 en mx.collections.ArrayCollection impossible.
            TypeError: Error #1034: Echec de la contrainte de type : conversion de []@7868269 en mx.collections.ArrayCollection impossible.
            TypeError: Error #1034: Echec de la contrainte de type : conversion de []@bc2ef39 en mx.collections.ArrayCollection impossible.

             

            I hope you see more clearly what I mean now...

             

            Thank you for trying to help me.

             

            Message was edited by: tim494