2 Replies Latest reply on Mar 5, 2010 6:41 PM by joelisaachart@gmail.com

    Using PHP Data Services to create an object and accessing that objects data in an unbound way in AS

    joelisaachart@gmail.com

      Hello,

       

      I've been able to use the php data services and bind the results of a function to a component. However I am having a hard time figuring out the syntax to use the data services to create an object out of the results, and then use that object as an array of filenames to provide the current index of the filename to a new sound object.

       

      My problem is obviously in not being able to figure out the specific syntax, I have declared the service and and object of the services returned type and in the creationComplete() function I have assigned object.token = service.getData();

       

      I've tried various ways of then pulling that data out of the object, with no success.

       

      Can someone point me in the right direction?

       

      This code probably looks horrible because it doesn't work yet.

       

      - Joel

       

                  import flash.media.Sound;
                  import flash.media.SoundChannel;
                  import mx.controls.Alert;
                 
                  var playing:Sound = new Sound();
                  var channel:SoundChannel = new SoundChannel();
                  var sndIndex:int=0;
                  var skpTr:String;
                 
                  public function init():void{
                   mp3Array.token = mp3service.getData();
                   currentTrack(mp3Array.lastResult.filename); 
                       trace(mp3Array.lastResult.filename[sndIndex]);
                  }
                 
                  public function currentTrack(t:String):void{
                      playing = new Sound();
                      playing.load(new URLRequest("mp3/" +t));
                  }
                 
                  public function skip():void{
                     
                     
                      stop();
                     
                      if (sndIndex != mp3Array.lastResult.length-1){
                          sndIndex++;
                          var skipTr:String=mp3Array.lastResult.filename[sndIndex].data;
                          currentTrack(skipTr);
                          play();
                      } else {
                          sndIndex=0;
                          skipTr=mp3Array.lastResult.filename[sndIndex].data;
                          currentTrack(skipTr);
                          play();
                      }
                     
                     
                     
                  }
                 
                  public function stop():void{
                      channel.stop();
                  }
                 
                  public function play():void{
                      channel = playing.play();
                  }

       

          <fx:Declarations>
              <s:CallResponder id="mp3Array"/>
              <mp3services:Mp3Service id="mp3service" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>

        • 1. Re: Using PHP Data Services to create an object and accessing that objects data in an unbound way in
          jdesko

          Hello Joel;

           

          In retrieving your data - what is your php returning to FB, an object, object array, an array?  Either way, I have a brief example below that an object(s) is being returned.  Pull the data from the lastResult in a ResultEvent.  The object instantiated in the resultEvent will contain your data and you can do what you want from there. 

           

          Also, I always use Network Monitor to see what data (if any) is being returned from the server, you can also see how it is being sent back.

           

          John

           

           

          private function init():void

          {
               mp3Array.token = mp3service.getData();

               mp3Array.addEventListener(FaultEvent.FAULT, faultHandler);

               mp3Array.addEventListener(ResultEvent.RESULT, mp3Array_resultHandler);

          }

           

          protected function faultHandler(event:FaultEvent):void

          {

               Alert.show("There was a fault error!" + event.message, "Fault Error", Alert.OK);

          }

           

          protected function mp3Array_resultHandler(event:ResultEvent):void

          {

               // Not sure if your service is sending back an object or an array or ?

              var info:Object = mp3Array.lastResult;

               doSomeFunction(info)

          }

           

          protected function doSomeFunction(data:Object):void

          {

               trace(info.filename);

          }