<?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>DoNotYet.com &#187; Sleep</title>
	<atom:link href="http://www.donotyet.com/tag/sleep/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.donotyet.com</link>
	<description>Freebie Resources for Tech Users, AIR, Flex, Flash Developers and Photoshop, web Designers</description>
	<lastBuildDate>Wed, 07 Dec 2011 06:35:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Wait or Sleep in Flex/ActionScript</title>
		<link>http://www.donotyet.com/2009/08/28/how-to-wait-or-sleep-in-flex-actionscript/</link>
		<comments>http://www.donotyet.com/2009/08/28/how-to-wait-or-sleep-in-flex-actionscript/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 14:52:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[Sleep]]></category>

		<guid isPermaLink="false">http://www.donotyet.com/2009/08/28/how-to-wait-or-sleep-in-flex-actionscript/</guid>
		<description><![CDATA[If you want to upload a big file to server or do a long time action in Flex/ActionScript like HTTPService to communicate with an external server that hosts the database, a time delay function like Sleep() will be needed. 
So, is there a sleep function in flex 2 ? Run multi-thread, one sleep and wait [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to upload a big file to server or do a long time action in Flex/ActionScript like HTTPService to communicate with an external server that hosts the database, a time delay function like Sleep() will be needed. </p>
<p>So, is there a sleep function in flex 2 ? Run multi-thread, one sleep and wait the result of this thread and the other will be continue.</p>
<p>Unfortunatly, because the flash player, from our perspective, is single threaded so we can not do that.</p>
<div style="margin: 0px 0px 0px 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-7859640280892154";
/* DoNotYet-Article-336-280-01 */
google_ad_slot = "0432827541";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p><span id="more-145"></span>  </p>
<p><a href="http://www.donotyet.com/wp-content/uploads/2009/08/WindowsLiveWriterHowtoWaitorSleepinFlexActionScript_14F96Sleep-and-wait-in-Flex_2.png"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="Sleep-and-wait-in-Flex" src="http://www.donotyet.com/wp-content/uploads/2009/08/WindowsLiveWriterHowtoWaitorSleepinFlexActionScript_14F96Sleep-and-wait-in-Flex_thumb.png" width="504" height="372" /></a> </p>
<p>But we can flash.utils.Timer to get the same effect:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Blue;">setTimout</span><span style="color: Olive;">(</span><span style="color: Gray;"> </span><span style="color: Blue;">yourFunction</span><span style="color: Gray;"> ,</span><span style="color: Maroon;">200</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li></ol></div>
<p>This function will call yourFunction after waiting 200 milliseconds.
<p>The explanation of setTimeout() function:</p>
<blockquote><p>Runs a specified function after a specified delay (in milliseconds). </p>
<p>Instead of using this method, consider creating a Timer object, with the specified interval, using 1 as the <code>repeatCount</code> parameter (which sets the timer to run only once).</p>
<p>If you intend to use the <code>clearTimeout()</code> method to cancel the <code>setTimeout()</code> call, be sure to assign the <code>setTimeout()</code> call to a variable (which the <code>clearTimeout()</code> function will later reference). If you do not call the <code>clearTimeout()</code> function to cancel the <code>setTimeout()</code> call, the object containing the set timeout closure function will not be garbage collected. </p>
<p> setTimeout():</p>
<p>Runs a specified function after a specified delay (in milliseconds). </p>
<p>Instead of using this method, consider creating a Timer object, with the specified interval, using 1 as the <code>repeatCount</code> parameter (which sets the timer to run only once).</p>
<p>If you intend to use the <code>clearTimeout()</code> method to cancel the <code>setTimeout()</code> call, be sure to assign the <code>setTimeout()</code> call to a variable (which the <code>clearTimeout()</code> function will later reference). If you do not call the <code>clearTimeout()</code> function to cancel the <code>setTimeout()</code> call, the object containing the set timeout closure function will not be garbage collected. </p>
</blockquote>
<p>Here is the list of functions for timing code execution: <a title="http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html" href="http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html">http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html</a></p>
<h3>Related Posts</h3>
<ul class="related_post">
<li><a href="http://www.donotyet.com/2010/01/14/7-actionscript-class-let-you-using-xml-easily/" title="7+ ActionScript Class Let You Using XML Easily">7+ ActionScript Class Let You Using XML Easily</a></li>
<li><a href="http://www.donotyet.com/2009/09/27/aszip-a-very-useful-actionscript-3-library-to-generate-zip-file-with-simple-interface/" title="ASZip: A Very Useful ActionScript 3 library to Generate ZIP file with Simple Interface">ASZip: A Very Useful ActionScript 3 library to Generate ZIP file with Simple Interface</a></li>
<li><a href="http://www.donotyet.com/2009/08/15/an-example-of-how-to-load-flashpaper-in-flex/" title="An example of How to load FlashPaper in Flex(with source code)">An example of How to load FlashPaper in Flex(with source code)</a></li>
<li><a href="http://www.donotyet.com/2009/08/09/5-very-beautiful-skins-for-flex-applications/" title="5+ Very Beautiful Skins for Flex Applications">5+ Very Beautiful Skins for Flex Applications</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.donotyet.com/2009/08/28/how-to-wait-or-sleep-in-flex-actionscript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

