5 Replies Latest reply on Nov 6, 2007 3:58 PM by Tigomark

    Time in Flex

    Tigomark
      I am looking to find some examples to create a clock that counts down from 3 minutes to zero and when the clock hits zero it will refresh the application. I would also like this clock to be clickable so that it to would refresh the app.

      I have looked all over the net but have not seen any time/date examples anywhere.

      any help would be great
        • 1. Re: Time in Flex
          dimival Level 1
          I think you can use the Timer class to achieve that:

          http://livedocs.adobe.com/flex/201/langref/flash/utils/Timer.html

          Hope it helps
          • 3. Re: Time in Flex
            Tigomark Level 1
            I've also found this but I am getting some weird errors

            <mx:Script>
            <![CDATA[
            public class ShortTimer extends Sprite{

            public function ShortTimer()
            {
            // creates a new five-second Timer
            var minuteTimer:Timer = new Timer(1000, 300);

            // designates listeners for the interval and completion events
            minuteTimer.addEventListener(TimerEvent.TIMER, onTick);
            minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);

            // starts the timer ticking
            minuteTimer.start();
            }

            public function onTick(evt:TimerEvent):void
            {
            // displays the tick count so far
            // The target of this event is the Timer instance itself.
            trace("tick " + evt.target.currentCount);
            }

            public function onTimerComplete(evt:TimerEvent):void
            {
            refresh();
            }
            }
            ]]>
            </mx:Script>


            It keeps returning the error
            Severity Description Resource In Folder Location Creation Time Id
            2 1131: Classes must not be nested. line 15 November 1, 2007 9:26:24 AM 104
            • 4. Re: Time in Flex
              dimival Level 1
              The problem is that you are declaring a class inside a Script block which belongs to the mxml file, which is as well a class, so you are nesting classes.

              Remove the public class declaration and call the logic inside your constructor from the creationComplete event of your mxml component.
              • 5. Re: Time in Flex
                Tigomark Level 1
                I'm sorry but I don't have any of the things in my MXML file that you described

                This is my clock.as file
                package
                {
                import flash.display.Sprite;
                import flash.events.TimerEvent;
                import flash.utils.Timer;

                public class ShortTimer extends Sprite
                {
                public function ShortTimer()
                {
                // creates a new five-minute Timer
                var minuteTimer:Timer = new Timer(1000, 300);

                // designates listeners for the interval and completion events
                minuteTimer.addEventListener(TimerEvent.TIMER, onTick);
                minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);

                // starts the timer ticking
                minuteTimer.start();
                }

                public function onTick(evt:TimerEvent):void
                {
                // displays the tick count so far
                // The target of this event is the Timer instance itself.
                trace("tick " + evt.target.currentCount);
                }

                public function onTimerComplete(evt:TimerEvent):void
                {
                refresh();
                }
                }
                }


                and this is my main application file

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="100%" viewSourceURL="srcview/index.html" height="100%">
                <mx:Style source="source.css"/>
                <mx:Image source="images/title.jpg" width="210" height="65" top="4" left="15"/>
                <mx:Image source="images/title1.jpg" id="image1" horizontalAlign="right" verticalAlign="top" width="784" height="58" y="3" right="0"/>
                <mx:XML id="tempXML" source=" http://company.sitename.net/interface.php?username=user&amp;password=pass&amp;customer=suc tomer&amp;action=showopen&amp;operation=defects&amp;format=xml&amp;critcal=both" />

                <mx:XMLListCollection id="defectXMLList" source="{tempXML.defect}" />
                <mx:Script source="clock.as" />
                <mx:TileList
                dataProvider="{tempXML.defect.asset}"
                horizontalCenter="0" bottom="56" top="72" width="100%" backgroundColor="#000000" color="#ff0000" fontSize="27" borderColor="#000000" columnWidth="300" rowHeight="50" themeColor="#808080" fontWeight="bold" allowMultipleSelection="true"/>




                </mx:Application>