﻿<?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>Armando Leopoldo Keller &#187; Armando Leopoldo Keller</title>
	<atom:link href="http://armandokeller.com/blog/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://armandokeller.com/blog</link>
	<description>Actionscript, AIR, Python, Engenharia Elétrica....</description>
	<lastBuildDate>Tue, 24 Jan 2012 19:26:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Pesquisa de Mercado</title>
		<link>http://armandokeller.com/blog/2012/01/pesquisa-de-mercado/</link>
		<comments>http://armandokeller.com/blog/2012/01/pesquisa-de-mercado/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 19:25:28 +0000</pubDate>
		<dc:creator>Armando Leopoldo Keller</dc:creator>
				<category><![CDATA[Sem categoria]]></category>

		<guid isPermaLink="false">http://armandokeller.com/blog/?p=131</guid>
		<description><![CDATA[0savesSave Quem tiver um tempo favor responder a pesquisa (4 perguntas) https://docs.google.com/spreadsheet/viewform?formkey=dDM0Qkt2cDRHa0toSl9xRWRaY2NFelE6MQ Obrigado]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript">
			<!-- 
				tweetmeme_url = "http://armandokeller.com/blog/2012/01/pesquisa-de-mercado/";
				tweetmeme_source = "tweetmeme";
				tweetmeme_style = "";
				
			//-->
			</script>
                        <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script>
			<!-- 
			var fbShare = {
				url: "http://armandokeller.com/blog/2012/01/pesquisa-de-mercado/",
				size: "large",
				google_analytics: "true"
			}
			//-->
			</script>
                        <script src="http://widgets.fbshare.me/files/fbshare.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript"><!-- 
		(function() {
		var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
		s.type = 'text/javascript';
		s.async = true;
		s.src = 'http://widgets.digg.com/buttons.js';
		s1.parentNode.insertBefore(s, s1);
		})();
		//-->
		</script><a class="DiggThisButton " href="http://digg.com/submit?url=http%3A%2F%2Farmandokeller.com%2Fblog%2F2012%2F01%2Fpesquisa-de-mercado%2F"></a></div><div class="socialize-in-button socialize-in-button-vertical"><div class="delicious-button"><div class="del-top"><span id="131">0</span>saves</div><div class="del-bot"><a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;">Save</a></div></div>
		<script>
			<!-- 
			function displayURL(data) { var urlinfo = data[0]; if (!urlinfo.total_posts) return;document.getElementById('131').innerHTML = urlinfo.total_posts;}
			//-->
		</script>
		<script src = "http://badges.del.icio.us/feeds/json/url/data?url=http://armandokeller.com/blog/2012/01/pesquisa-de-mercado/&amp;callback=displayURL"></script></div></div><p>Quem tiver um tempo favor responder a pesquisa (4 perguntas) <a href="https://docs.google.com/spreadsheet/viewform?formkey=dDM0Qkt2cDRHa0toSl9xRWRaY2NFelE6MQ" title="https://docs.google.com/spreadsheet/viewform?formkey=dDM0Qkt2cDRHa0toSl9xRWRaY2NFelE6MQ">https://docs.google.com/spreadsheet/viewform?formkey=dDM0Qkt2cDRHa0toSl9xRWRaY2NFelE6MQ</a></p>
<p>Obrigado</p>
]]></content:encoded>
			<wfw:commentRss>http://armandokeller.com/blog/2012/01/pesquisa-de-mercado/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyObjC Python no XCode</title>
		<link>http://armandokeller.com/blog/2010/06/pyobjc-python-no-xcode/</link>
		<comments>http://armandokeller.com/blog/2010/06/pyobjc-python-no-xcode/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 17:46:20 +0000</pubDate>
		<dc:creator>Armando Leopoldo Keller</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[eletrônica]]></category>
		<category><![CDATA[geral]]></category>
		<category><![CDATA[pessoal]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Sem categoria]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[controle]]></category>
		<category><![CDATA[integração]]></category>
		<category><![CDATA[Mac OS]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Petroleo]]></category>
		<category><![CDATA[PIC]]></category>
		<category><![CDATA[Projeto]]></category>
		<category><![CDATA[PyObjC]]></category>
		<category><![CDATA[rs232]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://armandokeller.com/blog/?p=100</guid>
		<description><![CDATA[Como utilizar python com XCode para desenvolver aplicaçoes nativas apra o Mac OS, algumas divagaçoes sobre o futuro do projeto do sistema de controle com PIC e RS232, e da minha vida profissional e pessoal, algumas teorias sobre o petroleo... ]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript">
			<!-- 
				tweetmeme_url = "http://armandokeller.com/blog/2010/06/pyobjc-python-no-xcode/";
				tweetmeme_source = "tweetmeme";
				tweetmeme_style = "";
				
			//-->
			</script>
                        <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script>
			<!-- 
			var fbShare = {
				url: "http://armandokeller.com/blog/2010/06/pyobjc-python-no-xcode/",
				size: "large",
				google_analytics: "true"
			}
			//-->
			</script>
                        <script src="http://widgets.fbshare.me/files/fbshare.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript"><!-- 
		(function() {
		var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
		s.type = 'text/javascript';
		s.async = true;
		s.src = 'http://widgets.digg.com/buttons.js';
		s1.parentNode.insertBefore(s, s1);
		})();
		//-->
		</script><a class="DiggThisButton " href="http://digg.com/submit?url=http%3A%2F%2Farmandokeller.com%2Fblog%2F2010%2F06%2Fpyobjc-python-no-xcode%2F"></a></div><div class="socialize-in-button socialize-in-button-vertical"><div class="delicious-button"><div class="del-top"><span id="100">0</span>saves</div><div class="del-bot"><a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;">Save</a></div></div>
		<script>
			<!-- 
			function displayURL(data) { var urlinfo = data[0]; if (!urlinfo.total_posts) return;document.getElementById('100').innerHTML = urlinfo.total_posts;}
			//-->
		</script>
		<script src = "http://badges.del.icio.us/feeds/json/url/data?url=http://armandokeller.com/blog/2010/06/pyobjc-python-no-xcode/&amp;callback=displayURL"></script></div></div><p>Bom, faz uma semana que estou com meu macbook, mas estou em epoca de provas na faculdade e não tive muito tempo de estudar ObjC, mas queria fazer algo nativo para o mac. Então fui procurar como desenvolver em uma linguagem que eu ja conheço, no caso Python.<br />
Acabei encontrando o PyObjC ( <a href="http://pyobjc.sourceforge.net/ ">http://pyobjc.sourceforge.net/ </a>) que utilizado junto com o XCode é uma maravilha para desenvolver.</p>
<p>Primeiro vai precisar instalar o XCode (<a href=" http://developer.apple.com/technologies/xcode.html "> http://developer.apple.com/technologies/xcode.html </a>) só seguir os passos ali do site que não tem erro.</p>
<p>Agora precisa baixar e instalar o PyObjC (<a href=" http://ioanna.me/2009/09/installing-pyobjc-xcode-templates-in-snow-leopard/"> http://ioanna.me/2009/09/installing-pyobjc-xcode-templates-in-snow-leopard/</a> )</p>
<p>Pronto agora é só desenvolver, seguem dois videos que encontrei neste blog ( <a href="http://fiorix.wordpress.com/2008/07/23/xcode-31-e-cocoa-python/">http://fiorix.wordpress.com/2008/07/23/xcode-31-e-cocoa-python/</a> ) , eles foram feitos no XCode 3.1 que é um pouco diferente do 3.2 (a versão que eu testei) mas muda pouca coisa, só ali na parte de atribuir as açoes aos componentes é em outra janela.</p>
<p>Parte 1:<br />
<object width="560" height="360"><param name="movie" value="http://www.youtube.com/v/60IulQIBGNA&#038;color1=0xb1b1b1&#038;color2=0xd0d0d0&#038;hl=en_US&#038;feature=player_embedded&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/60IulQIBGNA&#038;color1=0xb1b1b1&#038;color2=0xd0d0d0&#038;hl=en_US&#038;feature=player_embedded&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="560" height="360"></embed></object></p>
<p>Parte 2:<br />
<object width="560" height="360"><param name="movie" value="http://www.youtube.com/v/rrXF6Gn_KPM&#038;color1=0xb1b1b1&#038;color2=0xd0d0d0&#038;hl=en_US&#038;feature=player_embedded&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/rrXF6Gn_KPM&#038;color1=0xb1b1b1&#038;color2=0xd0d0d0&#038;hl=en_US&#038;feature=player_embedded&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="560" height="360"></embed></object></p>
<p>Agora passando as provas vou ter mais tempo de estudar ObjC, mas é bom saber que posso contar com python se necessario.<br />
Quanto ao meu projeto do sistema de controle com PIC e porta serial (rs232), foi apresentado ja a parte basica (comandos enviados via console, e apenas ligando ou desligando dispositivos). Agora vou desenvolvendo ele no meu tempo livre, quero mudar algumas coisas nele ainda:</p>
<p>- Utilizar mais python e menos C por questão de portabilidade (antes tinha que utilizar C pois era para a cadeira de programação C)<br />
- Desenvolver bibliotecas com funçoes basicas de controle para alguns modelos de PIC<br />
- Montar um destes kits de desenvolvimento, para que mais pessoas possam testar mesmo que não entendam muito de eletrônica</p>
]]></content:encoded>
			<wfw:commentRss>http://armandokeller.com/blog/2010/06/pyobjc-python-no-xcode/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Sistema de controle com PIC e porta Serial (rs232) parte 2</title>
		<link>http://armandokeller.com/blog/2010/05/sistema-de-controle-com-pic-e-porta-serial-rs232-parte-2/</link>
		<comments>http://armandokeller.com/blog/2010/05/sistema-de-controle-com-pic-e-porta-serial-rs232-parte-2/#comments</comments>
		<pubDate>Tue, 18 May 2010 02:45:34 +0000</pubDate>
		<dc:creator>Armando Leopoldo Keller</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[eletrônica]]></category>
		<category><![CDATA[geral]]></category>
		<category><![CDATA[Sem categoria]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[PIC]]></category>
		<category><![CDATA[rs232]]></category>
		<category><![CDATA[serial]]></category>

		<guid isPermaLink="false">http://armandokeller.com/blog/?p=96</guid>
		<description><![CDATA[Parte 2 sobre comunicação Serial PC<->PIC utilizando a linguagem de programação C]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript">
			<!-- 
				tweetmeme_url = "http://armandokeller.com/blog/2010/05/sistema-de-controle-com-pic-e-porta-serial-rs232-parte-2/";
				tweetmeme_source = "tweetmeme";
				tweetmeme_style = "";
				
			//-->
			</script>
                        <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script>
			<!-- 
			var fbShare = {
				url: "http://armandokeller.com/blog/2010/05/sistema-de-controle-com-pic-e-porta-serial-rs232-parte-2/",
				size: "large",
				google_analytics: "true"
			}
			//-->
			</script>
                        <script src="http://widgets.fbshare.me/files/fbshare.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript"><!-- 
		(function() {
		var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
		s.type = 'text/javascript';
		s.async = true;
		s.src = 'http://widgets.digg.com/buttons.js';
		s1.parentNode.insertBefore(s, s1);
		})();
		//-->
		</script><a class="DiggThisButton " href="http://digg.com/submit?url=http%3A%2F%2Farmandokeller.com%2Fblog%2F2010%2F05%2Fsistema-de-controle-com-pic-e-porta-serial-rs232-parte-2%2F"></a></div><div class="socialize-in-button socialize-in-button-vertical"><div class="delicious-button"><div class="del-top"><span id="96">0</span>saves</div><div class="del-bot"><a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;">Save</a></div></div>
		<script>
			<!-- 
			function displayURL(data) { var urlinfo = data[0]; if (!urlinfo.total_posts) return;document.getElementById('96').innerHTML = urlinfo.total_posts;}
			//-->
		</script>
		<script src = "http://badges.del.icio.us/feeds/json/url/data?url=http://armandokeller.com/blog/2010/05/sistema-de-controle-com-pic-e-porta-serial-rs232-parte-2/&amp;callback=displayURL"></script></div></div><p>Hoje vou mostrar como fazer a parte do PC para se conectar com o PIC , e tem algumas alteraçoes no codigo do pic tambem.<br />
Não vou entrar em muitos detalhes sobre o codigo do PIC pois este era o foco da parte 1<br />
Segue o codigo:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;16f628a.h&quot;                           // Inclui o cabeçalho especifico do pic a ser utilizado</span>
<span style="color: #339933;">#include &quot;stdio.h&quot;                              // Inclui as funçoes padroes de entrada e saida</span>
<span style="color: #339933;">#fuses HS,NOWDT,NOPROTECT                       // Configuração dos fuses (ver manual)</span>
<span style="color: #339933;">#use delay(clock=4000000)                       // Seta o clock interno para 4Mhz</span>
<span style="color: #339933;">#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1)  // Seta o baud rate para 9600, e define o pino B2 como TX e B1 como RX</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//Variavel do tipo char com 4 posiçoes (string de até 3 carateres) ou do tamanho do comando que desejarem utilizar</span>
<span style="color: #666666; font-style: italic;">// lembrando que sempre deve ter um caractere a mais pois tem o '\0' no final da string</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> pino<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Variavel que armazenara o pino que esta sendo utilizado</span>
&nbsp;
<span style="color: #993333;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// função principal</span>
<span style="color: #009900;">&#123;</span>
   delay_ms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//tempo para inicializar a conexão</span>
   <span style="color: #b1b100;">do</span> <span style="color: #009900;">&#123;</span>
      gets<span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// pega a string e coloca na variavel x</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'a'</span> <span style="color: #339933;">||</span> x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'A'</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Fazer isso para todas as portas desejadas, podendo ser A,B,C.. depende do pic</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Ve se qual pino da porta quer controlar</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'0'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_A0<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'1'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_A1<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'2'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_A2<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'3'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_A3<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// se não for nenhum, coloca como 0;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'b'</span> <span style="color: #339933;">||</span> x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'B'</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// mesma coisa que antes, porem agora para a porta B (e assim pode continuar)</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'0'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_B0<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'1'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// pino reservado para RS232</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'2'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// pino reservado para RS232</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'3'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_B3<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'4'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_B4<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'5'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_B5<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'6'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_B6<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'7'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_B7<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span>
      <span style="color: #009900;">&#123;</span>
       pino<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
       <span style="color: #666666; font-style: italic;">// Se não existir a porta que foi escolhida, seta o pino para 0 para que não mude o que foi escolhido anteriormente</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>pino <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Se o pino existir (não for 0)</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'l'</span> <span style="color: #339933;">||</span> x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'L'</span><span style="color: #009900;">&#41;</span><span style="color: #666666; font-style: italic;">// Se o comando for L ou l (de ligar) </span>
         <span style="color: #009900;">&#123;</span>
            output_high<span style="color: #009900;">&#40;</span>pino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Coloca o valor 1 logico no pino escolhido</span>
            <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;200<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'d'</span> <span style="color: #339933;">||</span> x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'D'</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Se o comando for D ou d(de desligar) </span>
         <span style="color: #009900;">&#123;</span>
            output_low<span style="color: #009900;">&#40;</span>pino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Coloca o valor 0 logico no pino escolhido </span>
            <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;200<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #b1b100;">else</span> <span style="color: #666666; font-style: italic;">// Se o comando não for de ligar ou desligar</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;505<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Avisa que o comando é invalido</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span> <span style="color: #666666; font-style: italic;">// Se o pino não existir (variavel pino igual a 0)</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;505<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>TRUE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// mantem o laço de repetição rodando em loop infinito</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Bom, agora vamos ao que interessa, o software que controla o PIC pela porta serial de um PC.<br />
Normalmente a conexão serial é meio chatinha de fazer (seja em linux, windows, mac..) então recomendo que usem a biblioteca que se encontra neste site ( http://www.teuniz.net/RS-232/ ) que facilita bastante o nosso trabalho, e ja deixa portavel para outros OS tambem. Essa biblioteca é extremamente simples de ser utilizada, não vejo sentido em reescrever todo o codigo para a comunicação serial se ja tem uma biblioteca boa que faz isso, a não ser para aprender como funciona (recomendo que leiam o codigo da biblioteca)</p>
<p>Segue o codigo:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;stdio.h&quot;</span>
<span style="color: #339933;">#include &quot;stdlib.h&quot;</span>
<span style="color: #339933;">#include &quot;conio.h&quot;</span>
<span style="color: #339933;">#include &quot;windows.h&quot;</span>
<span style="color: #339933;">#include &quot;string.h&quot;</span>
<span style="color: #339933;">#include &quot;rs232.h&quot;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Declarando a função loop que está la em baixo</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> comando<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// comando a ser enviado</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> buff<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1024</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// comando recebido</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Função principal</span>
<span style="color: #009900;">&#123;</span>
    OpenComport<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// abre a porta desejada (ver documentação)</span>
    loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Chama a função loop</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Função loop</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> n<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// variavel temporaria</span>
    n <span style="color: #339933;">=</span> PollComport<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>buff<span style="color: #339933;">,</span><span style="color: #0000dd;">1024</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// n != 0  se tiver algo pra ser recebido</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>n <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// se não tiver recebendo nada</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Digite o seu comando: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//pergunta qual comando quer executar</span>
        gets<span style="color: #009900;">&#40;</span>comando<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Pega o comando e coloca na variavel comando</span>
        strcat<span style="color: #009900;">&#40;</span>comando<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">// adiciona uma quebra de linha (mais por motivos esteticos se for testar em terminal ou quardar log)</span>
        cprintf<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>comando<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// manda o comando para a porta serial (ou USB com FTDI)</span>
        _sleep<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// delay de 200 milisegundos necessario para a sincronização (pode ser de 100)</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #666666; font-style: italic;">// Se tiver recebido algo</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Switch para ver o que cada codigo representa, e exibe para o usuario.</span>
        <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span>atoi<span style="color: #009900;">&#40;</span>buff<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">200</span><span style="color: #339933;">:</span>
                <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;OK!<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">505</span><span style="color: #339933;">:</span>
                <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Erro!<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Chama a função novamente, assim mantendo um loop infinito</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Acho que da pra entender como funciona só pelos comentarios.<br />
Esse codigo foi testado no windows 7 ultimate 64bit, utilizando o code::blocks para programar, e o GNU GCC para compilar. Para funcionar para linux tambem é necessario alterar algumas coisas, mas a logica é a mesma.</p>
<p>Ah, não saiam ligando os fios da serial direto no pic é preciso utilizar um MAX232 para isso, pois o sinal da serial é diferente do TTL utilizado pelo pic. Para saber como ligar o MAX232 é só olhar no datasheet.</p>
<p>Se quiserem testar só a comunicação serial virtualmente, recomendo o uso do virtual serial port driver da eltima, e hyper terminal. </p>
<p>Ainda falta eu colocar aqui a parte dos sockets (para o controle remoto), que ja está pronta só tenho que juntar tudo,  e a parte eletro-eletronica tambem, por exemplo um dimmer para uma lampada, como controlar interruptores&#8230; e alguns outros exemplos do que fazer.  A principio quero montar uma placa que controle varios interruptores.</p>
<p>Qualquer duvida, sugestão ou critica, favor deixar nos comentarios</p>
]]></content:encoded>
			<wfw:commentRss>http://armandokeller.com/blog/2010/05/sistema-de-controle-com-pic-e-porta-serial-rs232-parte-2/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Sistema de controle com PIC e porta Serial (rs232)</title>
		<link>http://armandokeller.com/blog/2010/05/sistema-de-controle-com-pic-e-porta-serial-rs232/</link>
		<comments>http://armandokeller.com/blog/2010/05/sistema-de-controle-com-pic-e-porta-serial-rs232/#comments</comments>
		<pubDate>Mon, 10 May 2010 00:06:49 +0000</pubDate>
		<dc:creator>Armando Leopoldo Keller</dc:creator>
				<category><![CDATA[geral]]></category>
		<category><![CDATA[Sem categoria]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[controle]]></category>
		<category><![CDATA[IC]]></category>
		<category><![CDATA[PIC]]></category>
		<category><![CDATA[rs232]]></category>
		<category><![CDATA[serial]]></category>
		<category><![CDATA[uC]]></category>

		<guid isPermaLink="false">http://armandokeller.com/blog/?p=76</guid>
		<description><![CDATA[Exemplo pratico de controle utilizando microcontroladores PIC. Coisas que normalmente seriam feitas com uma arduino podem ser feitas com um microcontrolador, gastando muito menos.]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript">
			<!-- 
				tweetmeme_url = "http://armandokeller.com/blog/2010/05/sistema-de-controle-com-pic-e-porta-serial-rs232/";
				tweetmeme_source = "tweetmeme";
				tweetmeme_style = "";
				
			//-->
			</script>
                        <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script>
			<!-- 
			var fbShare = {
				url: "http://armandokeller.com/blog/2010/05/sistema-de-controle-com-pic-e-porta-serial-rs232/",
				size: "large",
				google_analytics: "true"
			}
			//-->
			</script>
                        <script src="http://widgets.fbshare.me/files/fbshare.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript"><!-- 
		(function() {
		var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
		s.type = 'text/javascript';
		s.async = true;
		s.src = 'http://widgets.digg.com/buttons.js';
		s1.parentNode.insertBefore(s, s1);
		})();
		//-->
		</script><a class="DiggThisButton " href="http://digg.com/submit?url=http%3A%2F%2Farmandokeller.com%2Fblog%2F2010%2F05%2Fsistema-de-controle-com-pic-e-porta-serial-rs232%2F"></a></div><div class="socialize-in-button socialize-in-button-vertical"><div class="delicious-button"><div class="del-top"><span id="76">0</span>saves</div><div class="del-bot"><a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;">Save</a></div></div>
		<script>
			<!-- 
			function displayURL(data) { var urlinfo = data[0]; if (!urlinfo.total_posts) return;document.getElementById('76').innerHTML = urlinfo.total_posts;}
			//-->
		</script>
		<script src = "http://badges.del.icio.us/feeds/json/url/data?url=http://armandokeller.com/blog/2010/05/sistema-de-controle-com-pic-e-porta-serial-rs232/&amp;callback=displayURL"></script></div></div><p>Estou fazendo um projeto para a cadeira de programação C que tem o objetivo de controlar eletronicos (sejam interruptores, motores, ou até coisas mais completas como temperatura de um ar-condicionado) remotamente, e achei interessante postar aqui o projeto para que mais gente possa ver como isso é feito (e como é mais simples do que se imagina).<br />
Por enquanto estou desenvolvendo o projeto em partes, para juntar tudo depois.<br />
Hoje vou falar sobre a parte do PIC enviar e receber dados pela porta serial.</p>
<p>Material utilizado (para testar virtualmente):</p>
<p>- Proteus 7.1 (para a simulação)<br />
- PCWH Compiler IDE (CCS) 4.038 (para programar e compilar o programa em C)</p>
<p>Passos da montagem no proteus:<br />
Passo 1: Criar um novo arquivo no Proteus.<br />
Passo 2: Adicionar o PIC de sua preferencia que tenha suporte a RS232, no caso do exemplo é o PIC16F628A.<br />
Passo 3: Adicionar os leds que quiser (de acordo com o numero de pinos que deseja controlar).<br />
Passo 4: Colocar um resistor de 470 Ohms em cada led.<br />
Passo 5: Ligar o LED-Resistor ou Resistor-LED (tanto faz a ordem) ao terra.<br />
Passo 6: Adicionar um terminal virtual ao projeto<br />
Passo 7: Ligar o pino RX do pic no TX do terminal<br />
Passo 8: Ligar o pino TX do pic no RX do terminal<br />
Passo 9: Salve o projeto onde preferir<br />
por enquanto é  isso no proteus, agora precisamos do programa a ser inserido no pic.</p>
<p>Para o programa do PIC, cada um programa no editor que preferir, e usa o compilador que quiser(Lembrando que mudando de compilador o codigo sera diferente). No exemplo eu estou usando o compilador CCS.<br />
O programa é o seguinte:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &amp;lt;16f628a.h&amp;gt;                            // Inclui o cabeçalho especifico do pic a ser utilizado</span>
<span style="color: #339933;">#include                               // Inclui as funçoes padroes de entrada e saida</span>
<span style="color: #339933;">#fuses HS,NOWDT,NOPROTECT                       // Configuração dos fuses (ver manual)</span>
<span style="color: #339933;">#use delay(clock=4000000)                       // Seta o clock interno para 4Mhz</span>
<span style="color: #339933;">#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1)  // Seta o baud rate para 9600, e define o pino B2 como TX e B1 como RX</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//Variavel do tipo char com 4 posiçoes (string de até 3 carateres) ou do tamanho do comando que desejarem utilizar</span>
<span style="color: #666666; font-style: italic;">// lembrando que sempre deve ter um caractere a mais pois tem o '\0' no final da string</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> pino<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Variavel que armazenara o pino que esta sendo utilizado</span>
&nbsp;
<span style="color: #993333;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// função principal</span>
<span style="color: #009900;">&#123;</span>
   delay_ms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//tempo para inicializar a conexão</span>
&nbsp;
   <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;TESTE DE CONTROLE COM PIC<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Manda esta mesagem para o terminal</span>
   <span style="color: #666666; font-style: italic;">//Para testar se foi tudo ligado corretamente, feche a função aqui, compile e teste</span>
   <span style="color: #b1b100;">do</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Envie um comando de 3 caracteres&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;sendo abc a=porta b=pino c=estado(l ou d) <span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      gets<span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// pega a string e coloca na variavel x</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'a'</span> <span style="color: #339933;">||</span> x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'A'</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Fazer isso para todas as portas desejadas, podendo ser A,B,C.. depende do pic</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Ve se qual pino da porta quer controlar</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'0'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_A0<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'1'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_A1<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'2'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_A2<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'3'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_A3<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// se não for nenhum, coloca como 0;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'b'</span> <span style="color: #339933;">||</span> x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'B'</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// mesma coisa que antes, porem agora para a porta B (e assim pode continuar)</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'0'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_B0<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'1'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// pino reservado para RS232</span>
               <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Pino reservado!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'2'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// pino reservado para RS232</span>
               <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Pino reservado!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'3'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_B3<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'4'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_B4<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'5'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_B5<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'6'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_B6<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'7'</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> PIN_B7<span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
               pino <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span>
      <span style="color: #009900;">&#123;</span>
       pino<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
       <span style="color: #666666; font-style: italic;">// Se não existir a porta que foi escolhida, seta o pino para 0 para que não mude o que foi escolhido anteriormente</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>pino <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Se o pino existir (não for 0)</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'l'</span> <span style="color: #339933;">||</span> x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'L'</span><span style="color: #009900;">&#41;</span><span style="color: #666666; font-style: italic;">// Se o comando for L ou l (de ligar)</span>
         <span style="color: #009900;">&#123;</span>
            output_high<span style="color: #009900;">&#40;</span>pino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Coloca o valor 1 logico no pino escolhido</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'d'</span> <span style="color: #339933;">||</span> x<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'D'</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Se o comando for D ou d(de desligar)</span>
         <span style="color: #009900;">&#123;</span>
            output_low<span style="color: #009900;">&#40;</span>pino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Coloca o valor 0 logico no pino escolhido</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #b1b100;">else</span> <span style="color: #666666; font-style: italic;">// Se o comando não for de ligar ou desligar</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Comando invalido. Tente novamente <span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Avisa que o comando é invalido</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span> <span style="color: #666666; font-style: italic;">// Se o pino não existir (variavel pino igual a 0)</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Comando invalido. Tente novamente <span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>TRUE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// mantem o laço de repetição rodando em loop infinito</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Os dois promeiros includes não aparecem bem com esse plugin, mas são:<br />
#include &lt;16f628a.h&gt;<br />
#include<br />
Acho que não tem nada de muito complicado neste codigo, no máximo a parte de configuração dos fuses, o que pode ser visto no manual do compilador, ou em qualquer tutorial basico sobre o CCS. e o resto dos comandos são basicos da linguagem C (aprenda o basico de C antes de tentar fazer isso, aqueles programinhas em terminal). Qualquer outra coisa é só postar a duvida que eu respondo.</p>
<p>Agora precisa compilar o programa (sugiro copiar o .hex gerado para a pasta do projeto do proteus).</p>
<p>Voltando ao proteus agora,</p>
<p>Passo 10: Clique duas vezes sobre o PIC, sete o clock para 4Mhz (em Processor Clock Frequency) e em Program File coloque o caminho para o arquivo .hex gerado pelo compilador.</p>
<p>Pronto, agora depois de tudo configurado é só rodar a simulação que funcionara, a menos que tenha feito algo errado (antes de perguntar, favor ler novamente e ver se esta tudo igual). Lembrando que ao copiar e colar o codigo para o seu editor de textos normalmente tem que trocar as aspas pois vai como acento.</p>
<p>Esta é somente a base para algo mais complexo, se quiser controlar um motor, ler um valor analogico (potenciometro, ldr, temperatura&#8230;) ou qualquer outra coisa mais complexa, tera que implementar as suas funçoes e comandos para isso.</p>
<p>Conforme eu for fazendo o projeto, e tiver tempo, vou postando aqui.</p>
<p>Uma coisa que acho importante ao compartilhar este projeto, é mostrar para as pessoas que usam arduino, que não é preciso gastar muito com uma arduino para fazer projetos simples, os microcontroladores são baratos (em torno de uns 10 reais) e são super simples de programar.</p>
<p>Seguem algumas imagens de como fica o projeto:</p>
<div id="attachment_88" class="wp-caption alignnone" style="width: 778px"></p>
<div class="mceTemp mceIEcenter">
<dl id="attachment_87" class="wp-caption aligncenter" style="width: 778px;">
<dt class="wp-caption-dt"><img class="size-full wp-image-87 " title="Como fica no proteus" src="http://armandokeller.com/blog/wp-content/uploads/2010/05/proteus1.jpg" alt="Como fica no proteus" width="768" height="463" /><p class="wp-caption-text">Como fica no proteus</p></div>
<p><img class="size-full wp-image-88 " title="Funcionando no proteus com o terminal" src="http://armandokeller.com/blog/wp-content/uploads/2010/05/proteus11.jpg" alt="Funcionando no proteus com o terminal" width="768" height="460" /></p>
</dt>
<dd class="wp-caption-dd">Funcionando no proteus com o terminal</dd>
</dl>
</div>
<p>EDITANDO:  Como foi pedido nos comentarios, seguem os arquivos utilizados no exemplo: <a href="http://armandokeller.com/blog/wp-content/uploads/2010/05/RS232.zip">Arquivos do projeto</a></p>
]]></content:encoded>
			<wfw:commentRss>http://armandokeller.com/blog/2010/05/sistema-de-controle-com-pic-e-porta-serial-rs232/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>De Monster Debugger &#8211; como utilizar</title>
		<link>http://armandokeller.com/blog/2009/05/de-monster-debugger-como-utilizar/</link>
		<comments>http://armandokeller.com/blog/2009/05/de-monster-debugger-como-utilizar/#comments</comments>
		<pubDate>Sat, 02 May 2009 21:11:48 +0000</pubDate>
		<dc:creator>Armando Leopoldo Keller</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[debugger]]></category>
		<category><![CDATA[flash player]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Monster Debugger]]></category>
		<category><![CDATA[Trace]]></category>

		<guid isPermaLink="false">http://armandokeller.com/blog/?p=59</guid>
		<description><![CDATA[Exemplo rapido de como utilizar o MonsterDebugger.]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript">
			<!-- 
				tweetmeme_url = "http://armandokeller.com/blog/2009/05/de-monster-debugger-como-utilizar/";
				tweetmeme_source = "tweetmeme";
				tweetmeme_style = "";
				
			//-->
			</script>
                        <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script>
			<!-- 
			var fbShare = {
				url: "http://armandokeller.com/blog/2009/05/de-monster-debugger-como-utilizar/",
				size: "large",
				google_analytics: "true"
			}
			//-->
			</script>
                        <script src="http://widgets.fbshare.me/files/fbshare.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript"><!-- 
		(function() {
		var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
		s.type = 'text/javascript';
		s.async = true;
		s.src = 'http://widgets.digg.com/buttons.js';
		s1.parentNode.insertBefore(s, s1);
		})();
		//-->
		</script><a class="DiggThisButton " href="http://digg.com/submit?url=http%3A%2F%2Farmandokeller.com%2Fblog%2F2009%2F05%2Fde-monster-debugger-como-utilizar%2F"></a></div><div class="socialize-in-button socialize-in-button-vertical"><div class="delicious-button"><div class="del-top"><span id="59">0</span>saves</div><div class="del-bot"><a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;">Save</a></div></div>
		<script>
			<!-- 
			function displayURL(data) { var urlinfo = data[0]; if (!urlinfo.total_posts) return;document.getElementById('59').innerHTML = urlinfo.total_posts;}
			//-->
		</script>
		<script src = "http://badges.del.icio.us/feeds/json/url/data?url=http://armandokeller.com/blog/2009/05/de-monster-debugger-como-utilizar/&amp;callback=displayURL"></script></div></div><p>Faz tempo que eu não posto nada, devido a falta de tempo , e de ideias sobre o que postar.<br />
Hoje, resolvi postar sobre como utilizar o MonsterDebugger, o melhor debugger que eu ja vi para actionscript.</p>
<p>Primeiro, o que é esse MonsterDebugger ?<br />
O <a href="http://demonsterdebugger.com/">MonsterDebugger ( http://demonsterdebugger.com/ )</a>  é um debugger Open Source feito em AIR, que permite debugar aplicaçoes Actionscript (flash, flex, air &#8230;), não só dando trace, mas podendo editar as propriedades dos objetos em tempo real, e podendo executar os metodos dos objetos quando quiser. Alem de claro, dar trace nas coisas (se for algum array, xml, objeto &#8230;  ele apresenta o conteudo em arvore, assim fica mais facil de debuggar).</p>
<p>Agora sim, vou mostrar como se usa ele.</p>
<p>1 &#8211; Instale o client:<br />
Va em <a href="http://demonsterdebugger.com/">http://demonsterdebugger.com/</a> , pegue a versão mais recente do MonsterDebugger e instale ele no seu computador. </p>
<p>2 &#8211; Gere as classes necessarias:<br />
Abra o client (instalado anteriormente) e va em File -> Export Client Class<br />
<img src="http://armandokeller.com/blog/imagens/exportar-classe-cliente.jpg" alt="Exportar Classe Cliente - MonsterDebugger" /></p>
<p>3 &#8211; Se quiser pode gerar um exemplo (File -> Export example), ou pode tentar usar direto sem o exemplo.</p>
<p>Como dar um simples Trace:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">MonsterDebugger<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> o_que_é_para_ir_no_trace<span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>Como ativar o live application:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> _debugger<span style="color: #000066; font-weight: bold;">:</span>MonsterDebugger<span style="color: #000066; font-weight: bold;">;</span>
_debugger = <span style="color: #0033ff; font-weight: bold;">new</span> MonsterDebugger<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>A parte de utilizar o Client é bem intuitiva, caso alguem tenha duvidas de como utilizar, favor me avisar que eu coloco aqui detalhadamente como utilizar.</p>
<p>Lembrando que aceito sugestoes de posts, é só entrar em contato.</p>
]]></content:encoded>
			<wfw:commentRss>http://armandokeller.com/blog/2009/05/de-monster-debugger-como-utilizar/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Conexão AS3 com python via socket (simplificado)</title>
		<link>http://armandokeller.com/blog/2009/01/conexo-as3-com-python-via-socket-simplificado/</link>
		<comments>http://armandokeller.com/blog/2009/01/conexo-as3-com-python-via-socket-simplificado/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 17:30:41 +0000</pubDate>
		<dc:creator>Armando Leopoldo Keller</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[conexao]]></category>
		<category><![CDATA[Flash geral]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Socket]]></category>
		<category><![CDATA[Actionscript 3]]></category>

		<guid isPermaLink="false">http://alkeller.wordpress.com/2009/01/17/conexo-as3-com-python-via-socket-simplificado/</guid>
		<description><![CDATA[Algumas vezes me perguntei como fazer algumas coisas mais complexas em AIR de uma maneira rapida e segura, como por exemplo pegar informaçoes do usuario, conectar com um banco de dados (sem ser o nativo do AIR) como oracle,mssql… executar linha de comando, e outras coisas que só seriam possiveis utilizando alguma outra linguagem mais poderosa. Levando em conta que isto realmente era necessario para aumentar o “poder” do AIR e que o AMF fazia algo parecido, só que para a internet, resolvi criar uma classe em AS e uma função em Python que facilita a comunicação entre os dois (deixe o servidor python rodando de fundo e chame as funçoes dele :D )]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript">
			<!-- 
				tweetmeme_url = "http://armandokeller.com/blog/2009/01/conexo-as3-com-python-via-socket-simplificado/";
				tweetmeme_source = "tweetmeme";
				tweetmeme_style = "";
				
			//-->
			</script>
                        <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script>
			<!-- 
			var fbShare = {
				url: "http://armandokeller.com/blog/2009/01/conexo-as3-com-python-via-socket-simplificado/",
				size: "large",
				google_analytics: "true"
			}
			//-->
			</script>
                        <script src="http://widgets.fbshare.me/files/fbshare.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript"><!-- 
		(function() {
		var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
		s.type = 'text/javascript';
		s.async = true;
		s.src = 'http://widgets.digg.com/buttons.js';
		s1.parentNode.insertBefore(s, s1);
		})();
		//-->
		</script><a class="DiggThisButton " href="http://digg.com/submit?url=http%3A%2F%2Farmandokeller.com%2Fblog%2F2009%2F01%2Fconexo-as3-com-python-via-socket-simplificado%2F"></a></div><div class="socialize-in-button socialize-in-button-vertical"><div class="delicious-button"><div class="del-top"><span id="41">0</span>saves</div><div class="del-bot"><a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;">Save</a></div></div>
		<script>
			<!-- 
			function displayURL(data) { var urlinfo = data[0]; if (!urlinfo.total_posts) return;document.getElementById('41').innerHTML = urlinfo.total_posts;}
			//-->
		</script>
		<script src = "http://badges.del.icio.us/feeds/json/url/data?url=http://armandokeller.com/blog/2009/01/conexo-as3-com-python-via-socket-simplificado/&amp;callback=displayURL"></script></div></div><p>Algumas vezes me perguntei como fazer algumas coisas mais complexas em AIR de uma maneira rapida e segura, como por exemplo pegar informaçoes do usuario, conectar com um banco de dados (sem ser o nativo do AIR) como oracle,mssql… executar linha de comando, e outras coisas que só seriam possiveis utilizando alguma outra linguagem mais poderosa. Levando em conta que isto realmente era necessario para aumentar o “poder” do AIR e que o AMF fazia algo parecido, só que para a internet, resolvi criar uma classe em AS e uma função em Python que facilita a comunicação entre os dois (deixe o servidor python rodando de fundo e chame as funçoes dele <img src='http://armandokeller.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  )</p>
<p>Primeiro a classe Python.as que pode ser baixada <a href="http://cid-cd79b3b43841b5ae.skydrive.live.com/self.aspx/.Public/Python.as">aqui</a> :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>adobe<span style="color: #000066; font-weight: bold;">.</span>serialization<span style="color: #000066; font-weight: bold;">.</span>json<span style="color: #000066; font-weight: bold;">.</span>JSON<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Socket</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #3f5fbf;">/**
     * Classe para conexao com python utilizando socket
     * @author    Armando Leopoldo Keller - (http://alkeller.wordpress.com) - alkeller@live.de
     */</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Python <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Socket</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #009900; font-style: italic;">// TODO: Implementar um metodo de retorno, verificando o tipo do retorno, e passando como parametro na funcao associada</span>
        <span style="color: #3f5fbf;">/**
         * Cria um novo Socket
         * @param host    Host onde esta o socket
         * @param port    Porta que esta o socket
         * @see flash.net.Socket
         * @usage    var p:Python = new Python(&quot;10.1.1.23&quot;,2727);
         */</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Python<span style="color: #000000;">&#40;</span>host<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> port<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>        <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span>host<span style="color: #000066; font-weight: bold;">,</span> port<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            host = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
            port = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #3f5fbf;">/**
         * Chama uma funcao do python se o socket estiver conectado 
         * @param func    Nome da funcao a ser chamada no python
         * @param args    Argumentos a serem chamados no python
         * @usage p.call(&quot;teste&quot;,{um:1,dois:2,tres:3});
         * @usage p.call(&quot;teste&quot;);
         */</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span>func<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span>args<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">connected</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> obj<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Object</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                obj<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;funcao&quot;</span><span style="color: #000000;">&#93;</span> = func<span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:*</span> <span style="color: #0033ff; font-weight: bold;">in</span> args<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>args<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> args<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;'&quot;</span><span style="color: #000066; font-weight: bold;">+</span>args<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;'&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
                    obj<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>=args<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeUTFBytes</span><span style="color: #000000;">&#40;</span>JSON<span style="color: #000066; font-weight: bold;">.</span>encode<span style="color: #000000;">&#40;</span>obj<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                obj = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0033ff; font-weight: bold;">else</span>
                <span style="color: #0033ff; font-weight: bold;">throw</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Error</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Voce deve estar conectado ao socket.&quot;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Depois é necessario a função em python que vai reconhecer o que está sendo chamado pelo flash, o arquivo pode ser baixado <a href="http://cid-cd79b3b43841b5ae.skydrive.live.com/self.aspx/.Public/JMF.py">aqui</a> :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> json<span style="color: #66cc66;">;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> executar<span style="color: black;">&#40;</span>objeto<span style="color: black;">&#41;</span>:
    __arr__ = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">;</span>
    <span style="color: #0000cd;">__str__</span> = <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #66cc66;">;</span>
    obj = json.<span style="color: black;">loads</span><span style="color: black;">&#40;</span>objeto<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #0000cd;">__str__</span> = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>obj<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;funcao&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #483d8b;">&quot;(&quot;</span><span style="color: #66cc66;">;</span>
    obj.<span style="color: black;">pop</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;funcao&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>obj.<span style="color: black;">keys</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;;</span>= <span style="color: #ff4500;">1</span>:
        <span style="color: #ff7700;font-weight:bold;">for</span> k <span style="color: #ff7700;font-weight:bold;">in</span> obj:
            __arr__.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>k<span style="color: black;">&#41;</span>+<span style="color: #483d8b;">&quot;=&quot;</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>obj<span style="color: black;">&#91;</span>k<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>__arr__<span style="color: black;">&#41;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
            <span style="color: #0000cd;">__str__</span> = <span style="color: #0000cd;">__str__</span>+__arr__<span style="color: black;">&#91;</span>x<span style="color: black;">&#93;</span>+<span style="color: #483d8b;">&quot;,&quot;</span><span style="color: #66cc66;">;</span>
        <span style="color: #0000cd;">__str__</span> = <span style="color: #0000cd;">__str__</span> +__arr__<span style="color: black;">&#91;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>__arr__<span style="color: black;">&#41;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>+<span style="color: #483d8b;">&quot;)&quot;</span><span style="color: #66cc66;">;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #0000cd;">__str__</span> = <span style="color: #0000cd;">__str__</span>+<span style="color: #483d8b;">&quot;)&quot;</span><span style="color: #66cc66;">;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #0000cd;">__str__</span><span style="color: #66cc66;">;</span></pre></td></tr></table></div>

<p>Agora precisamos de um “servidor socket” rodando de fundo com as funçoes a serem chamadas, que pode ser baixado <a href="http://cid-cd79b3b43841b5ae.skydrive.live.com/self.aspx/.Public/ServidorPython.py">aqui</a> :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">socket</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">threading</span>
<span style="color: #ff7700;font-weight:bold;">import</span> json
<span style="color: #ff7700;font-weight:bold;">from</span> JMF <span style="color: #ff7700;font-weight:bold;">import</span> executar
<span style="color: #ff7700;font-weight:bold;">class</span> ClientThread <span style="color: black;">&#40;</span> <span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span> <span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span> <span style="color: black;">&#40;</span> <span style="color: #008000;">self</span>, channel, details <span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">channel</span> = channel
        <span style="color: #008000;">self</span>.<span style="color: black;">details</span> = details
        <span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span>.<span style="color: #0000cd;">__init__</span> <span style="color: black;">&#40;</span> <span style="color: #008000;">self</span> <span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> run <span style="color: black;">&#40;</span> <span style="color: #008000;">self</span> <span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Conexao recebida: '</span>, <span style="color: #008000;">self</span>.<span style="color: black;">details</span> <span style="color: black;">&#91;</span> <span style="color: #ff4500;">0</span> <span style="color: black;">&#93;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">channel</span>.<span style="color: black;">send</span> <span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;resposta vinda do python&quot;</span> <span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span> <span style="color: black;">&#40;</span> <span style="color: #ff4500;">10</span> <span style="color: black;">&#41;</span>:
            <span style="color: #dc143c;">string</span> = <span style="color: #008000;">self</span>.<span style="color: black;">channel</span>.<span style="color: black;">recv</span> <span style="color: black;">&#40;</span> <span style="color: #ff4500;">1024</span> <span style="color: black;">&#41;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">interpretaComando</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">string</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">channel</span>.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Conexao fechada: '</span>, <span style="color: #008000;">self</span>.<span style="color: black;">details</span> <span style="color: black;">&#91;</span> <span style="color: #ff4500;">0</span> <span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> interpretaComando<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,<span style="color: #dc143c;">string</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">eval</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;self.&quot;</span>+executar<span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">string</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> testar<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,arg1,arg2<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Chamou testar: &quot;</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>arg1<span style="color: black;">&#41;</span>+<span style="color: #483d8b;">&quot;,&quot;</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>arg2<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">channel</span>.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Chamou testar: &quot;</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>arg1<span style="color: black;">&#41;</span>+<span style="color: #483d8b;">&quot;,&quot;</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>arg2<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> pegaVariaveis<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;chamou pegaVariaveis&quot;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">channel</span>.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;chamou pegaVariaveis&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> pegarArray<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Chamou pegar Array&quot;</span><span style="color: #66cc66;">;</span>
        arr = <span style="color: black;">&#91;</span><span style="color: #483d8b;">'a'</span>,<span style="color: #483d8b;">'b'</span>,<span style="color: #483d8b;">'c'</span>,<span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">;</span>
        txt = json.<span style="color: black;">dumps</span><span style="color: black;">&#40;</span>arr<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">channel</span>.<span style="color: black;">send</span><span style="color: black;">&#40;</span>txt<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> pegarObj<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Chamou pegar Objeto&quot;</span><span style="color: #66cc66;">;</span>
        teste = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
        teste<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;item1&quot;</span><span style="color: black;">&#93;</span>   =   <span style="color: #483d8b;">&quot;Primeiro item&quot;</span><span style="color: #66cc66;">;</span>
        teste<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;item2&quot;</span><span style="color: black;">&#93;</span>   =   <span style="color: #483d8b;">&quot;Segundo item&quot;</span><span style="color: #66cc66;">;</span>
        teste<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;numero&quot;</span><span style="color: black;">&#93;</span>  =   <span style="color: #ff4500;">2</span><span style="color: #66cc66;">;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">channel</span>.<span style="color: black;">send</span><span style="color: black;">&#40;</span>json.<span style="color: black;">dumps</span><span style="color: black;">&#40;</span>teste<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #808080; font-style: italic;"># Inicia o servidor</span>
server = <span style="color: #dc143c;">socket</span>.<span style="color: #dc143c;">socket</span> <span style="color: black;">&#40;</span> <span style="color: #dc143c;">socket</span>.<span style="color: black;">AF_INET</span>, <span style="color: #dc143c;">socket</span>.<span style="color: black;">SOCK_STREAM</span> <span style="color: black;">&#41;</span>
server.<span style="color: black;">bind</span> <span style="color: black;">&#40;</span> <span style="color: black;">&#40;</span> <span style="color: #dc143c;">socket</span>.<span style="color: black;">gethostbyname</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">socket</span>.<span style="color: black;">gethostname</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>, <span style="color: #ff4500;">2727</span> <span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
server.<span style="color: black;">listen</span> <span style="color: black;">&#40;</span> <span style="color: #ff4500;">5</span> <span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Iniciando servidor...&quot;</span>
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
    channel, details = server.<span style="color: black;">accept</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    ClientThread <span style="color: black;">&#40;</span> channel, details<span style="color: black;">&#41;</span>.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Pronto, agora só falta uma aplicação de exemplo chamando estas funçoes, que pode ser baixada <a href="http://cid-cd79b3b43841b5ae.skydrive.live.com/self.aspx/.Public/PyFlex.mxml">aqui</a> :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;;</span>
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>WindowedApplication applicationComplete=<span style="color: #990000;">&quot;iniciar()&quot;</span> xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #990000;">&quot;absolute&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
    <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
        <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>
            <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>adobe<span style="color: #000066; font-weight: bold;">.</span>serialization<span style="color: #000066; font-weight: bold;">.</span>json<span style="color: #000066; font-weight: bold;">.</span>JSON<span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> py<span style="color: #000066; font-weight: bold;">:</span>Python
            <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> texto<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;&quot;</span>
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> iniciar<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                py = <span style="color: #0033ff; font-weight: bold;">new</span> Python<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">ProgressEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SOCKET_DATA</span><span style="color: #000066; font-weight: bold;">,</span>onRecebe<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CONNECT</span><span style="color: #000066; font-weight: bold;">,</span>onConecta<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IO_ERROR</span><span style="color: #000066; font-weight: bold;">,</span>onErroIO<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">connect</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;10.1.1.3&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">2727</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> onRecebe<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ProgressEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> str<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readUTFBytes</span><span style="color: #000000;">&#40;</span>py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesAvailable</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                texto = str<span style="color: #000066; font-weight: bold;">;</span>
                py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> onConecta<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Conectou&quot;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> chamarTeste<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">connected</span><span style="color: #000000;">&#41;</span>
                    py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;testar&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#123;</span>arg1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">&quot;Argumento 1&quot;</span><span style="color: #000066; font-weight: bold;">,</span>arg2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #990000;">&quot;Argumento 2&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0033ff; font-weight: bold;">else</span>
                    texto = <span style="color: #990000;">&quot;O socket esta desconectado&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> chamarPegaVariaveis<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">connected</span><span style="color: #000000;">&#41;</span>
                    py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;pegaVariaveis&quot;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0033ff; font-weight: bold;">else</span>
                    texto = <span style="color: #990000;">&quot;O socket esta desconectado&quot;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> pegarArray<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">connected</span><span style="color: #000000;">&#41;</span>
                    py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;pegarArray&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #0033ff; font-weight: bold;">else</span>
                    texto = <span style="color: #990000;">&quot;O socket esta desconectado&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> pegarObj<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">connected</span><span style="color: #000000;">&#41;</span>
                    py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;pegarObj&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #0033ff; font-weight: bold;">else</span>
                    texto = <span style="color: #990000;">&quot;O socket esta desconectado&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> matarServer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                py<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                texto = <span style="color: #990000;">&quot;Desconectado&quot;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> onErroIO<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Erro ao conectar com o socket&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
    <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
    <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>VBox<span style="color: #000066; font-weight: bold;">&gt;</span>
        <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>HBox<span style="color: #000066; font-weight: bold;">&gt;</span>
            <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button label = <span style="color: #990000;">&quot;Testar&quot;</span>         <span style="color: #004993;">click</span> = <span style="color: #990000;">&quot;chamarTeste()&quot;</span>         <span style="color: #000066; font-weight: bold;">/&gt;</span>
            <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button label = <span style="color: #990000;">&quot;PegaVar&quot;</span>        <span style="color: #004993;">click</span> = <span style="color: #990000;">&quot;chamarPegaVariaveis()&quot;</span> <span style="color: #000066; font-weight: bold;">/&gt;</span>
            <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button label = <span style="color: #990000;">&quot;pegarArray&quot;</span>     <span style="color: #004993;">click</span> = <span style="color: #990000;">&quot;pegarArray()&quot;</span>          <span style="color: #000066; font-weight: bold;">/&gt;</span>
            <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button label = <span style="color: #990000;">&quot;pegarObj&quot;</span>       <span style="color: #004993;">click</span> = <span style="color: #990000;">&quot;pegarObj()&quot;</span>            <span style="color: #000066; font-weight: bold;">/&gt;</span>
            <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button label = <span style="color: #990000;">&quot;Kill Server&quot;</span>    <span style="color: #004993;">click</span> = <span style="color: #990000;">&quot;matarServer()&quot;</span>         <span style="color: #000066; font-weight: bold;">/&gt;</span>
        <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>HBox<span style="color: #000066; font-weight: bold;">&gt;</span>
        <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Text <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{texto}&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;115&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
    <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>VBox<span style="color: #000066; font-weight: bold;">&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>WindowedApplication<span style="color: #000066; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>Claro que esta aplicação ainda está bastante simples, mas o objetivo é demonstrar como pode ser facil conectar o AS3 com Python utilizando socket, para quem não conhece python, vale a pena dar uma estudada, é uma linguagem muito util, poderosa, e simples, que é utilizada em diversos lugares, alguns exemplos bons são nasa e google (precisa mais ? ), agora mistura isso com AS3  (tem algo MUITO funcional e bonito).</p>
<p><strong>Explicação rapida</strong></p>
<p>A sintaxe é muito parecida com a Tweener (classe de tween) que ja é bastante conhecida, então creio que não deve ter muita dificuldade para utilizar esta classe. Sendo que para chamar uma função do python é só chamar     instancia.call(“nome_da_funcao”,{nome_do_argumento:valor_do_argumento…….});</p>
<p>Se alguem tiver alguma duvida, ou sugestão para esta classe ou para futuras classes, deixe um comentario ou envie por email mesmo.</p>
<p>A formatação dos codigos ainda  não está boa, mas esta melhorando (plugin do Windows Live Writer)  se alguem conhecer algum plugin para formatar codigos que tenha suporte a AS, Python, PHP,e C  me avisa.</p>
]]></content:encoded>
			<wfw:commentRss>http://armandokeller.com/blog/2009/01/conexo-as3-com-python-via-socket-simplificado/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JSFL para converter png e jpg para swf (até 92% de compressão)</title>
		<link>http://armandokeller.com/blog/2008/12/jsfl-para-converter-png-e-jpg-para-swf-ate-92-de-compressao/</link>
		<comments>http://armandokeller.com/blog/2008/12/jsfl-para-converter-png-e-jpg-para-swf-ate-92-de-compressao/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 14:22:42 +0000</pubDate>
		<dc:creator>Armando Leopoldo Keller</dc:creator>
				<category><![CDATA[Flash geral]]></category>
		<category><![CDATA[JSFL]]></category>

		<guid isPermaLink="false">http://alkeller.wordpress.com/?p=35</guid>
		<description><![CDATA[JSFL que exporta imagens para swf, realizando uma compressão de até 92% no tamanho dos arquivos.]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript">
			<!-- 
				tweetmeme_url = "http://armandokeller.com/blog/2008/12/jsfl-para-converter-png-e-jpg-para-swf-ate-92-de-compressao/";
				tweetmeme_source = "tweetmeme";
				tweetmeme_style = "";
				
			//-->
			</script>
                        <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script>
			<!-- 
			var fbShare = {
				url: "http://armandokeller.com/blog/2008/12/jsfl-para-converter-png-e-jpg-para-swf-ate-92-de-compressao/",
				size: "large",
				google_analytics: "true"
			}
			//-->
			</script>
                        <script src="http://widgets.fbshare.me/files/fbshare.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript"><!-- 
		(function() {
		var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
		s.type = 'text/javascript';
		s.async = true;
		s.src = 'http://widgets.digg.com/buttons.js';
		s1.parentNode.insertBefore(s, s1);
		})();
		//-->
		</script><a class="DiggThisButton " href="http://digg.com/submit?url=http%3A%2F%2Farmandokeller.com%2Fblog%2F2008%2F12%2Fjsfl-para-converter-png-e-jpg-para-swf-ate-92-de-compressao%2F"></a></div><div class="socialize-in-button socialize-in-button-vertical"><div class="delicious-button"><div class="del-top"><span id="35">0</span>saves</div><div class="del-bot"><a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;">Save</a></div></div>
		<script>
			<!-- 
			function displayURL(data) { var urlinfo = data[0]; if (!urlinfo.total_posts) return;document.getElementById('35').innerHTML = urlinfo.total_posts;}
			//-->
		</script>
		<script src = "http://badges.del.icio.us/feeds/json/url/data?url=http://armandokeller.com/blog/2008/12/jsfl-para-converter-png-e-jpg-para-swf-ate-92-de-compressao/&amp;callback=displayURL"></script></div></div><p>Aproveitando as ferias da faculdade e essa parada de final de ano para trazer mais um JSFL desta vez realmente util.</p>
<p>O que ele faz:</p>
<p>- Abre 3 janelas, a primeira para escolher em que pasta estão as imagens a serem convertidas, a segunda para ver onde vão ser salvos os swf , e a terceira para ver onde vão ser salvos os flas (essa pode ser cancelada caso não precise dos flas)</p>
<p>- Para cada imagem da pasta selecionada na primeira janela, ele vai criar um fla novo, importar a imagem, redimensionar o palco, colocar allowsmooth, e exportar o swf, se optou por salvar so flas, ele ira salvar o fla na pasta selecionada, caso contrario ira fechar o fla e ir para a proxima imagem.</p>
<p>Resultados:</p>
<p>- Com alguns testes que eu fiz nas ultimas semanas a compressão dos arquivos chegou até 92% (isso faz uma boa diferença em qualquer site).</p>
<p>- Está facil de usar, qualquer um consegue usar, pois o jsfl faz tudo praticamente sozinho.</p>
<p>O JSFL:</p>
<p>Salve o codigo a seguir em como um arquivo jsfl:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
* JSFL para converter imagens para swf
* Importa a imagem em um fla novo, e exporta o swf com a imagem. (redução de até 92% no &quot;peso do arquivo&quot;)
* @author Armando Leopoldo Keller (alkeller@live.de)  http://alkeller.wordpress.com
*
* Quem utilizar esta classe, favor enviar um email para ALKELLER@LIVE.DE com o &quot;peso&quot; das imagens antes e depois de serem exportadas.
*
*/</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> fotosURI <span style="color: #339933;">=</span> fl.<span style="color: #660066;">browseForFolderURL</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Armando Leopoldo Keller(alkeller@live.de)<span style="color: #000099; font-weight: bold;">\n</span> <span style="color: #000099; font-weight: bold;">\n</span>Selecione a pasta das imagens.<span style="color: #000099; font-weight: bold;">\n</span> &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> swfsURI <span style="color: #339933;">=</span> fl.<span style="color: #660066;">browseForFolderURL</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Armando Leopoldo Keller(alkeller@live.de)<span style="color: #000099; font-weight: bold;">\n</span> <span style="color: #000099; font-weight: bold;">\n</span>Selecione a pasta dos swfs.<span style="color: #000099; font-weight: bold;">\n</span> &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> flasURI <span style="color: #339933;">=</span> fl.<span style="color: #660066;">browseForFolderURL</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Armando Leopoldo Keller(alkeller@live.de)<span style="color: #000099; font-weight: bold;">\n</span> <span style="color: #000099; font-weight: bold;">\n</span>Selecione a pasta dos flas.<span style="color: #000099; font-weight: bold;">\n</span> &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> fileMask1 <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;*.png&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> fileMask2 <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;*.jpg&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> list1 <span style="color: #339933;">=</span> FLfile.<span style="color: #660066;">listFolder</span><span style="color: #009900;">&#40;</span>fotosURI <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/&quot;</span> <span style="color: #339933;">+</span> fileMask1<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;files&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> list2 <span style="color: #339933;">=</span> FLfile.<span style="color: #660066;">listFolder</span><span style="color: #009900;">&#40;</span>fotosURI <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/&quot;</span> <span style="color: #339933;">+</span> fileMask2<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;files&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> converte<span style="color: #009900;">&#40;</span>list<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> list<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> doc <span style="color: #339933;">=</span> fl.<span style="color: #660066;">createDocument</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		doc.<span style="color: #660066;">importFile</span><span style="color: #009900;">&#40;</span>fotosURI<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;/&quot;</span><span style="color: #339933;">+</span>list<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> it <span style="color: #339933;">=</span> doc.<span style="color: #660066;">library</span>.<span style="color: #660066;">items</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		it.<span style="color: #660066;">quality</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">80</span><span style="color: #339933;">;</span>
		it.<span style="color: #660066;">allowSmoothing</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		doc.<span style="color: #660066;">addItem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>x<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>y<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>it<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> selecionado <span style="color: #339933;">=</span> doc.<span style="color: #660066;">getTimeline</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">layers</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">frames</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">elements</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		selecionado.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
		selecionado.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
		doc.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>selecionado.<span style="color: #660066;">width</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		doc.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>selecionado.<span style="color: #660066;">height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		doc.<span style="color: #660066;">frameRate</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>flasURI<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			fl.<span style="color: #660066;">saveDocument</span><span style="color: #009900;">&#40;</span>doc<span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span>flasURI<span style="color: #339933;">+</span><span style="color: #3366CC;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>list<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.png&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.jpg&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'.fla'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		doc.<span style="color: #660066;">exportSWF</span><span style="color: #009900;">&#40;</span>swfsURI<span style="color: #339933;">+</span><span style="color: #3366CC;">'/'</span><span style="color: #339933;">+</span>list<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.png&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.jpg&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'.swf'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		doc.<span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>fotosURI <span style="color: #339933;">&amp;&amp;</span> swfsURI<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>list1.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>converte<span style="color: #009900;">&#40;</span>list1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// png</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>list2.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>converte<span style="color: #009900;">&#40;</span>list2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// jpg</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Você deve selecionar todas as pastas.(a de .flas é opcional)&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Claro que ainda pode ser otimizado, assim que tiver mais tempo quero ver se otimizo ele.</p>
<p>Observaçoes importantes:</p>
<p>- Quando for converter pngs, exporte todos eles como interlaced (faça um batch no photoshop) assim ele não fica perguntando se quer importar como um bitmap flateado.</p>
<p>- Quem utilizar ele, favor mandar um email ou colocar aqui nos comentarios o tamanho dos arquivos convertidos antes e depois de converter (a soma de todos os arquivos) para motivos de estatistica e para ver se ainda tem como reduzir mais sem perder a qualidade da imagem.</p>
<p>Qualquer duvida é só colocar nos comentarios que eu respondo assim que tiver tempo.</p>
]]></content:encoded>
			<wfw:commentRss>http://armandokeller.com/blog/2008/12/jsfl-para-converter-png-e-jpg-para-swf-ate-92-de-compressao/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>BUG no flashplayer (votem para corrigirem)</title>
		<link>http://armandokeller.com/blog/2008/11/bug-no-flashplayer-votem-para-corrigirem/</link>
		<comments>http://armandokeller.com/blog/2008/11/bug-no-flashplayer-votem-para-corrigirem/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 01:23:12 +0000</pubDate>
		<dc:creator>Armando Leopoldo Keller</dc:creator>
				<category><![CDATA[Flash geral]]></category>
		<category><![CDATA[flash player]]></category>
		<category><![CDATA[BUG]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[TextField]]></category>

		<guid isPermaLink="false">http://alkeller.wordpress.com/?p=29</guid>
		<description><![CDATA[reporte de bug que impede a entrada de caracteres especiais em campos de texto quando o wmode esta transparente.]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript">
			<!-- 
				tweetmeme_url = "http://armandokeller.com/blog/2008/11/bug-no-flashplayer-votem-para-corrigirem/";
				tweetmeme_source = "tweetmeme";
				tweetmeme_style = "";
				
			//-->
			</script>
                        <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script>
			<!-- 
			var fbShare = {
				url: "http://armandokeller.com/blog/2008/11/bug-no-flashplayer-votem-para-corrigirem/",
				size: "large",
				google_analytics: "true"
			}
			//-->
			</script>
                        <script src="http://widgets.fbshare.me/files/fbshare.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript"><!-- 
		(function() {
		var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
		s.type = 'text/javascript';
		s.async = true;
		s.src = 'http://widgets.digg.com/buttons.js';
		s1.parentNode.insertBefore(s, s1);
		})();
		//-->
		</script><a class="DiggThisButton " href="http://digg.com/submit?url=http%3A%2F%2Farmandokeller.com%2Fblog%2F2008%2F11%2Fbug-no-flashplayer-votem-para-corrigirem%2F"></a></div><div class="socialize-in-button socialize-in-button-vertical"><div class="delicious-button"><div class="del-top"><span id="29">0</span>saves</div><div class="del-bot"><a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;">Save</a></div></div>
		<script>
			<!-- 
			function displayURL(data) { var urlinfo = data[0]; if (!urlinfo.total_posts) return;document.getElementById('29').innerHTML = urlinfo.total_posts;}
			//-->
		</script>
		<script src = "http://badges.del.icio.us/feeds/json/url/data?url=http://armandokeller.com/blog/2008/11/bug-no-flashplayer-votem-para-corrigirem/&amp;callback=displayURL"></script></div></div><p>Bom, como devem ter percebido o blog está meio abandonado já faz algum tempo, mas isso devido a falta de tempo, trabalho + faculdade = no time <img src='http://armandokeller.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  , agora nas ferias da faculdade vou ter mais tempo para escrever aqui.</p>
<p>Hoje quero pedir a ajuda de toso os desenvolvedores que estão lendo o blog, para votarem para a adobe corrigir este bug ( <span class="Apple-style-span" style="border-collapse:separate;color:#000000;font-family:'Lucida Grande';font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-indent:0;text-transform:none;white-space:pre;widows:2;word-spacing:0;"><a title="http://bugs.adobe.com/jira/browse/FP-501" href="http://bugs.adobe.com/jira/browse/FP-501" target="_blank">http://bugs.adobe.com/jira/browse/FP-501</a> ) </span>, este bug é muito incomodo para a entrada de textos em flash (formularios), quando o wmode esta transparente é impossivel digitar caracteres como &#8220;ãéíúê&#8221;&#8230; e todos os outros caracteres que precisam de duas teclas para serem inseridos como por exemplo teclados que possuem a tecla ç  conseguem inserir a mesma, ja teclados como os de notebooks que precisa digitar &#8216; + c para inserir o ç não é possivel usar ç nos campos <img src='http://armandokeller.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />    aqui tem um exemplo do bug acontecendo ( <span class="Apple-style-span" style="border-collapse:separate;color:#000000;font-family:'Lucida Grande';font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-indent:0;text-transform:none;white-space:pre;widows:2;word-spacing:0;"><a title="http://www.5etdemi.com/blog/archives/2005/06/firefox-wmodetransparent-is-completely-screwy-and-breaks-textfields/" href="http://www.5etdemi.com/blog/archives/2005/06/firefox-wmodetransparent-is-completely-screwy-and-breaks-textfields/" target="_blank">http://www.5etdemi.com/blog/archives/2005/06/firefox-wmodetransparent-is-completely-screwy-and-breaks-textfields/</a> )</span>.</p>
<p>Quem encontrar outro bug no flashplayer ( mas que tenha certeza que é no flashplayer e não no seu codigo, e nem algo que foi alterado por questoes de segurança) por favor, verifique se o bug ja foi reportado, se foi reportado, comente e vote para que ele seja corrigido (isso agiliza o processo), caso contrario reporte ele.</p>
<p>Desde ja, obrigado a todos os que votarem,  e provavelmente agora em dezembro eu volte a postar com mais frequencia.</p>
<p>Ideia dos proximos posts:  Como usar o debuger, inserir flash no flex, inserir flex no flash, performance no AS3 &#8230;.      Se  alguem  tiver mais alguma sugestão, avisa por email, ou por comentario.</p>
]]></content:encoded>
			<wfw:commentRss>http://armandokeller.com/blog/2008/11/bug-no-flashplayer-votem-para-corrigirem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSFL para ajustar posiçoes dos itens como campos de texto com pixelFonts(pixel Snapping)</title>
		<link>http://armandokeller.com/blog/2008/07/jsfl-para-ajustar-posicoes-dos-itens-como-campos-de-texto-com-pixelfontspixel-snapping/</link>
		<comments>http://armandokeller.com/blog/2008/07/jsfl-para-ajustar-posicoes-dos-itens-como-campos-de-texto-com-pixelfontspixel-snapping/#comments</comments>
		<pubDate>Sat, 12 Jul 2008 01:28:55 +0000</pubDate>
		<dc:creator>Armando Leopoldo Keller</dc:creator>
				<category><![CDATA[AS 2.0]]></category>
		<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Flash geral]]></category>
		<category><![CDATA[JSFL]]></category>
		<category><![CDATA[as2]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[pixelSnapping]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://alkeller.wordpress.com/?p=15</guid>
		<description><![CDATA[0savesSave Olá, primeiramente quero dizer que não tenho postado muita coisa no blog devido a falta de tempo, e tambem de conteudo(até se alguem tiver alguma sugestão manda por email ou coloca aqui como comentario que eu farei o possivel para falar sobre o assunto). Hoje a tarde depois de arrumar as posiçoes dezenas de [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript">
			<!-- 
				tweetmeme_url = "http://armandokeller.com/blog/2008/07/jsfl-para-ajustar-posicoes-dos-itens-como-campos-de-texto-com-pixelfontspixel-snapping/";
				tweetmeme_source = "tweetmeme";
				tweetmeme_style = "";
				
			//-->
			</script>
                        <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script>
			<!-- 
			var fbShare = {
				url: "http://armandokeller.com/blog/2008/07/jsfl-para-ajustar-posicoes-dos-itens-como-campos-de-texto-com-pixelfontspixel-snapping/",
				size: "large",
				google_analytics: "true"
			}
			//-->
			</script>
                        <script src="http://widgets.fbshare.me/files/fbshare.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript"><!-- 
		(function() {
		var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
		s.type = 'text/javascript';
		s.async = true;
		s.src = 'http://widgets.digg.com/buttons.js';
		s1.parentNode.insertBefore(s, s1);
		})();
		//-->
		</script><a class="DiggThisButton " href="http://digg.com/submit?url=http%3A%2F%2Farmandokeller.com%2Fblog%2F2008%2F07%2Fjsfl-para-ajustar-posicoes-dos-itens-como-campos-de-texto-com-pixelfontspixel-snapping%2F"></a></div><div class="socialize-in-button socialize-in-button-vertical"><div class="delicious-button"><div class="del-top"><span id="15">0</span>saves</div><div class="del-bot"><a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;">Save</a></div></div>
		<script>
			<!-- 
			function displayURL(data) { var urlinfo = data[0]; if (!urlinfo.total_posts) return;document.getElementById('15').innerHTML = urlinfo.total_posts;}
			//-->
		</script>
		<script src = "http://badges.del.icio.us/feeds/json/url/data?url=http://armandokeller.com/blog/2008/07/jsfl-para-ajustar-posicoes-dos-itens-como-campos-de-texto-com-pixelfontspixel-snapping/&amp;callback=displayURL"></script></div></div><p>Olá, primeiramente quero dizer que não tenho postado muita coisa no blog devido a falta de tempo, e tambem de conteudo(até se alguem tiver alguma sugestão manda por email ou coloca aqui como comentario que eu farei o possivel para falar sobre o assunto).</p>
<p>Hoje a tarde depois de arrumar as posiçoes dezenas de movieClips para que não distorcessem eu pensei &#8220;por que eu estou fazendo isso? o flash poderia fazer sozinho&#8221;, então criei este JSFL que faz exatamente isto <a title="Pixel Snapping [alk].jsfl" href="http://paginas.terra.com.br/lazer/alksk8/Pixel%20Snapping%20alk.jsfl" target="_blank">(link)</a></p>
<p>OBS: se o link não funcionar copie ele e cole no navegador;</p>
<p>Como utilizar: é só executar.</p>
<p>ele pega todos os itens(movieClip,Button,Graphic,TextField..)  da timeline atual e ajusta  as posiçoes dos mesmos.</p>
<p>para aplicar isto dentro de um movieClip , abra-o e execute o comando dentro do movie;</p>
<p>pra quem não conseguiu abrir o link aqui vai o codigo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Pixel Snapping [alk].jsfl</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/*
Script criado por Armando Leopoldo Keller(http://alkeller.wordpress.com)
para instalar: só colar este arquivo em C:\Users\nome_do_usuario\AppData\Local\Adobe\Flash CS3\en\Configuration\Commands
obs: este é o caminho no windows vista
*/</span>
<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> fl.<span style="color: #660066;">getDocumentDOM</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTimeline</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">layers</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> layerAtual <span style="color: #339933;">=</span> fl.<span style="color: #660066;">getDocumentDOM</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTimeline</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">layers</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> j <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> layerAtual.<span style="color: #660066;">frames</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> frameAtual <span style="color: #339933;">=</span> layerAtual.<span style="color: #660066;">frames</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> k <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">;</span> k <span style="color: #339933;">&lt;</span> frameAtual.<span style="color: #660066;">elements</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">;</span> k<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> elementoAtual <span style="color: #339933;">=</span> frameAtual.<span style="color: #660066;">elements</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
elementoAtual.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>elementoAtual.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
elementoAtual.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>elementoAtual.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Qualquer coisa é só comentar, ou mandar email que eu respondo.</p>
]]></content:encoded>
			<wfw:commentRss>http://armandokeller.com/blog/2008/07/jsfl-para-ajustar-posicoes-dos-itens-como-campos-de-texto-com-pixelfontspixel-snapping/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Classe para utilização de SQL em AIR (Flash, Flex)</title>
		<link>http://armandokeller.com/blog/2008/04/classe-para-utilizacao-de-sql-em-air-flash-flex/</link>
		<comments>http://armandokeller.com/blog/2008/04/classe-para-utilizacao-de-sql-em-air-flash-flex/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 22:42:27 +0000</pubDate>
		<dc:creator>Armando Leopoldo Keller</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Flash geral]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[AS 3]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[DB]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://alkeller.wordpress.com/?p=12</guid>
		<description><![CDATA[0savesSave Neste tutorial mostrarei como utilizar uma classe que eu criei para facilitar o uso de SQL em AIR (tanto para flash quanto para flex) A classe é esta: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:left;"><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript">
			<!-- 
				tweetmeme_url = "http://armandokeller.com/blog/2008/04/classe-para-utilizacao-de-sql-em-air-flash-flex/";
				tweetmeme_source = "tweetmeme";
				tweetmeme_style = "";
				
			//-->
			</script>
                        <script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script>
			<!-- 
			var fbShare = {
				url: "http://armandokeller.com/blog/2008/04/classe-para-utilizacao-de-sql-em-air-flash-flex/",
				size: "large",
				google_analytics: "true"
			}
			//-->
			</script>
                        <script src="http://widgets.fbshare.me/files/fbshare.js"></script></div><div class="socialize-in-button socialize-in-button-vertical"><script type="text/javascript"><!-- 
		(function() {
		var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
		s.type = 'text/javascript';
		s.async = true;
		s.src = 'http://widgets.digg.com/buttons.js';
		s1.parentNode.insertBefore(s, s1);
		})();
		//-->
		</script><a class="DiggThisButton " href="http://digg.com/submit?url=http%3A%2F%2Farmandokeller.com%2Fblog%2F2008%2F04%2Fclasse-para-utilizacao-de-sql-em-air-flash-flex%2F"></a></div><div class="socialize-in-button socialize-in-button-vertical"><div class="delicious-button"><div class="del-top"><span id="12">0</span>saves</div><div class="del-bot"><a href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;">Save</a></div></div>
		<script>
			<!-- 
			function displayURL(data) { var urlinfo = data[0]; if (!urlinfo.total_posts) return;document.getElementById('12').innerHTML = urlinfo.total_posts;}
			//-->
		</script>
		<script src = "http://badges.del.icio.us/feeds/json/url/data?url=http://armandokeller.com/blog/2008/04/classe-para-utilizacao-de-sql-em-air-flash-flex/&amp;callback=displayURL"></script></div></div><p>Neste tutorial mostrarei como utilizar uma classe que eu criei para facilitar o uso de SQL em AIR (tanto para flash quanto para flex)<br />
A classe é esta:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #3f5fbf;">/*
################################################
#                                              #
#   Classe  : DB (com.alkeller.air.DB)         #
#   Autor   : Armando Leopoldo Keller          #
#   Versão  : 1.0                              #
#   Contato : alksk8@hotmail.com               #
#   Blog    : http://alkeller.wordpress.com    #
#   Documentaçao em breve no blog              #
#                                              #
################################################
------- Deixe os creditos na classe ----------
*/</span>
<span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>alkeller<span style="color: #000066; font-weight: bold;">.</span>air
<span style="color: #000000;">&#123;</span>
	<span style="color: #009900; font-style: italic;">// Imports</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flash<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>SQLResult<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flash<span style="color: #000066; font-weight: bold;">.</span>filesystem<span style="color: #000066; font-weight: bold;">.</span>File<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flash<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>SQLStatement<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flash<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>SQLConnection<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span>SQLEvent<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span>SQLErrorEvent<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.errors</span><span style="color: #000066; font-weight: bold;">.</span>SQLError<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Classe;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> DB
	<span style="color: #000000;">&#123;</span>
		<span style="color: #009900; font-style: italic;">// Variaveis utilizadas;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> conectado<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> dbFile<span style="color: #000066; font-weight: bold;">:</span>File
		<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> conn<span style="color: #000066; font-weight: bold;">:</span>SQLConnection
		<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> _sqlStatement<span style="color: #000066; font-weight: bold;">:</span>SQLStatement<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> resultado<span style="color: #000066; font-weight: bold;">:</span>SQLResult<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> retornoString<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> retornoObjeto<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #009900; font-style: italic;">// Funçao Inicia :utilizada para conectar com o banco de dados;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> Inicia<span style="color: #000000;">&#40;</span>_nome<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span>
		<span style="color: #000000;">&#123;</span>
			conn = <span style="color: #0033ff; font-weight: bold;">new</span> SQLConnection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			dbFile = File<span style="color: #000066; font-weight: bold;">.</span>applicationStorageDirectory<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #004993;">String</span><span style="color: #000000;">&#40;</span>_nome<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;.db&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">try</span>
			<span style="color: #000000;">&#123;</span>
				conn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">open</span><span style="color: #000000;">&#40;</span>dbFile<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				conectado = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Conectado com &quot;</span><span style="color: #000066; font-weight: bold;">+</span>_nome<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;.db&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				retornoString = <span style="color: #990000;">&quot;Conectado com &quot;</span><span style="color: #000066; font-weight: bold;">+</span>_nome<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;.db&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">catch</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">:</span>SQLError<span style="color: #000000;">&#41;</span> 
			<span style="color: #000000;">&#123;</span>
				conectado = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
				retornoString = <span style="color: #990000;">&quot;Falha ao conectar: &quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">message</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;<span style="">\n</span>Detalhes: &quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">.</span>details<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> retornoString<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900; font-style: italic;">// Funçao executeQuery: Utilizada para executar um comando SQL(verificar quais são aceitos pelo AIR);</span>
		<span style="color: #009900; font-style: italic;">// Retorno: SQLResult --&gt; http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/data/SQLResult.html</span>
		<span style="color: #009900; font-style: italic;">// ou  String de erro;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> executeQuery<span style="color: #000000;">&#40;</span>_sql<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>conectado == <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				_sqlStatement = <span style="color: #0033ff; font-weight: bold;">new</span> SQLStatement<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				_sqlStatement<span style="color: #000066; font-weight: bold;">.</span>sqlConnection = conn<span style="color: #000066; font-weight: bold;">;</span>
				_sqlStatement<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = _sql<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #0033ff; font-weight: bold;">try</span>
				<span style="color: #000000;">&#123;</span>
					_sqlStatement<span style="color: #000066; font-weight: bold;">.</span>execute<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					resultado = _sqlStatement<span style="color: #000066; font-weight: bold;">.</span>getResult<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					retornoObjeto = resultado<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0033ff; font-weight: bold;">catch</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">:</span>SQLError<span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					retornoString = <span style="color: #990000;">&quot;Falha ao executar(&quot;</span><span style="color: #000066; font-weight: bold;">+</span>_sql<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;): &quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">message</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;<span style="">\n</span>Detalhes: &quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">.</span>details<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0033ff; font-weight: bold;">return</span> retornoObjeto<span style="color: #000066; font-weight: bold;">?</span>retornoObjeto<span style="color: #000066; font-weight: bold;">:</span>retornoString<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">else</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #990000;">&quot;Não conectado!&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Classe para download: http://paginas.terra.com.br/lazer/alksk8/DB.as</p>
<p>Como utilizar:<br />
1 &#8211; Importe a classe:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// OBS: Aqui é bom verificar se a classe esta no local certo com/alkeller/air/</span>
<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>alkeller<span style="color: #000066; font-weight: bold;">.</span>air<span style="color: #000066; font-weight: bold;">.*;</span>
<span style="color: #009900; font-style: italic;">// ou</span>
<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>alkeller<span style="color: #000066; font-weight: bold;">.</span>air<span style="color: #000066; font-weight: bold;">.</span>DB<span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>2 &#8211; Inicie o banco:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">DB<span style="color: #000066; font-weight: bold;">.</span>Inicia<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;teste&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// sendo que teste é o nome do banco</span></pre></td></tr></table></div>

<p>3 &#8211; Se as tabelas não existirem, crie elas:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">DB<span style="color: #000066; font-weight: bold;">.</span>executeQuery<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;CREATE TABLE IF NOT EXISTS testando (id INTEGER PRIMARY KEY AUTOINCREMENT,nome TEXT,sobrenome TEXT)&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>4.1 &#8211; Execute as Querys que desejar, por exemplo inserir alguns dados:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">DB<span style="color: #000066; font-weight: bold;">.</span>executeQuery<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;INSERT INTO testando (id,nome,sobrenome) VALUES (null,'ARMANDO LEOPOLDO','KELLER')&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>4.2 &#8211; Exemplo de como buscar dados:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> obj<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = DB<span style="color: #000066; font-weight: bold;">.</span>executeQuery<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;SELECT * FROM testando&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> obj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;linha: &quot;</span><span style="color: #000066; font-weight: bold;">+</span>i<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> j<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> <span style="color: #0033ff; font-weight: bold;">in</span> obj<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>j<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;: &quot;</span><span style="color: #000066; font-weight: bold;">+</span>obj<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Aproveitem a classe <img src='http://armandokeller.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Em breve colocarei aqui este tutorial em video.</p>
]]></content:encoded>
			<wfw:commentRss>http://armandokeller.com/blog/2008/04/classe-para-utilizacao-de-sql-em-air-flash-flex/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

