8 Replies Latest reply on Dec 11, 2009 2:27 PM by pir897

    Timer and loop questions

    pir897

      I have a TimerEvent that updates the index of a ComboBox that loops through XML content as if they were slides.  Currently there are 6 slides in my XML file but when I run the presentation it only goes through 3 before looping back to the first slide.  I shuffled the XML slide order and it still only showed the 3 so I don't believe there is a problem in the XML.  I can also test the data and get a response with all of the content in FlashBuilder.

       

      How do I get it go go through the entire XML file before looping back to the first.  Could it be that it is only loading the first 3 before the application begins playing?

       

      The XML data is pulled through an httpService that was created via the Data/Services tab.

       

      Forgive me, this originally started as a drop down list before I converted to a combo box.  The id for the combo box is still "dropDownList".

       

      The AS

      private var timer:Timer;               
                     
      private function init():void 
      {
          timer = new Timer(2500);
          timer.addEventListener(TimerEvent.TIMER, onTimer);
          timer.start();
      }
                     
      private function onTimer(evt:TimerEvent):void 
      {
          var idx:uint = dropDownList.selectedIndex;
          var max:uint = dropDownList.numChildren;
          var newIdx:uint = ++idx % max;
          dropDownList.selectedIndex = newIdx;
      }
      

       

      Some MXML

      <fx:Binding source="dropDownList.selectedItem as Slide" destination="slide"/>
      
      <mx:ComboBox editable="true"
          x="10" y="10" 
          id="dropDownList" 
          creationComplete="dropDownList_creationCompleteHandler(event)" 
          dataProvider="{getSlidesResult.lastResult}" 
          labelField="number"
          visible="false" />
      

       

       

      Once this is resolved I need to find answers to two more problems:

      1. How can I refresh the XML data at the end of each loop.  The XML file is going to be constantly updated.

      2. There will be some video content.  I would like to be able to cancel the timer for slides with a video and add a listener that forwards to the next slide when the video is complete.

        • 1. Re: Timer and loop questions
          Flex harUI Adobe Employee

          var max:uint = dropDownList.dataProvider.length;

           

          You can call send() on your HTTPService to get data again.  If the url does not change, you might need to add a fake parameter to the url that does change so the browser won't serve the old one from the cache.

           

          You could create a custom event that fires from both the timer and the video to indicate that it is time to advance. Shut off the timer if you are playing a video.

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          1 person found this helpful
          • 2. Re: Timer and loop questions
            pir897 Level 1

            The dataProvider.length worked perfectly.

             

            Can you dumb down the HTTPService suggestion a bit for a guy who lives in a world of CSS & HTML?  Do I need to create a listener to know when I've reached the end of the XML list?  If so, where do I add it.  The HTTPService info is in a package named services.slidesservice.  That AS file has this function

             

                 public function getSlides() : AsyncToken
                 {
                      var _internal_operation:AbstractOperation = _serviceControl.getOperation("getSlides");
                      var _internal_token:AsyncToken = _internal_operation.send() ;
            
                      return _internal_token;
                 }
            

             

            Is this the right send operation?

             

            Thanks for your help.

            • 3. Re: Timer and loop questions
              pir897 Level 1

              I answered the video portion of my question by adding in some event handlers to the VideoPlayer.

               

               

               

              protected function VideoPlayer_readyHandler(event:VideoEvent):void
              {
                  timer.stop();
              }
              
              protected function VideoPlayer_completeHandler(event:VideoEvent):void
              {
                  timer.start();
                                  
              }
              

               

              Now I need to unload the FLV in the completeHandler too.  I know how to do that in AS2 in an FLVPlayback, but it appears the VideoPlayer is different.

              • 4. Re: Timer and loop questions
                Flex harUI Adobe Employee

                You'll know you hit the end when max == selectedIndex.

                 

                I don't use HTTPService much so other folks may better help you.  Where is the code that gets the original data set?

                 

                Alex Harui

                Flex SDK Developer

                Adobe Systems Inc.

                Blog: http://blogs.adobe.com/aharui

                • 5. Re: Timer and loop questions
                  rfrishbe Level 3

                  To unload content in the new Spark VideoPlayer, you can just set the source to null or set it to another valid video source and the old one should unload.

                   

                  -Ryan

                  1 person found this helpful
                  • 6. Re: Timer and loop questions
                    pir897 Level 1

                    That worked.  I also had success using VideoPlayer.visible=false, but I'll stick with your version since I don't have to make it visible again later.

                    • 7. Re: Timer and loop questions
                      pir897 Level 1

                      SlidesService.as

                      package services.slidesservice
                      {
                      
                      public class SlidesService extends _Super_SlidesService
                      {
                      
                                     
                      }
                      
                      }
                      

                       

                      _Super_SlidesService

                      package services.slidesservice
                      {
                      import mx.rpc.AsyncToken;
                      import com.adobe.fiber.core.model_internal;
                      import mx.rpc.AbstractOperation;
                      import valueObjects.Slide;
                      import com.adobe.fiber.services.wrapper.HTTPServiceWrapper;
                      import mx.rpc.http.HTTPMultiService;
                      import mx.rpc.http.Operation;
                      import com.adobe.serializers.xml.XMLSerializationFilter;
                      [ExcludeClass]
                      internal class _Super_SlidesService extends HTTPServiceWrapper
                      {      
                          private static var serializer0:XMLSerializationFilter = new XMLSerializationFilter();
                             
                          // Constructor
                          public function _Super_SlidesService()
                          {
                              // initialize service control
                              _serviceControl = new HTTPMultiService(""); 
                               var operations:Array = new Array();
                               var operation:Operation;  
                               var argsArray:Array;       
                               
                               operation = new Operation(null, "getSlides");
                               operation.url = "http://xxxx/slides1.xml";
                               operation.method = "GET";
                               operation.serializationFilter = serializer0;
                               operation.properties = new Object();
                               operation.properties["xPath"] = "/::slide";
                                 operation.resultElementType = valueObjects.Slide;
                               operations.push(operation);
                          
                               _serviceControl.operationList = operations;  
                      
                          
                                            
                               model_internal::initialize();
                          }
                      
                           /**
                             * This method is a generated wrapper used to call the 'getSlides' operation. It returns an AsyncToken whose 
                             * result property will be populated with the result of the operation when the server response is received. 
                             * To use this result from MXML code, define a CallResponder component and assign its token property to this method's return value. 
                             * You can then bind to CallResponder.lastResult or listen for the CallResponder.result or fault events.
                            *
                            * @see mx.rpc.AsyncToken
                            * @see mx.rpc.CallResponder 
                            *
                            * @return an AsyncToken whose result property will be populated with the result of the operation when the server response is received.
                             */          
                           public function getSlides() : AsyncToken
                           {
                                var _internal_operation:AbstractOperation = _serviceControl.getOperation("getSlides");
                                var _internal_token:AsyncToken = _internal_operation.send() ;
                      
                                return _internal_token;
                           }   
                            
                      }
                      
                      }
                      
                      • 8. Re: Timer and loop questions
                        pir897 Level 1

                        I just want to make sure you saw my reply.