6 Replies Latest reply on Dec 14, 2009 2:21 PM by pir897

    Help adding a variable to a timer

    pir897 Level 1

      I'm building a slideshow presentation using Flash Builder 4 beta.  I need to be able to set a timer delay with the time coming from my XML file so each slide can have a different duration.

       

      The script for the timer is:

       

      private function init():void
                  {
                      timer = new Timer(2500);
                      timer.addEventListener(TimerEvent.TIMER, onTimer);
                      timer.start();
                  }

       

       

      I need to take "timer = new Timer(2500);" and replace the hard coded "2500" with a result from my XML.  Example from the XML file:

      <duration>10000</duration>
      

       

      How do I go about doing this?

        • 1. Re: Help adding a variable to a timer
          SHevenal776 Level 1

          How are you accessing your XML file from the client, an HTTPService?

          • 2. Re: Help adding a variable to a timer
            pir897 Level 1

            Yes, HTTPMultiService.  I set it up through the Data/Services tab.

            • 3. Re: Help adding a variable to a timer
              pir897 Level 1

              I really need to get this answered right away.  I'm getting unbelievable pressure to get this done and this is one of the last problems.

               

              As I mentioned before the time is currently set in the function with:

              timer = new Timer(2500);

               

              When I had my duration set as a text item to test my XML it looked like this:

              <mx:Text id="durationText" text="{slide.duration}"/>

               

               

              There has to be some way to replace (2500) with the result of {slide.duration}.  Help please!

              • 4. Re: Help adding a variable to a timer
                pir897 Level 1

                Can I somehow set my timer.delay = slide.duration?  I've tried a few variations of this but I get

                "Implicit coercion of a value of type String to an unrelated type Number."

                • 5. Re: Help adding a variable to a timer
                  pir897 Level 1

                  I'm trying to set my timer.delay using my slide.duration.  The problem is the timer.delay requires a Number where my slide.duration is a String.  I tried this:

                   

                  var delayString:Number = slide.duration as Number;

                  timer.delay = (delayString);

                   

                  It didn't throw any error codes when I saved it but didn't add any delay to my timer.  I'm still hunting for an answer.

                  • 6. Re: Help adding a variable to a timer
                    pir897 Level 1

                    Maybe a little closer...

                     

                    var delayString:Number =  8000;
                    var delayNum:Number = delayString;
                    timer.delay = (delayNum);

                     

                    This works to add an 8 second delay.  Apparently using "slide.duration as Number" isn't pulling the info I need.  I'm sure its something "as Number" that I have to use to replace the 8000.  I just need to figure out what that is.

                     

                     

                    EDIT:   I was able to go through and  change my delay from a String to a Number so I can do away with the "as Number" bit.  I still don't know what to use as my timer since neither timer.delay = slide.duration nor timer.delay = (slide.duration) give me a delay.