14 Replies Latest reply on Sep 6, 2010 2:26 AM by flexillu10

    How to bind a PHP service to an ArrayCollection

    flexillu10 Level 1

      Ok. i have used Flash builder data connect wizard to connect to my database and generate some PHP services.

       

      One of them being a get all service.

       

       

      servicebox.png

      I can drag and drop that onto a datagrid fine and it works.

       

      But

      Could someone please tell me, with as much detail as possible how to call that service, and bind it to an array/arraycollection.

        • 2. Re: How to bind a PHP service to an ArrayCollection
          daslicht Level 2

          Hi,

           

          you need a Result handler which casts the ResultEvent as ArrayCollection.

           

          Have a nice day!

          Marc

          • 3. Re: How to bind a PHP service to an ArrayCollection
            flexillu10 Level 1

            daslicht wrote:

             

            Hi,

             

            you need a Result handler which casts the ResultEvent as ArrayCollection.

             

            Have a nice day!

            Marc

             

            could you give me some example code, i use flash builder to generate my result handlers, how do i create one for this service?

            • 4. Re: How to bind a PHP service to an ArrayCollection
              daslicht Level 2

              Hi,

              do you like to post your service call, please?

              Cheers

              Marc

              • 5. Re: How to bind a PHP service to an ArrayCollection
                flexillu10 Level 1

                Hello,

                 

                Sorry all i have is the service shown in my above post, it was generated by flash builder.

                 

                I just want to call it, and store it in an array, how do i do that?

                • 6. Re: How to bind a PHP service to an ArrayCollection
                  flexillu10 Level 1

                  if i right click on it and select generate service call; this code is generated

                   

                  protected function getAllTbl_images():void
                          {
                              getAllTbl_imagesResult.token = tblimagesService.getAllTbl_images();
                          }

                  • 7. Re: How to bind a PHP service to an ArrayCollection
                    Subeesh Arakkan Level 4

                    Hi,

                     

                    Check this code. You need to import the correct namespace of the service.

                     

                    <?xml version="1.0" encoding="utf-8"?>
                    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"     
                         xmlns:s="library://ns.adobe.com/flex/spark"
                         xmlns:mx="library://ns.adobe.com/flex/mx" 
                         minWidth="955" minHeight="600">
                         <fx:Script>
                              <![CDATA[
                                   import mx.collections.ArrayCollection;
                                   import mx.rpc.events.FaultEvent;
                                   import mx.rpc.events.ResultEvent;
                                   
                                   [Bindable]private var images:ArrayCollection; 
                    
                                   protected function myService_resultHandler(event:ResultEvent):void
                                   {
                                        images = event.result as ArrayCollection;
                                   }
                    
                    
                                   protected function myService_faultHandler(event:FaultEvent):void
                                   {
                                        trace(event.fault.faultString);
                                   }
                    
                    
                                   protected function button1_clickHandler(event:MouseEvent):void
                                   {
                                        myService.tblimagesService.getAllTbl_images();
                                   }
                    
                              ]]>
                         </fx:Script>
                         
                         <s:Button label="Get Data" click="button1_clickHandler(event)"/>
                         
                         <fx:Declarations>
                              <services:TblImagesService id="myService" 
                                   result="myService_resultHandler(event)" fault="myService_faultHandler(event)"/>
                         </fx:Declarations>
                    
                    </s:Application>
                    
                    • 8. Re: How to bind a PHP service to an ArrayCollection
                      daslicht Level 2

                      Yeah that should do the job!

                      • 9. Re: How to bind a PHP service to an ArrayCollection
                        flexillu10 Level 1

                        thanks, but how do i know which namespace it is?

                         

                         

                        It says the prefix services is unbound?

                        • 10. Re: How to bind a PHP service to an ArrayCollection
                          Subeesh Arakkan Level 4

                          start typing the custom TblImagesService tag and flash builder will automataiically import the namespace for you just like the code completion for all the other flex controls in mxml

                          • 11. Re: How to bind a PHP service to an ArrayCollection
                            flexillu10 Level 1

                            ok, not sure if it's working. In the click handler i get an error:

                             

                            Multiple markers at this line:
                            -myService
                            -1119: Access of possibly undefined property tblimagesService through a reference with static type
                            services.tblimagesservice:TblimagesService.

                             

                            and when i try and type it the auto complete can't find it:

                             

                            myservice.png

                             

                            any ideas?

                            • 12. Re: How to bind a PHP service to an ArrayCollection
                              Subeesh Arakkan Level 4

                              Hi,

                               

                              I meant to use the code completion when you create the service instance in MXML.

                               

                              <?xml version="1.0" encoding="utf-8"?>
                              <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"    
                                   xmlns:s="library://ns.adobe.com/flex/spark"
                                   xmlns:mx="library://ns.adobe.com/flex/mx"
                                   minWidth="955" minHeight="600"
                                   xmlns:services="services.*"
                                  
                              >
                                   <fx:Script>
                                        <![CDATA[
                                             import mx.collections.ArrayCollection;
                                             import mx.rpc.events.FaultEvent;
                                             import mx.rpc.events.ResultEvent;
                                            
                                             [Bindable]private var images:ArrayCollection;

                                             protected function myService_resultHandler(event:ResultEvent):void
                                             {
                                                  images = event.result as ArrayCollection;
                                             }


                                             protected function myService_faultHandler(event:FaultEvent):void
                                             {
                                                  trace(event.fault.faultString);
                                             }


                                             protected function button1_clickHandler(event:MouseEvent):void
                                             {
                                                  myService.tblimagesService.getAllTbl_images();
                                             }

                                        ]]>
                                   </fx:Script>
                                  
                                   <s:Button label="Get Data" click="button1_clickHandler(event)"/>
                                  
                                   <fx:Declarations>
                                        <services:TblImagesService id="myService"
                                             result="myService_resultHandler(event)" fault="myService_faultHandler(event)"/>
                                   </fx:Declarations>

                              </s:Application>

                               

                               

                              The previous example is modified to include the namespace in the application tag, assuming that yourTblImagesService is in the services folder. If it is different, change the namespace declaration .

                              • 13. Re: How to bind a PHP service to an ArrayCollection
                                flexillu10 Level 1

                                ok yeah i think its working anyway, do you know any easy way to test it?


                                • 14. Re: How to bind a PHP service to an ArrayCollection
                                  flexillu10 Level 1

                                  When i debug the application i can look through the array and see the data i want, but when i call toString() on one of the items in the arraycollection i am getting "Object:Imagedetails[]"

                                   

                                  Can anyone tell me how i can get the data out of the object?

                                   

                                  Do i need a call responder?