<?xml version="1.0" encoding="ISO-8859-1"?>
<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>DClick Team Weblog [en] &#187; ProgramaÃ§Ã£o</title>
	<atom:link href="http://blog.dclick.com.br/category/programacao/pt/feed/en/" rel="self" type="application/rss+xml" />
	<link>http://blog.dclick.com.br</link>
	<description>DClick Team Weblog</description>
	<lastBuildDate>Tue, 11 May 2010 11:07:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Logic Operator &#124;&#124;= in AS3</title>
		<link>http://blog.dclick.com.br/2009/08/28/logic-operator-in-as3/en/</link>
		<comments>http://blog.dclick.com.br/2009/08/28/logic-operator-in-as3/en/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 18:33:59 +0000</pubDate>
		<dc:creator>Bruno Sales</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Otimização]]></category>
		<category><![CDATA[Programação]]></category>

		<guid isPermaLink="false">http://blog.dclick.com.br/?p=2077</guid>
		<description><![CDATA[Twitter! Well, few people knows about the logic operator "&#124;&#124;=". I'll try to explain a little more about it.
In the adobe documentation, this operator is described like: "Assigns expression1 the value of expression1 &#124;&#124; expression2". Just to remember, the sintaxe to logic operator is "expression1 operator expression2".
I'll show some examples of how it works.

Exemple1:
PLAIN TEXT
ACTIONSCRIPT:




var [...]]]></description>
			<content:encoded><![CDATA[<span class="post-twitter" ><a href="http://twitter.com/home?status=DClick%20Post%3A%20%20%22Logic%20Operator%20%7C%7C%3D%20in%20AS3%22%20http%3A%2F%2Ftinyurl.com%2Fyhrq2m5" title="Twitter! <br /><br />" rel="nofollow">Twitter! <br /><br /></a></span><p>Well, few people knows about the logic operator "||=". I'll try to explain a little more about it.</p>
<p>In the adobe documentation, this operator is described like: "Assigns expression1 the value of expression1 || expression2". Just to remember, the sintaxe to logic operator is "<strong>expression1 operator expression2</strong>".</p>
<p>I'll show some examples of how it works.<br />
<span id="more-2077"></span></p>
<p>Exemple1:</p>
<div class="igBar"><span id="lactionscript-4"><a href="#" onclick="javascript:showPlainTxt('actionscript-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ACTIONSCRIPT:</span>
<div id="actionscript-4">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">array</span>:<span style="color: #0066CC;">Array</span>; <span style="color: #808080; font-style: italic;">// Variable arr is null.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">array</span> ||= <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">"Bruno Sales"</span><span style="color: #66cc66;">&#93;</span>; <span style="color: #808080; font-style: italic;">// In case array is null, assign the value [&quot;Bruno Sales&quot;]</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">array</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Result: New value assigned, trace prints &quot;Bruno Sales&quot; </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Exemple2:</p>
<div class="igBar"><span id="lactionscript-5"><a href="#" onclick="javascript:showPlainTxt('actionscript-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ACTIONSCRIPT:</span>
<div id="actionscript-5">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">array</span>:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">"DClick"</span><span style="color: #66cc66;">&#93;</span>; <span style="color: #808080; font-style: italic;">// Variable arr has the value [&quot;DClick&quot;].</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">array</span> ||= <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">"Bruno Sales"</span><span style="color: #66cc66;">&#93;</span>; <span style="color: #808080; font-style: italic;">// In case array is null, assign the value [&quot;Bruno Sales&quot;]</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">array</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Result: No value assigned, trace prints &quot;DClick&quot; </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Soon, looking the difference of this 2 exemples, we conclued that the logic operator "||=" makes the same thing of the code below, but in a better way.</p>
<div class="igBar"><span id="lactionscript-6"><a href="#" onclick="javascript:showPlainTxt('actionscript-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ACTIONSCRIPT:</span>
<div id="actionscript-6">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">array</span>:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">"DClick"</span><span style="color: #66cc66;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">array</span> == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">"Bruno Sales"</span><span style="color: #66cc66;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>I hope you all liked it. <img src='http://blog.dclick.com.br/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dclick.com.br/2009/08/28/logic-operator-in-as3/en/feed/en/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Variable Scope in ActionScrip 3</title>
		<link>http://blog.dclick.com.br/2009/07/25/variable-scope-in-actionscrip-3/en/</link>
		<comments>http://blog.dclick.com.br/2009/07/25/variable-scope-in-actionscrip-3/en/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 00:44:26 +0000</pubDate>
		<dc:creator>Bruno Sales</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programação]]></category>

		<guid isPermaLink="false">http://blog.dclick.com.br/?p=2068</guid>
		<description><![CDATA[Twitter! Do you know what happens in the follow code?
PLAIN TEXT
ACTIONSCRIPT:




var test:Boolean = false;


if&#40;test&#41;


&#123;


&#160; &#160; var name:String;


&#125;


else


&#123;


&#160; &#160; name = "Bruno Sales";


&#125;


trace&#40;"Name: " + name&#41;; 






Compile error? Runtime Error? Nothing. The trace result is "Name: Bruno Sales". The variable was created even if the code inside the IF was never executed.
Thats happens because ActionScript has [...]]]></description>
			<content:encoded><![CDATA[<span class="post-twitter" ><a href="http://twitter.com/home?status=DClick%20Post%3A%20%20%22Variable%20Scope%20in%20ActionScrip%203%22%20http%3A%2F%2Ftinyurl.com%2Fyl6k299" title="Twitter! <br /><br />" rel="nofollow">Twitter! <br /><br /></a></span><p>Do you know what happens in the follow code?</p>
<div class="igBar"><span id="lactionscript-8"><a href="#" onclick="javascript:showPlainTxt('actionscript-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">ACTIONSCRIPT:</span>
<div id="actionscript-8">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> test:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>test<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">else</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">name</span> = <span style="color: #ff0000;">"Bruno Sales"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Name: "</span> + <span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
Compile error? Runtime Error? Nothing. The trace result is "Name: Bruno Sales". The variable was created even if the code inside the IF was never executed.<br />
Thats happens because ActionScript has just 2 types of scope: Global and Local; remembering that Local is everything inside a function.</p>
<p>However, I suggest <strong>never</strong> using something like this in your development process. Your code logic will be very confusing and will cause problem to maintenance and debug.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dclick.com.br/2009/07/25/variable-scope-in-actionscrip-3/en/feed/en/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
