3 Replies Latest reply on Mar 22, 2010 3:57 AM by benethridge

    How to display a component for X seconds?

    benethridge Level 1

      Hi, everyone.

       

      I have a sort of "slideshow" presentation that I'm writing in flex.  An image and its associated text fades in, displays in the browser long enough for the average reader to read it and fades out, to be replaced with the next image/text.

       

      I can set the delay for the fadein/out easily enough (using states and transition effects and the "delay" property), but how do I set a delay for the display itself?

       

      I'm thinking of coding timers and associated timer event listeners for this, one for each "slide" since the time it takes to read each slide will vary (some text is longer than others), but I was wondering if anyone had a more elegant solution...like say the "duration" property built into effects such as <mx:Fade> and <mx:Move>.

       

      Is there an existing "display" or "slideshow" Effect for this already?  or do you just write your own timer code (as I've seen elsewhere googling this)?

       

      Ben

        • 1. Re: How to display a component for X seconds?
          benethridge Level 1

          Another way of asking this would be:

           

          How do you get flex to hold a given state for X seconds?

           

          Ben

          • 2. Re: How to display a component for X seconds?
            Flex Smoker

            Hi Ben,

             

            Maybe you must use the Timer, here is a simple code:

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
                 creationComplete="init()"
                  backgroundColor="0xFFFFFF">
            <mx:Script>
                 <![CDATA[
                      import mx.controls.Alert;
                      
                      private var timer:Timer = new Timer(1000); //1000 = 1 sec
                      private function init():void{
                           this.timer.addEventListener(TimerEvent.TIMER,onTimer);
                           this.timer.start();
                      }
                      private function onTimer(e:TimerEvent):void{
                           this.btnTest.x = this.btnTest.y = this.timer.currentCount * 2;
                      }
                 ]]>
            </mx:Script>
            <mx:Button id="btnTest"/>
            </mx:Application>
            

             

            Enjoy.. =)

            • 3. Re: How to display a component for X seconds?
              benethridge Level 1

              Thanks, but I already coded my timers last night. I have it all working but I was just hoping for something directly supplied and supported by Adobe in MXML...like, say, the duration property for the effects.

               

              Ben