<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; TimerEvent</title>
	<atom:link href="http://blog.flexexamples.com/category/timerevent/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using a timer to change the selected index of a ViewStack container in Flex</title>
		<link>http://blog.flexexamples.com/2008/01/04/using-a-timer-to-change-the-selected-index-of-a-viewstack-container-in-flex/</link>
		<comments>http://blog.flexexamples.com/2008/01/04/using-a-timer-to-change-the-selected-index-of-a-viewstack-container-in-flex/#comments</comments>
		<pubDate>Fri, 04 Jan 2008 16:14:53 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[Timer]]></category>
		<category><![CDATA[TimerEvent]]></category>
		<category><![CDATA[ViewStack]]></category>
		<category><![CDATA[selectedIndex]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/01/04/using-a-timer-to-change-the-selected-index-of-a-viewstack-container-in-flex/</guid>
		<description><![CDATA[<p>The following example shows how you can use a timer to change the selected index in a Flex ViewStack container.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ViewStack_selectedIndex_test/main.mxml">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2008/01/04/using-a-timer-to-change-the-selected-index-of-a-viewstack-container-in-flex/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="init();"&#62; &#60;mx:Script&#62; &#60;![CDATA[ private var timer:Timer; private function init():void { timer = new Timer(1000); [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can use a timer to change the selected index in a Flex ViewStack container.</p>
<p>Full code after the jump.</p>
<p><span id="more-418"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ViewStack_selectedIndex_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/01/04/using-a-timer-to-change-the-selected-index-of-a-viewstack-container-in-flex/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            private var timer:Timer;

            private function init():void {
                timer = new Timer(1000); /* 1000ms == 1second */
                timer.addEventListener(TimerEvent.TIMER, onTimer);
            }

            private function onTimer(evt:TimerEvent):void {
                var idx:uint = viewStack.selectedIndex;
                var max:uint = viewStack.numChildren;

                var newIdx:uint = ++idx % max;
                viewStack.selectedIndex = newIdx;
            }

            private function startTimer():void {
                if (!timer.running) {
                    timer.start();
                }
            }

            private function stopTimer():void {
                if (timer.running) {
                    timer.stop();
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Button label="Start timer" click="startTimer();" /&gt;
        &lt;mx:Button label="Stop timer" click="stopTimer();" /&gt;

        &lt;mx:Spacer width="100%" /&gt;

        &lt;mx:Label text="selectedIndex:" /&gt;
        &lt;mx:HSlider id="slider"
                minimum="0"
                maximum="3"
                liveDragging="true"
                snapInterval="1"
                tickInterval="1"
                change="viewStack.selectedIndex = event.value;" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:ViewStack id="viewStack" width="100%" height="100%"&gt;
        &lt;mx:VBox backgroundColor="haloBlue"
                width="100%"
                height="100%"&gt;
            &lt;mx:Label text="VBox 1" /&gt;
        &lt;/mx:VBox&gt;
        &lt;mx:VBox backgroundColor="haloGreen"
                width="100%"
                height="100%"&gt;
            &lt;mx:Label text="VBox 2" /&gt;
        &lt;/mx:VBox&gt;
        &lt;mx:VBox backgroundColor="haloOrange"
                width="100%"
                height="100%"&gt;
            &lt;mx:Label text="VBox 3" /&gt;
        &lt;/mx:VBox&gt;
        &lt;mx:VBox backgroundColor="haloSilver"
                width="100%"
                height="100%"&gt;
            &lt;mx:Label text="VBox 4" /&gt;
        &lt;/mx:VBox&gt;
    &lt;/mx:ViewStack&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/ViewStack_selectedIndex_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/ViewStack_selectedIndex_test/bin/main.html" width="100%" height="250"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Using a timer to change the selected index of a ViewStack container in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/01/04/using-a-timer-to-change-the-selected-index-of-a-viewstack-container-in-flex/',contentID: 'post-418',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'selectedIndex',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/01/04/using-a-timer-to-change-the-selected-index-of-a-viewstack-container-in-flex/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating a simple timer in Flex with the flash.utils.Timer class</title>
		<link>http://blog.flexexamples.com/2007/08/14/creating-a-simple-timer-in-flex-with-the-flashutilstimer-class/</link>
		<comments>http://blog.flexexamples.com/2007/08/14/creating-a-simple-timer-in-flex-with-the-flashutilstimer-class/#comments</comments>
		<pubDate>Wed, 15 Aug 2007 04:51:38 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Timer]]></category>
		<category><![CDATA[TimerEvent]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/14/creating-a-simple-timer-in-flex-with-the-flashutilstimer-class/</guid>
		<description><![CDATA[<p>Here&#8217;s an example of a simple timer which displays minutes, seconds, and milliseconds, which I built in Flex using the flash.utils.Timer class. You can start and stop the timer using two Button controls.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Timer_test/main.mxml">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2007/08/14/creating-a-simple-timer-in-flex-with-the-flashutilstimer-class/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="init()"&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an example of a simple timer which displays minutes, seconds, and milliseconds, which I built in Flex using the flash.utils.Timer class. You can start and stop the timer using two Button controls.</p>
<p>Full code after the jump.</p>
<p><span id="more-87"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Timer_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/08/14/creating-a-simple-timer-in-flex-with-the-flashutilstimer-class/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init()"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import flash.utils.Timer;
            import flash.events.TimerEvent;

            private const MIN_MASK:String = "00";
            private const SEC_MASK:String = "00";
            private const MS_MASK:String = "000";
            private const TIMER_INTERVAL:int = 10;

            private var baseTimer:int;

            private var t:Timer;

            private function init():void {
                t = new Timer(TIMER_INTERVAL);
                t.addEventListener(TimerEvent.TIMER, updateTimer);
            }

            private function updateTimer(evt:TimerEvent):void {
                var d:Date = new Date(getTimer() - baseTimer);
                var min:String = (MIN_MASK + d.minutes).substr(-MIN_MASK.length);
                var sec:String = (SEC_MASK + d.seconds).substr(-SEC_MASK.length);
                var ms:String = (MS_MASK + d.milliseconds).substr(-MS_MASK.length);
                counter.text = String(min + ":" + sec + "." + ms);
            }

            private function startTimer():void {
                baseTimer = getTimer();
                t.start();
            }

            private function stopTimer():void {
                t.stop();
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Button label="Start timer" click="startTimer()" /&gt;
        &lt;mx:Button label="Stop timer" click="stopTimer()" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:Label id="counter" fontSize="96" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/Timer_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/Timer_test/bin/main.html" width="100%" height="220"></iframe></p>
<p class="new">Here&#8217;s a similar version using the DateFormatter class. Note that unlike the previous code, this version doesn&#8217;t include milliseconds in the output.</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init()"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import flash.utils.Timer;
            import flash.events.TimerEvent;

            private const TIMER_INTERVAL:int = 10;

            private var baseTimer:int;

            private var t:Timer;

            private function init():void {
                t = new Timer(TIMER_INTERVAL);
                t.addEventListener(TimerEvent.TIMER, updateTimer);
            }

            private function updateTimer(evt:TimerEvent):void {
                var d:Date = new Date(getTimer() - baseTimer);
                counter.text = dateFormatter.format(d);
            }

            private function startTimer():void {
                baseTimer = getTimer();
                t.start();
            }

            private function stopTimer():void {
                t.stop();
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:DateFormatter id="dateFormatter" formatString="NN:SS" /&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Button label="Start timer" click="startTimer()" /&gt;
        &lt;mx:Button label="Stop timer" click="stopTimer()" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:Label id="counter" fontSize="96" /&gt;

&lt;/mx:Application&gt;
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Creating a simple timer in Flex with the flash.utils.Timer class on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/14/creating-a-simple-timer-in-flex-with-the-flashutilstimer-class/',contentID: 'post-87',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: '',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/08/14/creating-a-simple-timer-in-flex-with-the-flashutilstimer-class/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
	</channel>
</rss>

