3 Replies Latest reply on Oct 1, 2010 1:29 AM by matt@tintisha

    Calling an AS function after data is retrieved

    matt@tintisha

      Hi,

       

      I have an application which  gets data from a database using php. I would like the data that is  retrieved with a creationComplete call to be used in another function  which also is called automatically when the application is opened. This  causes nothing to be displayed because the second function is called  before the data has been retrieved.

       

      Is there a way of  delaying a function until after the data has been successfully  downloaded, or calling the function as a consequence of the successful  data retrieval? As it is, I have to use a button to call the second  function which I would like to run automatically.

       

      Thank you

        • 1. Re: Calling an AS function after data is retrieved
          Arun Ganesh

          How did you connect to the php server?

          HttpService or URLLoader...


          You can add the addEventListener with event handler(where u get the result), which is wait upto the date retrieved.

          If your data get retrieved succesfully means that listener automatically call the event handler, there u can call ur AS function

          • 2. Re: Calling an AS function after data is retrieved
            matt@tintisha Level 1

            Thank you for your response. I am still not sure what I need to add the eventlistener to.

             

            I connected to the php server using Flash Builder 4's built in 'Connect to PHP' option and then to collect all of the data I use:

             

             

            protected function getData():void{
                    getAllDataResult.token = dataService.getAllData();
            }

             

            I then want to use 'name' of each member's data to populate a function that I would like to run after the data is retrieved:

             

             

            private function addMembers():void{

             

                 for(var a:int=0;a<getAllDataResult.lastResult.length;a++){
                      var memberProfile:MemberProfileCpt = new MemberProfileCpt;

                      viewport.addElement(memberProfile);

                      memberProfile.name.text = getAllDataResult.lastResult[a]['name'];

             

            }

             

            If I use a button to call the addMembers function then it works fine. I need a way to automatically run the second function after the getData process has completed.

             

            Thank you.

            • 3. Re: Calling an AS function after data is retrieved
              matt@tintisha Level 1

              Hi,

               

              If anyone is interested in the answer to this I found that you can run a function after the service call has collected the data by adding:

               

              result="function(event)"

               

              to the service call in the declarations. For example if your service is called MainService:

               

              <mainservice:MainService id="mainService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true" result="mainService_resultHandler(event)"/>

               

              will run the mainService_resultHandler function on completion.