<?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>Stefan Horochovec</title>
	<atom:link href="http://www.horochovec.com.br/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.horochovec.com.br/blog</link>
	<description>Blog sobre plataforma Flash - Flex e AIR - e sua integração com Java</description>
	<lastBuildDate>Mon, 12 Jul 2010 02:01:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>FlexMania 2010 &#8211; Sucesso absoluto</title>
		<link>http://www.horochovec.com.br/blog/2010/07/11/flexmania-2010-sucesso-absoluto/</link>
		<comments>http://www.horochovec.com.br/blog/2010/07/11/flexmania-2010-sucesso-absoluto/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 02:00:32 +0000</pubDate>
		<dc:creator>Stefan Horochovec</dc:creator>
				<category><![CDATA[Palestras]]></category>

		<guid isPermaLink="false">http://www.horochovec.com.br/blog/?p=465</guid>
		<description><![CDATA[Olá pessoal, como vão todos? Pois bem, fiquei um tempo fora do blog devido a uma série de compromissos na empresa aonde trabalho e de compromissos de ordem pessoal também, um deles foi o FlexMania 2010. Durante os dias 8, 9 e 10 de julho tivemos o prazer de acompanhar o FlexMania 2010, organizado pelo [...]]]></description>
			<content:encoded><![CDATA[<p>Olá pessoal, como vão todos?</p>
<p>Pois bem, fiquei um tempo fora do blog devido a uma série de compromissos na empresa aonde trabalho e de compromissos de ordem pessoal também, um deles foi o <a href="http://www.flexmania.com.br/" target="_new">FlexMania 2010</a>.</p>
<p>Durante os dias 8, 9 e 10 de julho tivemos o prazer de acompanhar o FlexMania 2010, organizado pelo Igor Costa, de forma gratuita através da excelente ferramenta da Adobe, o Adobe Connect.<br />
<span id="more-465"></span><br />
O FlexMania é um evento gratuito, idealizado e organizado por Igor Costa &#8211; Adobe Community Professional. Tive o enorme prazer em palestrar no <a href="http://www.flexmania.com.br/2009">FlexMania 2009</a> (clique <a href="http://experts.na3.acrobat.com/p43706438/" target="_new">aqui</a> para assistir a gravação da minha palestra sobre &#8220;<em>Flex, Java e BlazeDS &#8211; Integração com alta produtividade e desempenho</em>&#8220;) e confesso que fiquei muito feliz e muito empolgado com o convite para o evento em 2010.</p>
<p>Foram dois meses de muita ansiedade. Para quem não sabe como funciona o processo do convite ao evento, os palestrantes recebem os convites, entretanto não sabem quais serão seus companheiros de &#8220;palco&#8221;, dessa forma, cria-se um grande mistério entre todos. Após um certo tempo, somos apresentados uns aos outros e logo em seguida o site do evento é publicado.</p>
<p>Esse ano recebi (e todos os outros palestrantes) da <a href="http://www.fdt.powerflasher.com/">PowerFlasher</a> uma licença do seu editor, o FDT. E não só nós, diversas licenças foram sorteadas durante o evento além de todos os outros produtos, em uma soma de mais de R$ 30.000,00 em prêmios. É muita coisa quando falamos de um evento on-line que você não paga absolutamente nada para participar.</p>
<p>A grande sensação do evento foi as reações do twitter a cada palestra, principalmente pela galera do #soudev. Imagino que muitos novos colegas da madrugada irão surgir com posts #soudev depois do FlexMania.</p>
<p>Esse ano eu abordei um assunto que a cada dia ganha mais espaço no mundo da TI e agora os grandes data centers do país começaram a disponibilizar esse serviço, o Cloud Computing.</p>
<p>Minha abordagem teve inicio sobre os tipos de cloud-computing, vantagens e suas desvantagens (nem tudo é um mar de rosas). Em seguida, entrei no assunto do <a href="http://appengine.google.com/" target="_new">Google App Engine</a>, o serviço do Google gratuito (até um certo ponto) para cloud computing, contanto com recursos de Java e armazenamento de dados.</p>
<p>Mostrei suas vantagens, formas de utilização, plugins e ferramentas disponíveis e finalmente entrei no assunto <a href="http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK">Adobe Flex</a>, demonstrando o que deve ser alterado nas configurações padrões do Adobe Flex com <a href="http://java.sun.com/" target="_new">Java</a> para que possamos utilizar o <a href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS" target="_new">BlazeDS</a> dentro da estrutura do Google.</p>
<p>Conforme prometido ao final da palestra, estou disponibilizando para download os projetos (Java e Flex) e os slides utilizados na apresentação.</p>
<p><strong>Slides:</strong></p>
<div id="__ss_4725764" style="width: 425px;"><strong><a title="FlexMania 2010" href="http://www.slideshare.net/horochovec/flexmania-2010">FlexMania 2010</a></strong><object id="__sse4725764" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=apresentao-100710093544-phpapp01&amp;stripped_title=flexmania-2010" /><param name="name" value="__sse4725764" /><param name="allowfullscreen" value="true" /><embed id="__sse4725764" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=apresentao-100710093544-phpapp01&amp;stripped_title=flexmania-2010" name="__sse4725764" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="padding: 5px 0 12px;">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/horochovec">Stefan Horochovec</a>.</div>
</div>
<p><strong>Projeto Java:</strong> clique <a href="http://www.horochovec.com.br/blog/flexmania2010/ProjetoJava.zip">aqui</a> para download</p>
<p><strong>Projeto AIR:</strong> clique <a href="http://www.horochovec.com.br/blog/flexmania2010/ProjetoFlex.zip">aqui</a> para download</p>
<p><strong>Agradecimentos:</strong></p>
<ul>
<li><strong>Igor Costa &#8211; Adobe Community Professional</strong> pelo convite e por todo suporte antes e durante o evento;</li>
<li><strong>IDS &#8211; Software e Consultoria LTDA</strong> por permitir minha participação;</li>
<li><strong>Patrocinadores:</strong></li>
<li>Adobe System</li>
<li><strong>RIACycle </strong>(pela camiseta e pelo boné)</li>
<li><strong>PowerFlasher</strong> (em especial pela licença do FDT cedida cordialmente a todos os palestrantes do evento)</li>
<li>Mundo Livre Tecnologia</li>
<li>Oreilly</li>
<li>ElementRiver</li>
</ul>
<p>Espero ter contruído e despertado o interesse dos desenvolvedores a conhecer um pouco mais sobre a estrutura do Google App Engine integrando Flex e Java nessa estrutura incrível que o Google dispõe para nós.</p>
<p>Um forte abraço ao Igor Costa, a todos os palestrantes e patrocinadores e a todos que participaram do evento.</p>
<p>Agora é esperar pelo FlexMania 2011. Mas antes ainda temos pela frente a <a href="http://www.brconference.com.br" target="_new">BRConferente</a>, organizada pelo Pedro Claudio &#8211; Adobe Community Professional, e também o <a href="http://www.flashcampbrasil.com.br/" target="_new">Flash Camp Brasil</a>, organizado pelo Demian Borba &#8211; Adobe Community Professional.</p>
<p>Como é bom ver a quantia de eventos que estão surgindo no Brasil. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.horochovec.com.br/blog/2010/07/11/flexmania-2010-sucesso-absoluto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Palestra na Vizivali sobre Adobe Flash Plataform</title>
		<link>http://www.horochovec.com.br/blog/2010/06/19/palestra-na-vizivali-sobre-adobe-flash-plataform/</link>
		<comments>http://www.horochovec.com.br/blog/2010/06/19/palestra-na-vizivali-sobre-adobe-flash-plataform/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 21:50:19 +0000</pubDate>
		<dc:creator>Stefan Horochovec</dc:creator>
				<category><![CDATA[Sem categoria]]></category>

		<guid isPermaLink="false">http://www.horochovec.com.br/blog/?p=457</guid>
		<description><![CDATA[Olá Recentemente (dia 07 de junho) tive o prazer de estar novamente em Dois Vizinhos &#8211; Paraná (já estive em outra oportunidade ministrando um curso de Adobe Flex 3 em parceria com a Sudotec), mais precisamente na Faculdade Vizivali para uma palestra sobre a Adobe Flash Plataform. O convite foi feito pelo coordenador do curso [...]]]></description>
			<content:encoded><![CDATA[<p>Olá</p>
<p>Recentemente (dia 07 de junho) tive o prazer de estar novamente em Dois Vizinhos &#8211; Paraná (já estive em outra oportunidade ministrando um curso de Adobe Flex 3 em parceria com a <a href="http://www.sudotec.org.br/" target="_new">Sudotec</a>), mais precisamente na Faculdade <a href="http://www.vizivali.edu.br/">Vizivali</a> para uma palestra sobre a Adobe Flash Plataform.<br />
<span id="more-457"></span><br />
O convite foi feito pelo coordenador do curso de Sistemas de Informação para Internet, o professor e mestre Lucas Sandini. Tive a oportunidade de durante uma hora e meia explicar e demonstrar as ferramentas e recursos que a <a href="http://www.adobe.com/" target="_new">Adobe</a> disponibiliza para o desenvolvimento de soluções RIA.</p>
<p>Também aproveitei a oportunidade para efetuar um sorteio de uma vaga no curso de Adobe Flex 4 e Java que será ministrado no dia 03 de julho em parceria com a <a href="http://www.riacycle.com/java" target="_new">RIACycle</a>.</p>
<p>Foi muito bacana estar presente no evento, agradeço novamente o convite e podem contar comigo sempre que for preciso na instituição.</p>
<p>Um abraço a todos os docentes da Vizivali, que me receberam muito bem e a todos os acadêmicos presentes na semana acadêmica.</p>
<p>Sobre a semana acadêmica, clique <a href="http://www.vizivali.edu.br/notindividual.asp?id=336" target="_new">aqui</a>.</p>
<p>Abaixo algumas fotos:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/06/vizivali01.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/06/vizivali01.jpg" alt="" title="vizivali01" width="560" height="398" class="aligncenter size-full wp-image-458" /></a></p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/06/vizivali02.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/06/vizivali02.jpg" alt="" title="vizivali02" width="560" height="450" class="aligncenter size-full wp-image-459" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.horochovec.com.br/blog/2010/06/19/palestra-na-vizivali-sobre-adobe-flash-plataform/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adobe Flex 4 &#8211; States</title>
		<link>http://www.horochovec.com.br/blog/2010/05/13/adobe-flex-4-states/</link>
		<comments>http://www.horochovec.com.br/blog/2010/05/13/adobe-flex-4-states/#comments</comments>
		<pubDate>Thu, 13 May 2010 04:44:56 +0000</pubDate>
		<dc:creator>Stefan Horochovec</dc:creator>
				<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Flex4]]></category>
		<category><![CDATA[States]]></category>

		<guid isPermaLink="false">http://www.horochovec.com.br/blog/?p=420</guid>
		<description><![CDATA[Olá Neste post irei comentar um pouco sobre a grande evolução que os States sofreram no Adobe Flex 4 em relação as versões 2 e 3 do Flex SDK. Com novos recursos, realmente agora ficou muito fácil sua implementação em nossos projetos. Na versão 3 do Flex SDK, era muito difícil a utilização de States [...]]]></description>
			<content:encoded><![CDATA[<p>Olá</p>
<p>Neste post irei comentar um pouco sobre a grande evolução que os<strong> States </strong>sofreram no Adobe Flex 4 em relação as versões 2 e 3 do Flex SDK. Com novos recursos, realmente agora ficou muito fácil sua implementação em nossos projetos.<br />
<span id="more-420"></span><br />
Na versão 3 do Flex SDK, era muito difícil a utilização de States em nossas aplicações. Sua implementação era muito complexa e ao invés de facilitar a vida do desenvolvedor na verdade ela criava mais uma barreira para o desenvolvimento, ou seja, muito pouco material você irá encontrar na internet caso pesquise, encorajando a sua utilização.</p>
<p>Entretanto, no Flex 4 SDK, os States foram reformulados. Sua implementação ficou muito mais fácil e agora sim, vale a pena utilizar esse recurso em seus projetos.</p>
<p>Para exemplificar a utilização do State, iremos criar um projeto em nosso Adobe Flash Builder, conforme imagem abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/011.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/011.jpg" alt="" title="" width="523" height="649" class="aligncenter size-full wp-image-423" /></a></p>
<p>Feito isso, iremos criar um layout que contemple essas duas situações:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/mockup_2.png"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/mockup_2.png" alt="Tela de Login" title="" width="524" height="423" class="aligncenter size-full wp-image-426" /></a></p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/mockup_4.png"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/mockup_4.png" alt="Tela de Cadastro" title="" width="524" height="423" class="aligncenter size-full wp-image-430" /></a></p>
<p>O detalhe é que esse layout irá conter um único TitleWindow, e não iremos utilizar nenhum ViewStack para fazer as telas de login e cadastro. Iremos apenas usar os novos conceitos de States para mostrar e ocultar informações.</p>
<p>Primeiro passo será criar a tela de Login, conforme imagem e código abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/031.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/031.jpg" alt="" title="" width="520" height="342" class="aligncenter size-full wp-image-431" /></a></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=420&amp;download=States.mxml">States.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4207"><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" id="p420code7"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> 
			   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> 
			   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;!</span>-- Place non-visual elements <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">g</span>., services, value objects<span style="color: #66cc66;">&#41;</span> here --<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:TitleWindow <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;384&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;200&quot;</span> horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> verticalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> title=<span style="color: #ff0000;">&quot;Login&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:layout<span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>s:BasicLayout<span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;/</span>s:layout<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:Label <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Olá, Seja bem vindo(a)!&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span> top=<span style="color: #ff0000;">&quot;15&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:Label <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Email:&amp;#xd;&quot;</span> top=<span style="color: #ff0000;">&quot;52&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;25&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:TextInput <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;65&quot;</span> top=<span style="color: #ff0000;">&quot;47&quot;</span> <span style="color: #0066CC;">right</span>=<span style="color: #ff0000;">&quot;15&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:Label <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Senha:&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;20&quot;</span> top=<span style="color: #ff0000;">&quot;82&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:TextInput x=<span style="color: #ff0000;">&quot;65&quot;</span> y=<span style="color: #ff0000;">&quot;77&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;148&quot;</span> displayAsPassword=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Entrar&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;65&quot;</span> top=<span style="color: #ff0000;">&quot;107&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Limpar&quot;</span> top=<span style="color: #ff0000;">&quot;107&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;143&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Não sou cadastrado&quot;</span> top=<span style="color: #ff0000;">&quot;107&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;221&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>s:TitleWindow<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Podemos observar que todos os objetos contidos no TitleWindow foram posicionados através de posicionamento relativo, utilizando valores para &#8220;left, right, top&#8221; e não valores para &#8220;x e y&#8221;. Até então tudo normal, sem nenhuma implementação nova. </p>
<p>Agora, iremos adicionar um novo State para nossa aplicação para o formulário de cadastro, conforme imagem abaixo. Caso seu Adobe Flash Builder não esteja com o painel para <strong>States</strong> habilitado. Utilize a opção &#8220;<strong>Window -> States</strong>&#8220;.</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/04.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/04.jpg" alt="" title="" width="520" height="342" class="aligncenter size-full wp-image-435" /></a></p>
<p>No campo <strong>Name</strong>, informamos o nome de nosso State, <strong>Cadastro</strong>, e na opção &#8220;<em>Create as</em>&#8221; iremos deixar marcada a opção para que o State a ser criado seja uma duplicação do <strong>State1</strong>, que é o nome padrão do State inicial dentro do Adobe Flash Builder.</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/05.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/05.jpg" alt="" title="" width="520" height="342" class="aligncenter size-full wp-image-437" /></a></p>
<p>Agora iremos alterar o nome do nosso primeiro State em nossa aplicação. Para isso, iremos clicar em cima do nome <strong>State1</strong>, e solicitar sua alteração, conforme imagem abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/06.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/06.jpg" alt="" title="" width="520" height="342" class="aligncenter size-full wp-image-440" /></a></p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/07.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/07.jpg" alt="" title="" width="520" height="342" class="aligncenter size-full wp-image-441" /></a></p>
<p>Feito isso, podemos verificar quais alterações ocorreram em nosso código-fonte e em nosso ambiente visual. Nosso layout não sofreu nenhuma alteração, surgindo apenas um bloco de códigos com as definições dos States.</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/08.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/08.jpg" alt="" title="" width="520" height="342" class="aligncenter size-full wp-image-442" /></a></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=420&amp;download=States.mxml">States.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4208"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p420code8"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>s:states<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:State <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Login&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:State <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Cadastro&quot;</span><span style="color: #66cc66;">/&gt;</span>
<span style="color: #66cc66;">&lt;/</span>s:states<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Agora, podemos dar inicio a construção de nossa tela de cadastro. Iremos então selecionar nosso State <strong>Cadastro</strong>, da seguinte forma:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/09.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/09.jpg" alt="" title="" width="520" height="342" class="aligncenter size-full wp-image-447" /></a></p>
<p>Feito isso, iremos iniciar as alterações em nossa janela, sem se preocupar com o State anterior. Obteremos então o seguinte resultado:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/10.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/10.jpg" alt="" title="" width="520" height="342" class="aligncenter size-full wp-image-448" /></a></p>
<p>Para o desenvolvimento desse layout, eu dupliquei o campo e o label do campo email para que eu pudesse armazenar o nome do usuário do sistema que fosse efetuar seu cadastro, e também dupliquei o campo e label senha, conforme a sugestão do layout.</p>
<p>Em seguida, alterei o label dos botões, e alterei o titulo de meu TitleWindow.</p>
<p>Entrando em modo de Design, obtemos o seguinte código:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=420&amp;download=States.mxml">States.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4209"><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
</pre></td><td class="code" id="p420code9"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> 
			   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> 
			   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:states<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:State <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Login&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:State <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Cadastro&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>s:states<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;!</span>-- Place non-visual elements <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">g</span>., services, value objects<span style="color: #66cc66;">&#41;</span> here --<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:TitleWindow <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;384&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;200&quot;</span> horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> verticalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> title=<span style="color: #ff0000;">&quot;Login&quot;</span> title.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;Cadastro&quot;</span> <span style="color: #0066CC;">height</span>.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;250&quot;</span> horizontalCenter.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;0&quot;</span> verticalCenter.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:layout<span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>s:BasicLayout<span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;/</span>s:layout<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:Label <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Olá, Seja bem vindo(a)!&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span> top=<span style="color: #ff0000;">&quot;15&quot;</span> <span style="color: #0066CC;">text</span>.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;Informe seus dados para o cadastro&amp;#xd;&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:Label <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Email:&amp;#xd;&quot;</span> top=<span style="color: #ff0000;">&quot;52&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;25&quot;</span> top.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;82&quot;</span> <span style="color: #0066CC;">left</span>.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;26&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:Label <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Nome:&quot;</span> top=<span style="color: #ff0000;">&quot;53&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;23&quot;</span> includeIn=<span style="color: #ff0000;">&quot;Cadastro&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:TextInput top=<span style="color: #ff0000;">&quot;77&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;66&quot;</span> <span style="color: #0066CC;">right</span>=<span style="color: #ff0000;">&quot;14&quot;</span> includeIn=<span style="color: #ff0000;">&quot;Cadastro&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:TextInput <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;65&quot;</span> top=<span style="color: #ff0000;">&quot;47&quot;</span> <span style="color: #0066CC;">right</span>=<span style="color: #ff0000;">&quot;15&quot;</span> top.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;47&quot;</span> <span style="color: #0066CC;">left</span>.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;66&quot;</span> <span style="color: #0066CC;">right</span>.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;14&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:Label <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Senha:&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;20&quot;</span> top=<span style="color: #ff0000;">&quot;82&quot;</span> top.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;112&quot;</span> <span style="color: #0066CC;">left</span>.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;21&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:TextInput x=<span style="color: #ff0000;">&quot;65&quot;</span> y=<span style="color: #ff0000;">&quot;77&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;148&quot;</span> displayAsPassword=<span style="color: #ff0000;">&quot;true&quot;</span> x.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;66&quot;</span> y.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;107&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:Label <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Senha:&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;21&quot;</span> top=<span style="color: #ff0000;">&quot;142&quot;</span> includeIn=<span style="color: #ff0000;">&quot;Cadastro&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:TextInput x=<span style="color: #ff0000;">&quot;66&quot;</span> y=<span style="color: #ff0000;">&quot;137&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;148&quot;</span> displayAsPassword=<span style="color: #ff0000;">&quot;true&quot;</span> includeIn=<span style="color: #ff0000;">&quot;Cadastro&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Entrar&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;65&quot;</span> top=<span style="color: #ff0000;">&quot;107&quot;</span> top.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;167&quot;</span> <span style="color: #0066CC;">left</span>.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;66&quot;</span> label.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;Cadastrar&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Limpar&quot;</span> top=<span style="color: #ff0000;">&quot;107&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;143&quot;</span> top.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;167&quot;</span> <span style="color: #0066CC;">left</span>.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;148&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Não sou cadastrado&quot;</span> top=<span style="color: #ff0000;">&quot;107&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;221&quot;</span> top.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;167&quot;</span> <span style="color: #0066CC;">left</span>.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;222&quot;</span> label.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;Efetuar Login&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>s:TitleWindow<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Nesse momento, fica fácil perceber como o Flex 4 SDK trabalha com os States. A cada propriedade comum de um objeto em mais de um State, é adicionado ao fim da propriedade, o nome do State correspondente. Para exemplificar, usaremos a declaração do TitleWindow:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=420&amp;download=States.mxml">States.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p42010"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p420code10"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>s:TitleWindow <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;384&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;200&quot;</span> horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> verticalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> title=<span style="color: #ff0000;">&quot;Login&quot;</span> title.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;Cadastro&quot;</span> <span style="color: #0066CC;">height</span>.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;250&quot;</span> horizontalCenter.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;0&quot;</span> verticalCenter.<span style="color: #006600;">Cadastro</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>A primeira vez o atributo <strong>title</strong> aparece sem a declaração de qual State deverá pertencer, ou seja, nesse caso esse é o valor quando o State da aplicação for o State <em>default</em>. Logo em seguida o atributo title aparece seguido de um ponto e do valor <strong>Cadastro</strong>, que é o nome de nosso segundo State, já com o novo valor do título da janela. E assim, essa regra permanece no próprio componente TitleWindow e também nos demais componentes.</p>
<p>É valido ressaltar, que ao selecionar o modo &#8220;Source&#8221; em seu Adobe Flash Builder, você também poderá mostrar o código de apenas um ou todos os States disponíveis em seu componente da seguinte forma:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/11.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/11.jpg" alt="" title="" width="520" height="342" class="aligncenter size-full wp-image-452" /></a></p>
<p>Nesse momento, podemos perceber que o Adobe Flash Builder oculta a codificação em MXML que não será utilizada no State selecionado.</p>
<p>Para efetuarmos a troca de State, faremos a seguinte implementação. Com o State <strong>Login</strong> selecionado, clique com o botão direito do mouse sob o botão com o label &#8220;<strong>Não sou cadastrado</strong>&#8221; e vá na opção &#8220;<strong>Generate Click Handler</strong>&#8220;.</p>
<p>Nesse momento, o Adobe Flash Builder entrará em modo &#8220;Source&#8221;. Faça a seguinte implementação:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=420&amp;download=States.mxml">States.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p42011"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p420code11"><pre class="actionscript" style="font-family:monospace;">protected <span style="color: #000000; font-weight: bold;">function</span> button1_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	currentState = <span style="color: #ff0000;">'Cadastro'</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Volte ao modo Design e faça a mesma operação no botão com o label &#8220;Efetuar Login&#8221; e faça a seguinte implementação:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=420&amp;download=States.mxml">States.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p42012"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p420code12"><pre class="actionscript" style="font-family:monospace;">protected <span style="color: #000000; font-weight: bold;">function</span> button2_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	currentState = <span style="color: #ff0000;">'Login'</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Pronto. Basta salvar e executar o projeto, e terá um exemplo simples e rápido para demonstrar o uso de States dentro do Flex 4 SDK. A partir de agora, fica por nossa conta a criatividade para sua melhor exploração. </p>
<p>Para ver o exemplo rodando clique <a href="http://www.horochovec.com.br/blog/demonstracao/05132010/" target="_new">aqui</a>.</p>
<p>Para ver o código fonte do exemplo completo clique <a href="http://www.horochovec.com.br/blog/demonstracao/05132010/srcview/index.html" target="_new">aqui</a>.</p>
<p>Para efetuar o download do exemplo clique <a href="http://www.horochovec.com.br/blog/demonstracao/05132010/States.fxp" target="_new">aqui</a>.</p>
<p>Obrigado pela visita, volte sempre!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.horochovec.com.br/blog/2010/05/13/adobe-flex-4-states/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Flex 4 Skin &#8211; BackgroundGradientColors</title>
		<link>http://www.horochovec.com.br/blog/2010/05/11/flex-4-skins-backgroundgradientcolors/</link>
		<comments>http://www.horochovec.com.br/blog/2010/05/11/flex-4-skins-backgroundgradientcolors/#comments</comments>
		<pubDate>Wed, 12 May 2010 02:15:45 +0000</pubDate>
		<dc:creator>Stefan Horochovec</dc:creator>
				<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Skin]]></category>

		<guid isPermaLink="false">http://www.horochovec.com.br/blog/?p=399</guid>
		<description><![CDATA[Olá Nesse post irei comentar um pouco sobre a utilização de background com um gradiente de cores. No Flex 3 era possível essa implementação através de uma propriedade chamada backgroundGradientColors, que estava disponível nos estilos do objeto Application e que agora, na versão 4 do Flex é necessário a implementação de um Skin para que [...]]]></description>
			<content:encoded><![CDATA[<div align="justify">Olá</p>
<p>Nesse post irei comentar um pouco sobre a utilização de background com um gradiente de cores. No Flex 3 era possível essa implementação através de uma propriedade chamada <em><strong>backgroundGradientColors</strong></em>, que estava disponível nos estilos do objeto <em><strong>Application</strong></em> e que agora, na versão 4 do Flex é necessário a implementação de um Skin para  que possamos aplicar o gradiente ao background da aplicação.<br />
<span id="more-399"></span><br />
O SDK do Adobe Flex 4 mudou muito com relação ao Adobe Flex 3. Uma das grandes mudanças é o uso extensivo de Skins para construção de nossos componentes e aplicações.</p>
<p>A grosso modo pode-se avaliar essas modificações de uma forma negativa, uma vez que a curva de aprendizado se tornou maior com relação ao Flex 3, entretanto essa forma mais robusta de implementação desses recursos nos permite mais flexibilidade e novas possibilidades em nossas implementações.</p>
<p>Ao se deparar com o novo Flex SDK, o desenvolvedor logo percebe que houve um aumento significativo de propriedades no agrupador &#8220;<strong>Styles</strong>&#8221; em seu Flex Properties, porém, mesmo com esse aumento algumas propriedades deixaram de existir. </p>
<p>Hoje falaremos do &#8220;<strong>BackgroundGradientColors</strong>&#8220;. Uma propriedade que nos permitia passar um array de cores para a aplicação e a mesma aplicava como background um gradiente de cores entre as informadas.</p>
<p>Para demonstrar essa situação, iremos criar um novo &#8220;<strong>Flex Project</strong>&#8221; em nosso Flash Builder chamado <strong>BackgroundGradientColor</strong> conforme imagem abaixo: </p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/01.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/01.jpg" alt="" title="" width="494" height="642" class="aligncenter size-full wp-image-403" /></a></p>
<p>Após criado, iremos adicionar um &#8220;<strong>MXML Skin</strong>&#8221; em nossa aplicação. Para isso, vá ao menu File, New, MXML Skin, e irá abrir uma tela para criação do arquivo. Nessa tela, iremos configurar o <strong>Name</strong> e o <strong>Host Component</strong> de nosso Skin, conforme demonstrado abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/02.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/02.jpg" alt="" title="" width="525" height="500" class="aligncenter size-full wp-image-405" /></a></p>
<p>Algumas considerações sobre a criação de um Skin que acabamos de fazer. O nome informado é o nome que a classe Skin irá receber em nosso projeto. A <em>metadata</em> <strong>HostComponent</strong> é utilizada para informar ao Skin qual componente do SDK fará sua implementação. Ao informar a metadata e sair do campo, o campo &#8220;<strong>create a copy of</strong>&#8221; será preenchido automaticamente, com a classe utilizada pelo componente informado no <strong>HostComponent</strong>.</p>
<p>Após abrir o arquivo criado, iremos ver que ele possui todas as informações sobre o desenho e cores do componente <strong>spark.components.Application</strong>. Podemos perceber também que existe um grande uso de States.</p>
<p>Iremos procurar o seguinte bloco de código dentro do ApplicationSkin.mxml. Ele deverá estar na linha<br />
47.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=399&amp;download=ApplicationSkin.mxml">ApplicationSkin.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p39916"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p399code16"><pre class="actionscript" style="font-family:monospace;">    <span style="color: #66cc66;">&lt;</span>s:Rect id=<span style="color: #ff0000;">&quot;backgroundRect&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #0066CC;">right</span>=<span style="color: #ff0000;">&quot;0&quot;</span> top=<span style="color: #ff0000;">&quot;0&quot;</span> bottom=<span style="color: #ff0000;">&quot;0&quot;</span>  <span style="color: #66cc66;">&gt;</span>
        <span style="color: #66cc66;">&lt;</span>s:fill<span style="color: #66cc66;">&gt;</span>
            <span style="color: #66cc66;">&lt;!</span>--- <span style="color: #66cc66;">@</span><span style="color: #0066CC;">private</span> --<span style="color: #66cc66;">&gt;</span>
            <span style="color: #66cc66;">&lt;</span>s:SolidColor id=<span style="color: #ff0000;">&quot;bgRectFill&quot;</span> <span style="color: #0066CC;">color</span>=<span style="color: #ff0000;">&quot;#FFFFFF&quot;</span><span style="color: #66cc66;">/&gt;</span>
        <span style="color: #66cc66;">&lt;/</span>s:fill<span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;/</span>s:Rect<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Iremos fazer nossas alterações nesse bloco de códigos, que contém o retângulo que cobre toda a área de nossa aplicação.</p>
<p>Podemos perceber que que dentro do retângulo existe um objeto <strong>SolidColor</strong> que contem a cor inicial de nosso Application. Esse objeto será removido para adicionarmos o objeto <strong>LinearGradient</strong> do pacote <strong>mx.graphics.*</strong>. E para definição das cores do gradiente, usamos objetos <strong>GradientEntry</strong> que irão conter as cores do gradiente a ser aplicado, conforme abaixo:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=399&amp;download=ApplicationSkin.mxml">ApplicationSkin.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p39917"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p399code17"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>s:Rect id=<span style="color: #ff0000;">&quot;backgroundRect&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #0066CC;">right</span>=<span style="color: #ff0000;">&quot;0&quot;</span> top=<span style="color: #ff0000;">&quot;0&quot;</span> bottom=<span style="color: #ff0000;">&quot;0&quot;</span>  <span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>s:fill<span style="color: #66cc66;">&gt;</span>
        <span style="color: #66cc66;">&lt;!</span>--- <span style="color: #66cc66;">@</span><span style="color: #0066CC;">private</span> --<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:LinearGradient rotation=<span style="color: #ff0000;">&quot;90&quot;</span><span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>s:GradientEntry <span style="color: #0066CC;">color</span>=<span style="color: #ff0000;">&quot;#000000&quot;</span> <span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;</span>s:GradientEntry <span style="color: #0066CC;">color</span>=<span style="color: #ff0000;">&quot;#999999&quot;</span> <span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;/</span>s:LinearGradient<span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;/</span>s:fill<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>s:Rect<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Após isso, podemos voltar a nossa aplicação principal e iremos adicionar a propriedade skinClass a classe correspondente ao skin da nossa aplicação, conforme abaixo:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=399&amp;download=BackgroundGradientColor.mxml">BackgroundGradientColor.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p39918"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p399code18"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> 
			   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> 
			   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span>
			   skinClass=<span style="color: #ff0000;">&quot;ApplicationSkin&quot;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;!</span>-- Place non-visual elements <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">g</span>., services, value objects<span style="color: #66cc66;">&#41;</span> here --<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Após essa alteração, entraremos em modo de &#8220;<strong>Design</strong>&#8221; e já podemos ver no próprio Flash Builder a implementação do Skin pela nossa aplicação conforme imagem abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/03.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/05/03.jpg" alt="" title="" width="500" height="328" class="aligncenter size-full wp-image-414" /></a></p>
<p>A possibilidade de trabalhar com Skin abre ainda mais as portas para a criatividade dentro do Flex 4 SDK. Agora, fica por nossa conta a criatividade para uma melhor exploração de layouts, cores e formas em nossas aplicações.</p>
<p>Fonte do exemplo? Clique <a href="http://www.horochovec.com.br/blog/BackgroundGradientColor.fxp" target="_new">aqui</a>.</p>
<p>Um abraço, até a próxima!</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.horochovec.com.br/blog/2010/05/11/flex-4-skins-backgroundgradientcolors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex 4 + BlazeDS 4 + Java + DataWizards</title>
		<link>http://www.horochovec.com.br/blog/2010/03/24/flex-4-blazeds-4-java-datawizards/</link>
		<comments>http://www.horochovec.com.br/blog/2010/03/24/flex-4-blazeds-4-java-datawizards/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 02:55:54 +0000</pubDate>
		<dc:creator>Stefan Horochovec</dc:creator>
				<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[DataWizards]]></category>
		<category><![CDATA[Flash Builder]]></category>

		<guid isPermaLink="false">http://www.horochovec.com.br/blog/?p=340</guid>
		<description><![CDATA[Olá pessoal A grande sensação ontem (23/03) foi a publicação pelo guru Christophe Coenraets demonstrando um vídeo aonde através do Flash Builder ele consumiu recursos de um projeto Java sem codificação no ambiente Flex. Nesse artigo vou demonstrar como trabalhar com esse recurso passo-a-passo. Bom, primeiro passo é você ter em seu computador todas as [...]]]></description>
			<content:encoded><![CDATA[<p>Olá pessoal</p>
<p>A grande sensação ontem (23/03) foi a publicação pelo guru <a href="http://coenraets.org/blog/2010/03/video-using-the-flash-builder-4-data-wizards-with-blazeds-4/" target="_new">Christophe Coenraets</a> demonstrando um vídeo aonde através do Flash Builder ele consumiu recursos de um projeto Java sem codificação no ambiente Flex. Nesse artigo vou demonstrar como trabalhar com esse recurso passo-a-passo.</p>
<p><span id="more-340"></span></p>
<p>Bom, primeiro passo é você ter em seu computador todas as ferramentas necessárias. Neste caso, você irá utilizar o <a href="http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/galileo/SR2/eclipse-jee-galileo-SR2-win32.zip" target="_new">Eclipse Galileu JEE</a>, <a href="http://www.adobe.com/products/flashbuilder/" target="_new">Flash Builder (stand-alone ou plugin)</a> e do <a href="http://flexorg.wip3.adobe.com/blazeds/trunk/14910/blazeds-bin-4.0.0.14910.zip" target="_new">BlazeDS 4 Beta</a>.</p>
<p>A aplicação que desenvolveremos nesse tutorial é a mesma desenvolvida no post anterior, com a diferença que aonde foi feito codificação manual no ambiente Flex, agora, iremos utilizar o Flash Builder para a geração do código fonte.</p>
<p>Bom, no Eclipse Galileo para iniciar um projeto, eu escolhi a opção <em>File -&gt; New -&gt; Web -&gt; Dynamic Web Project</em>, conforme abaixo:</p>
<p style="text-align: center;"><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/31.jpg"><img class="size-full wp-image-283  aligncenter" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/31.jpg" alt="" width="543" height="526" /></a></p>
<p>E depois configurei o projeto da seguinte maneira:</p>
<p style="text-align: center;"><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/4.jpg"><img class="size-full wp-image-284  aligncenter" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/4.jpg" alt="" width="541" height="720" /></a></p>
<p style="text-align: center;"><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/5.jpg"><img class="size-full wp-image-285  aligncenter" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/5.jpg" alt="" width="565" height="410" /></a></p>
<p style="text-align: center;"><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/61.jpg"><img class="size-full wp-image-287  aligncenter" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/61.jpg" alt="" width="565" height="410" /></a></p>
<p>Bom, depois de configurar o projeto, iremos criar um Bean para serializarmos algumas informações que serão enviadas para o Flex. A idéia é bastante simples, irei criar um model para uma simples agenda de contato.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=340&amp;download=Contato.java">Contato.java</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p34028"><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
</pre></td><td class="code" id="p340code28"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">br.com.horochovec.model</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.Serializable</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Modelo para agenda de contato
 * @author Stefan Horochovec 
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Contato <span style="color: #000000; font-weight: bold;">implements</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aserializable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Serializable</span></a> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 *
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> nome<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> email<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getNome<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> nome<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setNome<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> nome<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">nome</span> <span style="color: #339933;">=</span> nome<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getEmail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> email<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setEmail<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> email<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">email</span> <span style="color: #339933;">=</span> email<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>E em seguida, criarei um serviço que irá adicionar em um ArrayList os contatos que serão enviados do Flex para o Java.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=340&amp;download=ContatoService.java">ContatoService.java</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p34029"><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
</pre></td><td class="code" id="p340code29"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">br.com.horochovec.service</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">br.com.horochovec.model.Contato</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Serviço para manutenção dos contatos
 * @author Stefan Horochovec 
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ContatoService <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aarraylist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ArrayList</span></a> listContato <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aarraylist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ArrayList</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Adiciona um contato a lista
	 * @param contato
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addContato<span style="color: #009900;">&#40;</span>Contato contato<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		listContato.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>contato<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Retorna a lista de contatos
	 * @return
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aarraylist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ArrayList</span></a> getListContato<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> listContato<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Após isso, já temos uma simples aplicação pronta para trabalhar com o Flex, basta apenas configurar os arquivos .XML para que o BlazeDS possa funcionar.</p>
<p>A partir de agora é necessário que você já tenha descompactado o arquivo blazeds-bin-4.0.0.14910.zip. Após descompactá-lo, você terá que descompactar o arquivo blazeds.war que surgiu da descompactação anterior. Como resultado, obterá o seguinte:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/19.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/19.jpg" alt="" title="19" width="540" height="204" class="aligncenter size-full wp-image-348" /></a></p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/20.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/20.jpg" alt="" title="20" width="546" height="285" class="aligncenter size-full wp-image-349" /></a></p>
<p>Bom, podemos copiar para o diretório <em>WebContent/WEB-INF</em> de nosso projeto Java, os diretórios: <em>flex/</em>, <em>lib/</em>, <em>spring/</em> e os arquivos: <em>flex-servlet.xml</em> e <em>web.xml</em>. Após copiar esse conteúdo, o primeiro arquivo que iremos configurar, é o arquivo web.xml que fica dentro da pasta <em>WebContent/WEB-INF/</em>. </p>
<p>Para essa configuração, iremos alterar o conteúdo do arquivo web.xml que veio dentro do arquivo blazeds.war que foi previamente descompactado. </p>
<p>Perceba que os parametros da aplicação foram alterados e também foi alterado o valor da propriedade <em>useAppserverSecurity </em>para <em>false</em>. O resultado será:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=340&amp;download=web.xml">web.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p34030"><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
85
86
87
88
89
90
91
92
93
94
95
96
97
</pre></td><td class="code" id="p340code30"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE web-app PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot; &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>FlexDuck<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>FlexDuck<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- Http Flex Session attribute and binding listener support --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>flex.messaging.HttpFlexSession<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- MessageBroker Servlet --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>MessageBrokerServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>MessageBrokerServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>flex.messaging.MessageBrokerServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>services.configuration.file<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/WEB-INF/flex/services-config.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>RDSDispatchServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>RDSDispatchServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>flex.rds.server.servlet.FrontEndServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>useAppserverSecurity<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>        
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>10<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;RDS_DISPATCH_MAPPING&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>RDSDispatchServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/CFIDE/main/ide.cfm<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>MessageBrokerServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/messagebroker/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>index.html<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>index.htm<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- for WebSphere deployment, please uncomment --&gt;</span>
    <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">    &lt;resource-ref&gt;</span>
<span style="color: #808080; font-style: italic;">        &lt;description&gt;Flex Messaging WorkManager&lt;/description&gt;</span>
<span style="color: #808080; font-style: italic;">        &lt;res-ref-name&gt;wm/MessagingWorkManager&lt;/res-ref-name&gt;</span>
<span style="color: #808080; font-style: italic;">        &lt;res-type&gt;com.ibm.websphere.asynchbeans.WorkManager&lt;/res-type&gt;</span>
<span style="color: #808080; font-style: italic;">        &lt;res-auth&gt;Container&lt;/res-auth&gt;</span>
<span style="color: #808080; font-style: italic;">        &lt;res-sharing-scope&gt;Shareable&lt;/res-sharing-scope&gt;</span>
<span style="color: #808080; font-style: italic;">    &lt;/resource-ref&gt;</span>
<span style="color: #808080; font-style: italic;">    --&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">	&lt;context-param&gt;</span>
<span style="color: #808080; font-style: italic;">		&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;</span>
<span style="color: #808080; font-style: italic;">		&lt;param-value&gt;</span>
<span style="color: #808080; font-style: italic;">			/WEB-INF/spring/*-config.xml</span>
<span style="color: #808080; font-style: italic;">		&lt;/param-value&gt;</span>
<span style="color: #808080; font-style: italic;">	&lt;/context-param&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">    &lt;filter&gt;</span>
<span style="color: #808080; font-style: italic;">        &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;</span>
<span style="color: #808080; font-style: italic;">        &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;</span>
<span style="color: #808080; font-style: italic;">    &lt;/filter&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">    &lt;filter-mapping&gt;</span>
<span style="color: #808080; font-style: italic;">      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;</span>
<span style="color: #808080; font-style: italic;">      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;</span>
<span style="color: #808080; font-style: italic;">    &lt;/filter-mapping&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">	&lt;listener&gt;</span>
<span style="color: #808080; font-style: italic;">		&lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;</span>
<span style="color: #808080; font-style: italic;">	&lt;/listener&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">	&lt;servlet&gt;</span>
<span style="color: #808080; font-style: italic;">		&lt;servlet-name&gt;flex&lt;/servlet-name&gt;</span>
<span style="color: #808080; font-style: italic;">		&lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;</span>
<span style="color: #808080; font-style: italic;">		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;</span>
<span style="color: #808080; font-style: italic;">	&lt;/servlet&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">	&lt;servlet-mapping&gt;</span>
<span style="color: #808080; font-style: italic;">    	&lt;servlet-name&gt;flex&lt;/servlet-name&gt;</span>
<span style="color: #808080; font-style: italic;">    	&lt;url-pattern&gt;/messagebroker/*&lt;/url-pattern&gt;</span>
<span style="color: #808080; font-style: italic;"> 	&lt;/servlet-mapping&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">--&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Feito isso, iremos adicionar dentro da pasta <em>WebContent</em> a pasta <em>flex</em> que foi previamente descompactada do arquivo <em>blazeds.war</em>, e também todo o conteúdo da pasta lib para dentro do diretório <em>WebContent/WEB-INF/lib</em> , obtendo o seguinte resultado:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/21.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/21.jpg" alt="" title="21" width="401" height="412" class="aligncenter size-full wp-image-352" /></a></p>
<p>Feito isso, iremos configurar o único arquivo .xml do BlazeDS para que esse exemplo funcione. O arquivo WEB-INF/flex/remoting-config.xml. Iremos adicionar uma configuração para informar ao BlazeDS sobre o serviço ContatoService que foi criado anteriormente, conforme abaixo:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=340&amp;download=remoting-config.xml">remoting-config.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p34031"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p340code31"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;remoting-service&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;flex.messaging.services.RemotingService&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;adapters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;adapter-definition</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;java-object&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;flex.messaging.services.remoting.adapters.JavaAdapter&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/adapters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default-channels<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;my-amf&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/default-channels<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;destination</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;ContatoService&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>br.com.horochovec.service.ContatoService<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/destination<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Após essa última configuração, podemos exportar o nosso projeto para um servidor web. Nesse caso, utilizaremos o <a href="http://tomcat.apache.org/" target="_new">Tomcat 6.x</a>. Neste artigo não entrarei em detalhes de sua instalação e configuração.</p>
<p>Bom, as configurações no projeto Java já foram finalizadas, e considerando que o deploy da aplicação dentro do Tomcat já foi realizado, a partir deste momento iremos trabalhar diretamente com o Flash Builder. </p>
<p>Neste artigo irei demonstrar a comunicação utilizando o Flash Builder e a versão do Flex 4. Você pode fazer o download da versão 4.0 do Flash Builder e do Flex 4 SDK <a href="http://www.adobe.com/products/flashbuilder/" target="_new">aqui</a>.</p>
<p>Após instalado e iniciado o Flash Builder, iremos criar um projeto no seguinte molde:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/11.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/11.jpg" alt="" title="" width="450" height="459" class="aligncenter size-full wp-image-308" /></a></p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/12.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/12.jpg" alt="" title="" width="450" height="325" class="aligncenter size-full wp-image-309" /></a></p>
<p>As configurações feitas na segunda tela de configuração são bastante importantes. Fazendo elas da forma correta, você estará apto a iniciar o projeto sem fazer novas configurações. </p>
<p>Na primeira linha, em <strong>Root Folder</strong>, foi apontado o diretório de deploy da minha aplicação dentro do meu servidor de aplicação.</p>
<p>Na segunda linha, em <strong>Root URL</strong>, foi apontado o caminho da URL para abertura da aplicação em meu navegador de internet.</p>
<p>Na terceira linha, em <strong>ContextRoot</strong>, apontamos o nome da nossa aplicação.</p>
<p>Na quarta e ultima linha, em <strong>Output folder</strong>, apontamos o diretório de onde deve ser exportados os arquivos quando compilados. Para esse tutorial, foi apontado diretamente o diretório de minha aplicação dentro do meu servidor Tomcat.</p>
<p>Como resultado, o Flash Builder irá criar e disponibilizar no workspace um projeto da seguinte forma:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/13.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/13.jpg" alt="" title="" width="495" height="305" class="aligncenter size-full wp-image-312" /></a></p>
<p>É muito importante fazer a conferência de uma configuração gerada automaticamente pelo Flash Builder em cima dos parametros informados na segunda etapa da criação do projeto. No menu &#8216;Project&#8217; vá na opção &#8216;Properties&#8217; e confira as propriedades de acordo com a imagem abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/14.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/14.jpg" alt="" title="14" width="540" height="433" class="aligncenter size-full wp-image-314" /></a></p>
<p>Iremos criar uma tela no Flash Builder que contenha dois campos text input para preencher as informações do nome e email do contato, e também um grid para conter a lista dos contatos que serão adicionados no Java e retornarão ao Flex através do BlazeDS.</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/301.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/301.jpg" alt="" title="30" width="465" height="485" class="aligncenter size-full wp-image-377" /></a></p>
<p>Segue sua implementação</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=340&amp;download=FlexDuck.mxml">FlexDuck.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p34032"><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
</pre></td><td class="code" id="p340code32"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> 
			   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> 
			   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;419&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
&nbsp;
	<span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
&nbsp;
&nbsp;
	<span style="color: #66cc66;">&lt;</span>s:Panel <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;137&quot;</span> title=<span style="color: #ff0000;">&quot;Cadastro&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span> top=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;/</span>s:Panel<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>s:Panel x=<span style="color: #ff0000;">&quot;12&quot;</span> y=<span style="color: #ff0000;">&quot;166&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;227&quot;</span> title=<span style="color: #ff0000;">&quot;Pesquisa&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:DataGrid x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span> bottom=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #0066CC;">right</span>=<span style="color: #ff0000;">&quot;5&quot;</span> top=<span style="color: #ff0000;">&quot;5&quot;</span> id=<span style="color: #ff0000;">&quot;grid&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;/</span>mx:DataGrid<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> x=<span style="color: #ff0000;">&quot;-1&quot;</span> y=<span style="color: #ff0000;">&quot;163&quot;</span> label=<span style="color: #ff0000;">&quot;Listar todos&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;5&quot;</span> bottom=<span style="color: #ff0000;">&quot;5&quot;</span> id=<span style="color: #ff0000;">&quot;button&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>s:Panel<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>A partir deste momento, usaremos os recursos de Data/Services presentes no Flash Builder 4 para a geração da comunicação com o Java.</p>
<p>Primeiro, iremos conectar o Flash Builder com o BlazeDS. Para isso, na aba &#8220;Data/Services&#8221; clique na opção &#8220;Connect to Data/Service&#8221;. Caso ela não esteja disponivel em seu workspace, vá ao menu &#8220;Window&#8221; e marque a opção &#8220;Data/Services&#8221;.</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/22.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/22.jpg" alt="" title="22" width="429" height="165" class="aligncenter size-full wp-image-358" /></a></p>
<p>Feito isso, na próxima tela, marque a opção &#8220;BlazeDS&#8221;, clique em Next e marque a opção para não utilizar controle de acesso. Conforme as telas abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/231.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/231.jpg" alt="" title="23" width="500" height="371" class="aligncenter size-full wp-image-363" /></a></p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/24.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/24.jpg" alt="" title="24" width="549" height="275" class="aligncenter size-full wp-image-360" /></a></p>
<p>Na última tela, você deve marcar os serviços que deseja adicionar a aplicação, com opção de definição de endereços de pacotes e depois finalizar a criação do Objeto, conforme:<br />
<a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/25.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/25.jpg" alt="" title="25" width="532" height="457" class="aligncenter size-full wp-image-364" /></a></p>
<p>Após finalizar a configuração do serviço remoto, obtemos o seguinte resultado no Flash Builder.</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/311.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/311.jpg" alt="" title="31" width="429" height="151" class="aligncenter size-full wp-image-373" /></a></p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/32.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/32.jpg" alt="" title="32" width="327" height="328" class="aligncenter size-full wp-image-374" /></a></p>
<p>Agora, iremos definir que no momento do click no botão logo abaixo do DataGrid, a aplicação deverá invocar o método getListContato().</p>
<p>O primeiro passo para isso, é clicar com o botão direito sobre o botão com do painel que contem o DataGrid e marcar a opção &#8220;<em>Generate Service Call</em>&#8220;. Feito isso configure a tela do serviço conforme apresentado abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/33.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/33.jpg" alt="" title="33" width="465" height="485" class="aligncenter size-full wp-image-379" /></a></p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/34.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/34.jpg" alt="" title="34" width="465" height="278" class="aligncenter size-full wp-image-381" /></a></p>
<p>Feito isso, selecione o DataGrid e clicando com o botão direito dentro dele, selecione a opção &#8220;<em>Bind to Data</em>&#8221; e configure a tela conforme informado abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/35.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/35.jpg" alt="" title="35" width="465" height="404" class="aligncenter size-full wp-image-383" /></a></p>
<p>Nesse momento, o painel responsável por listar as informações da nossa agenda de contato já está finalizado.</p>
<p>Agora, clicando novamente com o botão direito em cima do DataGrid, clique na opção &#8220;<em>Generate Details Form</em>&#8221; e configure a tela conforme abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/36.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/36.jpg" alt="" title="36" width="537" height="511" class="aligncenter size-full wp-image-384" /></a></p>
<p>O formulário gerado será adicionado no mesmo container que estiver o DataGrid, portanto, será necessário reposicioná-lo dentro do <em>Panel</em> já criado, conforme imagem abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/37.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/37.jpg" alt="" title="37" width="537" height="511" class="aligncenter size-full wp-image-385" /></a></p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/38.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/38.jpg" alt="" title="38" width="537" height="511" class="aligncenter size-full wp-image-386" /></a></p>
<p>Ok, agora basta configurarmos o clique do botão de salvar para que adicione novos contatos. </p>
<p>O primeiro passo é alterar o label do botão para &#8220;<em>Cadastrar</em>&#8220;.</p>
<p>O segundo passo é clicar com o botão direito sobre o botão de cadastro e selecionar a opção &#8220;Generate Service Call&#8221; e configure a opção da seguinte forma:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/39.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/39.jpg" alt="" title="39" width="537" height="511" class="aligncenter size-full wp-image-388" /></a></p>
<p>Ao terminar essa configuração, você será direcionado diretamente para a implementação do click do botão com a chamada do serviço remoto. A implementação gerada do método será a seguinte:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=340&amp;download=FlexDuck.mxml">FlexDuck.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p34033"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p340code33"><pre class="actionscript" style="font-family:monospace;">protected <span style="color: #000000; font-weight: bold;">function</span> button2_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	contato.<span style="color: #006600;">email</span> = emailTextInput.<span style="color: #0066CC;">text</span>;
	contato.<span style="color: #006600;">nome</span> = nomeTextInput.<span style="color: #0066CC;">text</span>;
	addContatoResult.<span style="color: #006600;">token</span> = contatoService.<span style="color: #006600;">addContato</span><span style="color: #66cc66;">&#40;</span><span style="color: #808080; font-style: italic;">/*Enter value(s) for */</span> arg0<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>E você deverá fazer a seguinte alteração. Adicionar o parametro a ser enviado no método addContato() e inicializar o objeto contato, da seguinte forma:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=340&amp;download=FlexDuck.mxml">FlexDuck.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p34034"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p340code34"><pre class="actionscript" style="font-family:monospace;">protected <span style="color: #000000; font-weight: bold;">function</span> button2_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	contato = <span style="color: #000000; font-weight: bold;">new</span> Contato<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	contato.<span style="color: #006600;">email</span> = emailTextInput.<span style="color: #0066CC;">text</span>;
	contato.<span style="color: #006600;">nome</span> = nomeTextInput.<span style="color: #0066CC;">text</span>;
	addContatoResult.<span style="color: #006600;">token</span> = contatoService.<span style="color: #006600;">addContato</span><span style="color: #66cc66;">&#40;</span>contato<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Com isso, nosso projeto estará enviado as informações para o Java. Agora, para finalizar, iremos adicionar um evento para disparar um método quando tivermos o resultado do serviço remoto.</p>
<p>No <em>CallResponder</em> com o id &#8220;<em>addContatoResult</em>&#8221; pressione o CTRL + SPACE para acionar o code complete e acione o event &#8220;<em>result</em>&#8220;, e em seguida, solicite para que seja adicionado o <em>ResultHandler</em> para o event adicionado, conforme imagens abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/40.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/40.jpg" alt="" title="40" width="537" height="322" class="aligncenter size-full wp-image-391" /></a></p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/41.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/41.jpg" alt="" title="41" width="537" height="322" class="aligncenter size-full wp-image-392" /></a></p>
<p>E na função adicionada no código devemos fazer a seguinte implementação:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=340&amp;download=FlexDuck.mxml">FlexDuck.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p34035"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p340code35"><pre class="actionscript" style="font-family:monospace;">protected <span style="color: #000000; font-weight: bold;">function</span> addContatoResult_resultHandler<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	contato = <span style="color: #000000; font-weight: bold;">new</span> Contato<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	getListContatoResult.<span style="color: #006600;">token</span> = contatoService.<span style="color: #006600;">getListContato</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Rodando a aplicação, teremos como resultado no navegador o seguinte:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/42.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/42.jpg" alt="" title="" width="418" height="410" class="aligncenter size-full wp-image-394" /></a></p>
<p>E como resultado final no código fonte:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=340&amp;download=FlexDuck.mxml">FlexDuck.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p34036"><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
</pre></td><td class="code" id="p340code36"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> 
			   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> 
			   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;419&quot;</span> xmlns:services=<span style="color: #ff0000;">&quot;services.*&quot;</span> xmlns:valueObjects=<span style="color: #ff0000;">&quot;valueObjects.*&quot;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
			<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Alert</span>;
			<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ResultEvent</span>;
&nbsp;
			protected <span style="color: #000000; font-weight: bold;">function</span> button_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
			<span style="color: #66cc66;">&#123;</span>
				getListContatoResult.<span style="color: #006600;">token</span> = contatoService.<span style="color: #006600;">getListContato</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
			protected <span style="color: #000000; font-weight: bold;">function</span> button2_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> contato : Contato = <span style="color: #000000; font-weight: bold;">new</span> Contato<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				contato.<span style="color: #006600;">email</span> = emailTextInput.<span style="color: #0066CC;">text</span>;
				contato.<span style="color: #006600;">nome</span> = nomeTextInput.<span style="color: #0066CC;">text</span>;
				addContatoResult.<span style="color: #006600;">token</span> = contatoService.<span style="color: #006600;">addContato</span><span style="color: #66cc66;">&#40;</span>contato<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
			protected <span style="color: #000000; font-weight: bold;">function</span> addContatoResult_resultHandler<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
			<span style="color: #66cc66;">&#123;</span>
				contato = <span style="color: #000000; font-weight: bold;">new</span> Contato<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				getListContatoResult.<span style="color: #006600;">token</span> = contatoService.<span style="color: #006600;">getListContato</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span>
&nbsp;
&nbsp;
	<span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:CallResponder id=<span style="color: #ff0000;">&quot;getListContatoResult&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>services:ContatoService id=<span style="color: #ff0000;">&quot;contatoService&quot;</span> fault=<span style="color: #ff0000;">&quot;Alert.show(event.fault.faultString + '<span style="color: #000099; font-weight: bold;">\n</span>' + event.fault.faultDetail)&quot;</span> showBusyCursor=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>valueObjects:Contato id=<span style="color: #ff0000;">&quot;contato&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:CallResponder id=<span style="color: #ff0000;">&quot;addContatoResult&quot;</span> result=<span style="color: #ff0000;">&quot;addContatoResult_resultHandler(event)&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>fx:Binding source=<span style="color: #ff0000;">&quot;grid.selectedItem as Contato&quot;</span> destination=<span style="color: #ff0000;">&quot;contato&quot;</span><span style="color: #66cc66;">/&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>s:Panel <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;137&quot;</span> title=<span style="color: #ff0000;">&quot;Cadastro&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span> top=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:Form defaultButton=<span style="color: #ff0000;">&quot;{button2}&quot;</span> x=<span style="color: #ff0000;">&quot;1&quot;</span> y=<span style="color: #ff0000;">&quot;-4&quot;</span> bottom=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #0066CC;">right</span>=<span style="color: #ff0000;">&quot;0&quot;</span> top=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Email&quot;</span><span style="color: #66cc66;">&gt;</span>
				<span style="color: #66cc66;">&lt;</span>s:TextInput id=<span style="color: #ff0000;">&quot;emailTextInput&quot;</span> <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;{contato.email}&quot;</span><span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Nome&quot;</span><span style="color: #66cc66;">&gt;</span>
				<span style="color: #66cc66;">&lt;</span>s:TextInput id=<span style="color: #ff0000;">&quot;nomeTextInput&quot;</span> <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;{contato.nome}&quot;</span><span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> id=<span style="color: #ff0000;">&quot;button2&quot;</span> label=<span style="color: #ff0000;">&quot;Cadastrar&quot;</span> click=<span style="color: #ff0000;">&quot;button2_clickHandler(event)&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;/</span>mx:Form<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;/</span>s:Panel<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>s:Panel x=<span style="color: #ff0000;">&quot;12&quot;</span> y=<span style="color: #ff0000;">&quot;166&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;227&quot;</span> title=<span style="color: #ff0000;">&quot;Pesquisa&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:DataGrid x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span> bottom=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #0066CC;">right</span>=<span style="color: #ff0000;">&quot;5&quot;</span> top=<span style="color: #ff0000;">&quot;5&quot;</span> id=<span style="color: #ff0000;">&quot;grid&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{getListContatoResult.lastResult}&quot;</span><span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>mx:columns<span style="color: #66cc66;">&gt;</span>
				<span style="color: #66cc66;">&lt;</span>mx:DataGridColumn headerText=<span style="color: #ff0000;">&quot;email&quot;</span> dataField=<span style="color: #ff0000;">&quot;email&quot;</span><span style="color: #66cc66;">/&gt;</span>
				<span style="color: #66cc66;">&lt;</span>mx:DataGridColumn headerText=<span style="color: #ff0000;">&quot;nome&quot;</span> dataField=<span style="color: #ff0000;">&quot;nome&quot;</span><span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;/</span>mx:columns<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;/</span>mx:DataGrid<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> x=<span style="color: #ff0000;">&quot;-1&quot;</span> y=<span style="color: #ff0000;">&quot;163&quot;</span> label=<span style="color: #ff0000;">&quot;Listar todos&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;5&quot;</span> bottom=<span style="color: #ff0000;">&quot;5&quot;</span> id=<span style="color: #ff0000;">&quot;button&quot;</span> click=<span style="color: #ff0000;">&quot;button_clickHandler(event)&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>s:Panel<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Para fazer o download do projeto clique <a href="http://www.horochovec.com.br/blog/FlexDuck20100324.zip" target="_new">aqui</a>.</p>
<p>Espero ter ajudado, um abraço <img src='http://www.horochovec.com.br/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.horochovec.com.br/blog/2010/03/24/flex-4-blazeds-4-java-datawizards/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Flash Builder + Flex SDK 4 + Java + BlazeDS &#8211; Tutorial</title>
		<link>http://www.horochovec.com.br/blog/2010/03/23/flash-builder-flex-sdk-4-java-blazeds-tutorial/</link>
		<comments>http://www.horochovec.com.br/blog/2010/03/23/flash-builder-flex-sdk-4-java-blazeds-tutorial/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 16:20:57 +0000</pubDate>
		<dc:creator>Stefan Horochovec</dc:creator>
				<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flash Builder 4]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Flex SDK 4]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.horochovec.com.br/blog/?p=273</guid>
		<description><![CDATA[Olá pessoal! Depois de alguns dias sem postar nada no blog, vou atender ao pedido de alguns colegas que fizeram um curso de Scrum a uns dias atrás e postar algo no blog sobre como começar um projeto com Java e Flex, como faço para &#8220;instalar&#8221; o BlazeDS e fazer minha primeira comunicação. If you [...]]]></description>
			<content:encoded><![CDATA[<p>Olá pessoal!</p>
<p>Depois de alguns dias sem postar nada no blog, vou atender ao pedido de alguns colegas que fizeram um curso de Scrum a uns dias atrás e postar algo no blog sobre como começar um projeto com Java e Flex, como faço para &#8220;instalar&#8221; o BlazeDS e fazer minha primeira comunicação.</p>
<p>If you want to see this post in english, click <a href="http://www.horochovec.com/2010/03/29/flash-builder-flex-sdk-4-java-blazeds-tutorial/">here</a>.</p>
<p><span id="more-273"></span></p>
<p>Para quem está iniciando no desenvolvimento Flex com Java como back-end e está optando por trabalhar com Remote Objects precisa trabalhar com algo que faça a comunicação entre Flex e Java.</p>
<p>Existem diversas opções hoje no mercado, e a própria Adobe disponibiliza dois produtos para isso.  O objetivo desse tutorial é exemplificar o uso do BlazeDS para essa comunicação.</p>
<p>O BlazeDS é uma ferramenta open-source, e hoje é amplamente utilizada para a comunicação Java &#8211; Flex. Tem como objetivo prover ao desenvolvedor Flex uma forma de se comunicar com seu back-end através de <em>Remote Objects</em> ou comunicação <em>Real-Time</em> através de <em>Messages. </em></p>
<p><em> </em>Vale lembrar que o BlazeDS pode ser utilizado para comunicações de aplicações desenvolvidas em Flex para Web (Flash Player) ou para Desktop (AIR).</p>
<p>Mas como iniciar? Primeiramente, devemos fazer o download (clique <a href="http://flexorg.wip3.adobe.com/blazeds/3.0.x/milestone/3978/blazeds-bin-3.2.0.3978.zip" target="_blank">aqui</a> para o download) através do site oficial do <a href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS" target="_blank">BlazeDS</a>.</p>
<p>O download que estamos fazendo é a versão binária, contendo um arquivo .WAR que contém os arquivos .xml e os .jars necessários para a sua utilização. Também é possível fazer o download do código-fonte do BlazeDS clicando <a href="http://flexorg.wip3.adobe.com/blazeds/3.0.x/milestone/3978/blazeds-src-3.2.0.3978.zip" target="_blank">aqui</a>.</p>
<p>Após o download e sua descompactação, também é necessário descompactar o arquivo <em>blazeds.war. </em>Para isso, você poderá utilizar um descompactador como o WinRAR por exemplo. Fazendo isso, obteremos a seguinte estrutura:</p>
<p style="text-align: center;"><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/1.jpg"><img class="size-full wp-image-277  aligncenter" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/1.jpg" alt="" width="299" height="172" /></a></p>
<p>O conteúdo da pasta META-INF será desconsiderado. Levaremos em consideração apenas o conteúdo da pasta WEB-INF conforme seguinte apresentação:</p>
<p style="text-align: center;"><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/2.jpg"><img class="size-full wp-image-279  aligncenter" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/2.jpg" alt="" width="265" height="211" /></a></p>
<p>A pasta <em>classes</em> e <em>src </em>serão desconsideradas nesse tutorial também.</p>
<p>Dentro da pasta <em>flex</em>, temos os arquivos XMLs necessários para configuração em nosso projeto que será criado no Java, e na pasta <em>lib</em>, temos as bibliotecas java (*.jar) que deverão ser incorporados em nosso projeto. E o arquivo <em>web.xml</em> contém as informações necessárias para a configuração do servlet em nosso projeto.</p>
<p>Nesse artigo, o software utilizado para criação e desenvolvimento do projeto Java é Eclipse Galileu junto com o  WebTools. Você pode tranquilamente adaptar esse tutorial para qualquer IDE que você utilize em seu dia-a-dia.</p>
<p>Para iniciar um projeto, eu escolhi a opção <em>File -&gt; New -&gt; Web -&gt; Dynamic Web Project</em>, conforme abaixo:</p>
<p style="text-align: center;"><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/31.jpg"><img class="size-full wp-image-283  aligncenter" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/31.jpg" alt="" width="543" height="526" /></a></p>
<p>E depois configurei o projeto da seguinte maneira:</p>
<p style="text-align: center;"><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/4.jpg"><img class="size-full wp-image-284  aligncenter" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/4.jpg" alt="" width="541" height="720" /></a></p>
<p style="text-align: center;"><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/5.jpg"><img class="size-full wp-image-285  aligncenter" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/5.jpg" alt="" width="565" height="410" /></a></p>
<p style="text-align: center;"><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/61.jpg"><img class="size-full wp-image-287  aligncenter" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/61.jpg" alt="" width="565" height="410" /></a></p>
<p>Bom, depois de configurar o projeto, iremos criar um Bean para serializarmos algumas informações que serão enviadas para o Flex. A idéia é bastante simples, irei criar um model para uma simples agenda de contato.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=273&amp;download=Contato.java">Contato.java</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27349"><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
</pre></td><td class="code" id="p273code49"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">br.com.horochovec.model</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.Serializable</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Modelo para agenda de contato
 * @author Stefan Horochovec 
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Contato <span style="color: #000000; font-weight: bold;">implements</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aserializable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Serializable</span></a> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 *
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> nome<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> email<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getNome<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> nome<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setNome<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> nome<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">nome</span> <span style="color: #339933;">=</span> nome<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getEmail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> email<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setEmail<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> email<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">email</span> <span style="color: #339933;">=</span> email<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>E em seguida, criarei um serviço que irá adicionar em um ArrayList os contatos que serão enviados do Flex para o Java.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=273&amp;download=ContatoService.java">ContatoService.java</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27350"><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
</pre></td><td class="code" id="p273code50"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">br.com.horochovec.service</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">br.com.horochovec.model.Contato</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Serviço para manutenção dos contatos
 * @author Stefan Horochovec 
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ContatoService <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aarraylist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ArrayList</span></a> listContato <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aarraylist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ArrayList</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Adiciona um contato a lista
	 * @param contato
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addContato<span style="color: #009900;">&#40;</span>Contato contato<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		listContato.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>contato<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Retorna a lista de contatos
	 * @return
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aarraylist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ArrayList</span></a> getListContato<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> listContato<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Após isso, já temos uma simples aplicação pronta para trabalhar com o Flex, basta apenas configurar os arquivos .XML para que o BlazeDS possa funcionar.</p>
<p>O primeiro arquivo que iremos configurar, é o arquivo web.xml que fica dentro da pasta <em>WebContent/WEB-INF/</em>. Para essa configuração, iremos adicionar o conteúdo do arquivo web.xml que veio dentro do arquivo blazeds.war que foi previamente descompactado. O resultado será:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=273&amp;download=web.xml">web.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27351"><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
</pre></td><td class="code" id="p273code51"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;WebApp_ID&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.4&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/j2ee&quot;</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>FlexDuck<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>FlexDuck.html<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- Http Flex Session attribute and binding listener support --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>flex.messaging.HttpFlexSession<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- MessageBroker Servlet --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>MessageBrokerServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>flex.messaging.MessageBrokerServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>services.configuration.file<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/WEB-INF/flex/services-config.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>MessageBrokerServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/messagebroker/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Feito isso, iremos adicionar dentro da pasta <em>WebContent</em> a pasta <em>flex</em> que foi previamente descompactada do arquivo <em>blazeds.war</em>, e também todo o conteúdo da pasta lib para dentro do diretório <em>WebContent/WEB-INF/lib</em> , obtendo o seguinte resultado:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/71.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/71.jpg" alt="" title="" width="560" height="525" class="aligncenter size-full wp-image-298" /></a></p>
<p>Feito isso, iremos configurar o único arquivo .xml do BlazeDS para que esse exemplo funcione. O arquivo WEB-INF/flex/remoting-config.xml. Iremos adicionar uma configuração para informar ao BlazeDS sobre o serviço ContatoService que foi criado anteriormente, conforme abaixo:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=273&amp;download=remoting-config.xml">remoting-config.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27352"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p273code52"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;remoting-service&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;flex.messaging.services.RemotingService&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;adapters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;adapter-definition</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;java-object&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;flex.messaging.services.remoting.adapters.JavaAdapter&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/adapters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default-channels<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;my-amf&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/default-channels<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;destination</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;ContatoService&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>br.com.horochovec.service.ContatoService<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/destination<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Após essa última configuração, podemos exportar o nosso projeto para um servidor web. Nesse caso, utilizaremos o <a href="http://tomcat.apache.org/" target="_new">Tomcat 6.x</a>. Neste artigo não entrarei em detalhes de sua instalação e configuração.</p>
<p>Bom, as configurações no projeto Java já foram finalizadas, e considerando que o deploy da aplicação dentro do Tomcat já foi realizado, a partir deste momento iremos trabalhar diretamente com o Flex. </p>
<p>Neste artigo irei demonstrar a comunicação utilizando o Flash Builder e a versão do Flex 4. Você pode fazer o download da versão 4.0 do Flash Builder e do Flex 4 SDK <a href="http://www.adobe.com/products/flashbuilder/" target="_new">aqui</a>.</p>
<p>Após instalado e iniciado o Flash Builder, iremos criar um projeto no seguinte molde:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/11.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/11.jpg" alt="" title="" width="450" height="459" class="aligncenter size-full wp-image-308" /></a></p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/12.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/12.jpg" alt="" title="" width="450" height="325" class="aligncenter size-full wp-image-309" /></a></p>
<p>As configurações feitas na segunda tela de configuração são bastante importantes. Fazendo elas da forma correta, você estará apto a iniciar o projeto sem fazer novas configurações. </p>
<p>Na primeira linha, em <strong>Root Folder</strong>, foi apontado o diretório de deploy da minha aplicação dentro do meu servidor de aplicação.</p>
<p>Na segunda linha, em <strong>Root URL</strong>, foi apontado o caminho da URL para abertura da aplicação em meu navegador de internet.</p>
<p>Na terceira linha, em <strong>ContextRoot</strong>, apontamos o nome da nossa aplicação.</p>
<p>Na quarta e ultima linha, em <strong>Output folder</strong>, apontamos o diretório de onde deve ser exportados os arquivos quando compilados. Para esse tutorial, foi apontado diretamente o diretório de minha aplicação dentro do meu servidor Tomcat.</p>
<p>Como resultado, o Flash Builder irá criar e disponibilizar no workspace um projeto da seguinte forma:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/13.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/13.jpg" alt="" title="" width="495" height="305" class="aligncenter size-full wp-image-312" /></a></p>
<p>É muito importante fazer a conferência de uma configuração gerada automaticamente pelo Flash Builder em cima dos parametros informados na segunda etapa da criação do projeto. No menu &#8216;Project&#8217; vá na opção &#8216;Properties&#8217; e confira as propriedades de acordo com a imagem abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/14.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/14.jpg" alt="" title="14" width="540" height="433" class="aligncenter size-full wp-image-314" /></a></p>
<p>Após conferir essas informações, podemos iniciar o desenvolvimento do projeto no Flex.</p>
<p>Primeiramente, iremos criar o bean que será enviado para o Java e vice-versa. Esse bean será um espelho do bean criado no Java, conforme abaixo:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=273&amp;download=Contato.as">Contato.as</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27353"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p273code53"><pre class="actionscript" style="font-family:monospace;">package br.<span style="color: #006600;">com</span>.<span style="color: #006600;">horochovec</span>.<span style="color: #006600;">model</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #66cc66;">&#91;</span>RemoteClass<span style="color: #66cc66;">&#40;</span>alias=<span style="color: #ff0000;">&quot;br.com.horochovec.model.Contato&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Contato
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> nome 	: <span style="color: #0066CC;">String</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> email 	: <span style="color: #0066CC;">String</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Contato<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Em seguida, irei criar uma tela no Flash Builder que contenha dois campos text input para preencher as informações do nome e email do contato, e também um grid para conter a lista dos contatos que serão adicionados no Java e retornarão ao Flex através do BlazeDS.</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/15.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/15.jpg" alt="" title="15" width="453" height="502" class="aligncenter size-full wp-image-317" /></a></p>
<p>Segue sua implementação</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=273&amp;download=FlexDuck.mxml">FlexDuck.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27354"><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
</pre></td><td class="code" id="p273code54"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> 
			   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> 
			   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;!</span>-- Place non-visual elements <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">g</span>., services, value objects<span style="color: #66cc66;">&#41;</span> here --<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:Panel <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;137&quot;</span> title=<span style="color: #ff0000;">&quot;Cadastro&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span> top=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> x=<span style="color: #ff0000;">&quot;55&quot;</span> label=<span style="color: #ff0000;">&quot;Cadastrar&quot;</span> bottom=<span style="color: #ff0000;">&quot;10&quot;</span> id=<span style="color: #ff0000;">&quot;btnCadastro&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:Label x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;16&quot;</span> <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Nome:&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:Label x=<span style="color: #ff0000;">&quot;13&quot;</span> y=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Email:&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:TextInput x=<span style="color: #ff0000;">&quot;56&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;332&quot;</span> id=<span style="color: #ff0000;">&quot;nome&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:TextInput x=<span style="color: #ff0000;">&quot;56&quot;</span> y=<span style="color: #ff0000;">&quot;44&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;332&quot;</span> id=<span style="color: #ff0000;">&quot;email&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>s:Panel<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:Panel x=<span style="color: #ff0000;">&quot;12&quot;</span> y=<span style="color: #ff0000;">&quot;166&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;227&quot;</span> title=<span style="color: #ff0000;">&quot;Pesquisa&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:DataGrid x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span> bottom=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #0066CC;">right</span>=<span style="color: #ff0000;">&quot;5&quot;</span> top=<span style="color: #ff0000;">&quot;5&quot;</span> id=<span style="color: #ff0000;">&quot;grid&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{this.listContato}&quot;</span><span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>mx:columns<span style="color: #66cc66;">&gt;</span>
				<span style="color: #66cc66;">&lt;</span>mx:DataGridColumn headerText=<span style="color: #ff0000;">&quot;Nome&quot;</span> dataField=<span style="color: #ff0000;">&quot;nome&quot;</span><span style="color: #66cc66;">/&gt;</span>
				<span style="color: #66cc66;">&lt;</span>mx:DataGridColumn headerText=<span style="color: #ff0000;">&quot;Email&quot;</span> dataField=<span style="color: #ff0000;">&quot;email&quot;</span><span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;/</span>mx:columns<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;/</span>mx:DataGrid<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> x=<span style="color: #ff0000;">&quot;-1&quot;</span> y=<span style="color: #ff0000;">&quot;163&quot;</span> label=<span style="color: #ff0000;">&quot;Listar todos&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;5&quot;</span> bottom=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>s:Panel<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Após a construção da tela, iremos criar o serviço remoto que será responsável pela comunicação com o Java. Conforme trecho abaixo, criaremos um RemoteObject e dois métodos para serem executados pela aplicação. Definiremos também os métodos que devem ser disparados quando ocorrerem os retornos, tanto de sucesso quanto de falha na comunicação.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=273&amp;download=FlexDuck.mxml">FlexDuck.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27355"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p273code55"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:RemoteObject id=<span style="color: #ff0000;">&quot;remoteObject&quot;</span> 
					destination=<span style="color: #ff0000;">&quot;ContatoService&quot;</span> 
					fault=<span style="color: #ff0000;">&quot;onFault(event);&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:method <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;addContato&quot;</span> 
				  result=<span style="color: #ff0000;">&quot;onResultAddContatoHandler(event);&quot;</span>
				  fault=<span style="color: #ff0000;">&quot;onFault(event);&quot;</span> <span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:method <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;getListContato&quot;</span> 
				  result=<span style="color: #ff0000;">&quot;onResultGetListContatoHandler(event);&quot;</span>
				  fault=<span style="color: #ff0000;">&quot;onFault(event);&quot;</span> <span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>s:RemoteObject<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Feito isso, faremos a implementação dos métodos a cima informados para resultados do RemoteObject.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=273&amp;download=FlexDuck.mxml">FlexDuck.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27356"><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
</pre></td><td class="code" id="p273code56"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
<span style="color: #0066CC;">import</span> br.<span style="color: #006600;">com</span>.<span style="color: #006600;">horochovec</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">Contato</span>;
&nbsp;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayList</span>;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Alert</span>;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">FaultEvent</span>;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ResultEvent</span>;
&nbsp;
<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> contato : Contato 		= <span style="color: #000000; font-weight: bold;">new</span> Contato<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> listContato : ArrayList 	= <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Metodo para falhas na comunicação
 */</span>				
protected <span style="color: #000000; font-weight: bold;">function</span> onFault<span style="color: #66cc66;">&#40;</span>event:FaultEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Erro'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Funcao para retorno de cadastro do Contato
 */</span>
protected <span style="color: #000000; font-weight: bold;">function</span> onResultAddContatoHandler<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> 
<span style="color: #66cc66;">&#123;</span>
	Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Adicionado'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Funcao para retorno da lista de contatos
 */</span>
protected <span style="color: #000000; font-weight: bold;">function</span> onResultGetListContatoHandler<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">this</span>.<span style="color: #006600;">listContato</span> = event.<span style="color: #006600;">result</span> as ArrayList;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Agora, iremos implementar no botão do painel de cadastro e ao botão no painel de listagem de informações, o evento de <em>click</em> para que seja enviado ao java o bean para cadastro e solicitado ao java a lista de contatos.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=273&amp;download=FlexDuck.mxml">FlexDuck.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27357"><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" id="p273code57"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>s:Panel <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;137&quot;</span> title=<span style="color: #ff0000;">&quot;Cadastro&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span> top=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> x=<span style="color: #ff0000;">&quot;55&quot;</span> label=<span style="color: #ff0000;">&quot;Cadastrar&quot;</span> bottom=<span style="color: #ff0000;">&quot;10&quot;</span> id=<span style="color: #ff0000;">&quot;btnCadastro&quot;</span> click=<span style="color: #ff0000;">&quot;btnCadastroClickHandler(event)&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:Label x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;16&quot;</span> <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Nome:&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:Label x=<span style="color: #ff0000;">&quot;13&quot;</span> y=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Email:&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:TextInput x=<span style="color: #ff0000;">&quot;56&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;332&quot;</span> id=<span style="color: #ff0000;">&quot;nome&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:TextInput x=<span style="color: #ff0000;">&quot;56&quot;</span> y=<span style="color: #ff0000;">&quot;44&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;332&quot;</span> id=<span style="color: #ff0000;">&quot;email&quot;</span><span style="color: #66cc66;">/&gt;</span>
<span style="color: #66cc66;">&lt;/</span>s:Panel<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>s:Panel x=<span style="color: #ff0000;">&quot;12&quot;</span> y=<span style="color: #ff0000;">&quot;166&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;227&quot;</span> title=<span style="color: #ff0000;">&quot;Pesquisa&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>mx:DataGrid x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span> bottom=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #0066CC;">right</span>=<span style="color: #ff0000;">&quot;5&quot;</span> top=<span style="color: #ff0000;">&quot;5&quot;</span> id=<span style="color: #ff0000;">&quot;grid&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{this.listContato}&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:columns<span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>mx:DataGridColumn headerText=<span style="color: #ff0000;">&quot;Nome&quot;</span> dataField=<span style="color: #ff0000;">&quot;nome&quot;</span><span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;</span>mx:DataGridColumn headerText=<span style="color: #ff0000;">&quot;Email&quot;</span> dataField=<span style="color: #ff0000;">&quot;email&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;/</span>mx:columns<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:DataGrid<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> x=<span style="color: #ff0000;">&quot;-1&quot;</span> y=<span style="color: #ff0000;">&quot;163&quot;</span> label=<span style="color: #ff0000;">&quot;Listar todos&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;5&quot;</span> bottom=<span style="color: #ff0000;">&quot;5&quot;</span> id=<span style="color: #ff0000;">&quot;btnListar&quot;</span> click=<span style="color: #ff0000;">&quot;btnListarClickHandler(event)&quot;</span><span style="color: #66cc66;">/&gt;</span>
<span style="color: #66cc66;">&lt;/</span>s:Panel<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Com os eventos de click de cada botão implementados, falta apenas fazer a implementação de seus métodos. Para isso vamos adicionar ao bloco <em>fx:script</em> o seguinte código:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=273&amp;download=FlexDuck.mxml">FlexDuck.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27358"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" id="p273code58"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Evento de click do botão de cadastro
 */</span>
protected <span style="color: #000000; font-weight: bold;">function</span> btnCadastroClickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">this</span>.<span style="color: #006600;">remoteObject</span>.<span style="color: #006600;">addContato</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">contato</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Evento de click do botão de pesquisa
 */</span>
protected <span style="color: #000000; font-weight: bold;">function</span> btnListarClickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">this</span>.<span style="color: #006600;">remoteObject</span>.<span style="color: #006600;">getListContato</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Para finalizar o código, irei adicionar o <em>Binding</em> entre os dois <em>TextInput</em> e o bean que será serializado para o Java:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=273&amp;download=FlexDuck.mxml">FlexDuck.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27359"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p273code59"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>fx:Binding source=<span style="color: #ff0000;">&quot;nome.text&quot;</span> destination=<span style="color: #ff0000;">&quot;contato.nome&quot;</span> twoWay=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">/&gt;</span>
<span style="color: #66cc66;">&lt;</span>fx:Binding source=<span style="color: #ff0000;">&quot;email.text&quot;</span> destination=<span style="color: #ff0000;">&quot;contato.email&quot;</span> twoWay=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">/&gt;</span></pre></td></tr></table></div>

<p>Feito isso, pronto, nossa aplicação de teste está pronta para o uso final, como resultado, obtemos:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/16.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/16.jpg" alt="" title="16" width="419" height="410" class="aligncenter size-full wp-image-331" align="center" /></a></p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/17.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/17.jpg" alt="" title="17" width="419" height="410" class="aligncenter size-full wp-image-332" align="center" /></a></p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/18.jpg"><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/03/18.jpg" alt="" title="18" width="419" height="410" class="aligncenter size-full wp-image-333" align="center" /></a></p>
<p>A implementação completa do Flex será:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=273&amp;download=FlexDuck.mxml">FlexDuck.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27360"><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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
</pre></td><td class="code" id="p273code60"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> 
			   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> 
			   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
		<span style="color: #0066CC;">import</span> br.<span style="color: #006600;">com</span>.<span style="color: #006600;">horochovec</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">Contato</span>;
&nbsp;
		<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;
		<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Alert</span>;
		<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">FaultEvent</span>;
		<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ResultEvent</span>;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> contato : Contato 				= <span style="color: #000000; font-weight: bold;">new</span> Contato<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> listContato : ArrayCollection 	= <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Metodo para falhas na comunicação
		 */</span>				
		protected <span style="color: #000000; font-weight: bold;">function</span> onFault<span style="color: #66cc66;">&#40;</span>event:FaultEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Erro'</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Funcao para retorno de cadastro do Contato
		 */</span>
		protected <span style="color: #000000; font-weight: bold;">function</span> onResultAddContatoHandler<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> 
		<span style="color: #66cc66;">&#123;</span>
			Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Adicionado'</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Funcao para retorno da lista de contatos
		 */</span>
		protected <span style="color: #000000; font-weight: bold;">function</span> onResultGetListContatoHandler<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">listContato</span> = event.<span style="color: #006600;">result</span> as ArrayCollection;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Evento de click do botão de cadastro
		 */</span>
		protected <span style="color: #000000; font-weight: bold;">function</span> btnCadastroClickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">remoteObject</span>.<span style="color: #006600;">addContato</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">contato</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Evento de click do botão de pesquisa
		 */</span>
		protected <span style="color: #000000; font-weight: bold;">function</span> btnListarClickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">remoteObject</span>.<span style="color: #006600;">getListContato</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>fx:Binding source=<span style="color: #ff0000;">&quot;nome.text&quot;</span> 	destination=<span style="color: #ff0000;">&quot;contato.nome&quot;</span> 	twoWay=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;</span>fx:Binding source=<span style="color: #ff0000;">&quot;email.text&quot;</span> destination=<span style="color: #ff0000;">&quot;contato.email&quot;</span> twoWay=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">/&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
&nbsp;
		<span style="color: #66cc66;">&lt;</span>s:RemoteObject id=<span style="color: #ff0000;">&quot;remoteObject&quot;</span> 
						destination=<span style="color: #ff0000;">&quot;ContatoService&quot;</span> 
						fault=<span style="color: #ff0000;">&quot;onFault(event);&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
			<span style="color: #66cc66;">&lt;</span>s:method <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;addContato&quot;</span> 
					  result=<span style="color: #ff0000;">&quot;onResultAddContatoHandler(event);&quot;</span>
					  fault=<span style="color: #ff0000;">&quot;onFault(event);&quot;</span> <span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;</span>s:method <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;getListContato&quot;</span> 
					  result=<span style="color: #ff0000;">&quot;onResultGetListContatoHandler(event);&quot;</span>
					  fault=<span style="color: #ff0000;">&quot;onFault(event);&quot;</span> <span style="color: #66cc66;">/&gt;</span>
&nbsp;
		<span style="color: #66cc66;">&lt;/</span>s:RemoteObject<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span>
&nbsp;
&nbsp;
	<span style="color: #66cc66;">&lt;</span>s:Panel <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;137&quot;</span> title=<span style="color: #ff0000;">&quot;Cadastro&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span> top=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> x=<span style="color: #ff0000;">&quot;55&quot;</span> label=<span style="color: #ff0000;">&quot;Cadastrar&quot;</span> bottom=<span style="color: #ff0000;">&quot;10&quot;</span> id=<span style="color: #ff0000;">&quot;btnCadastro&quot;</span> click=<span style="color: #ff0000;">&quot;btnCadastroClickHandler(event)&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:Label x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;16&quot;</span> <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Nome:&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:Label x=<span style="color: #ff0000;">&quot;13&quot;</span> y=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Email:&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:TextInput x=<span style="color: #ff0000;">&quot;56&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;332&quot;</span> id=<span style="color: #ff0000;">&quot;nome&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:TextInput x=<span style="color: #ff0000;">&quot;56&quot;</span> y=<span style="color: #ff0000;">&quot;44&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;332&quot;</span> id=<span style="color: #ff0000;">&quot;email&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>s:Panel<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>s:Panel x=<span style="color: #ff0000;">&quot;12&quot;</span> y=<span style="color: #ff0000;">&quot;166&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;227&quot;</span> title=<span style="color: #ff0000;">&quot;Pesquisa&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:DataGrid x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span> bottom=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #0066CC;">right</span>=<span style="color: #ff0000;">&quot;5&quot;</span> top=<span style="color: #ff0000;">&quot;5&quot;</span> id=<span style="color: #ff0000;">&quot;grid&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{this.listContato}&quot;</span><span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>mx:columns<span style="color: #66cc66;">&gt;</span>
				<span style="color: #66cc66;">&lt;</span>mx:DataGridColumn headerText=<span style="color: #ff0000;">&quot;Nome&quot;</span> dataField=<span style="color: #ff0000;">&quot;nome&quot;</span><span style="color: #66cc66;">/&gt;</span>
				<span style="color: #66cc66;">&lt;</span>mx:DataGridColumn headerText=<span style="color: #ff0000;">&quot;Email&quot;</span> dataField=<span style="color: #ff0000;">&quot;email&quot;</span><span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;/</span>mx:columns<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;/</span>mx:DataGrid<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> x=<span style="color: #ff0000;">&quot;-1&quot;</span> y=<span style="color: #ff0000;">&quot;163&quot;</span> label=<span style="color: #ff0000;">&quot;Listar todos&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;5&quot;</span> bottom=<span style="color: #ff0000;">&quot;5&quot;</span> id=<span style="color: #ff0000;">&quot;btnListar&quot;</span> click=<span style="color: #ff0000;">&quot;btnListarClickHandler(event)&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>s:Panel<span style="color: #66cc66;">&gt;</span>
&nbsp;
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Você pode fazer o download do projeto <a href="http://www.horochovec.com.br/blog/FlexDuck20100323.zip" target="_new"/>aqui</a>.</p>
<p>Obrigado e um abraço a todos!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.horochovec.com.br/blog/2010/03/23/flash-builder-flex-sdk-4-java-blazeds-tutorial/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>FlexORM – Framework ORM para persistência em AIR 1.5 &#8211; Download</title>
		<link>http://www.horochovec.com.br/blog/2010/01/27/flexorm-%e2%80%93-framework-orm-para-persistencia-em-air-1-5-download/</link>
		<comments>http://www.horochovec.com.br/blog/2010/01/27/flexorm-%e2%80%93-framework-orm-para-persistencia-em-air-1-5-download/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 00:42:31 +0000</pubDate>
		<dc:creator>Stefan Horochovec</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[FlexORM]]></category>

		<guid isPermaLink="false">http://www.horochovec.com.br/blog/?p=270</guid>
		<description><![CDATA[Olá pessoal Conforme prometido através de comentários no post anterior, segue o download do projeto DuckToDo com a implementação de um projeto utilizando FlexORM com AIR 1.5 Download aqui. Forte abraço]]></description>
			<content:encoded><![CDATA[<p>Olá pessoal</p>
<p>Conforme prometido através de comentários no post anterior, segue o download do projeto DuckToDo com a implementação de um projeto utilizando FlexORM com AIR 1.5</p>
<p>Download <a href="http://www.horochovec.com.br/DuckToDo.zip" target="_new">aqui</a>.</p>
<p>Forte abraço</p>
]]></content:encoded>
			<wfw:commentRss>http://www.horochovec.com.br/blog/2010/01/27/flexorm-%e2%80%93-framework-orm-para-persistencia-em-air-1-5-download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FlexORM &#8211; Framework ORM para persistência em AIR 1.5</title>
		<link>http://www.horochovec.com.br/blog/2010/01/27/flexorm-framework-orm-para-persistencia-em-air-1-5/</link>
		<comments>http://www.horochovec.com.br/blog/2010/01/27/flexorm-framework-orm-para-persistencia-em-air-1-5/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 03:08:04 +0000</pubDate>
		<dc:creator>Stefan Horochovec</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[FlexORM]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://www.horochovec.com.br/blog/?p=250</guid>
		<description><![CDATA[Olá pessoal, Neste artigo, irei comentar um pouco sobre o FlexORM. Este framework tem como objetivo o mapeamento objeto-relacional em projetos que utilizem AIR e base de dados embarcada (SQLite). O FlexORM é uma criação de Mark Moloney, e é hospedado pela RIAForge. O FlexORM tem suporte a versão 1.5 do AIR e abaixo, podemos [...]]]></description>
			<content:encoded><![CDATA[<p>Olá pessoal,</p>
<p>Neste artigo, irei comentar um pouco sobre o <a href="http://flexorm.riaforge.org/" target="_new">FlexORM</a>. Este framework tem como objetivo o mapeamento objeto-relacional em projetos que utilizem AIR e base de dados embarcada (SQLite).</p>
<p><span id="more-250"></span></p>
<p>O FlexORM é uma criação de <a href="http://flexorm.riaforge.org/index.cfm?event=page.myprojects&amp;id=2317" target="_new">Mark Moloney</a>, e é hospedado pela <a href="http://riaforge.org/" target="_new">RIAForge</a>.</p>
<p>O FlexORM tem suporte a versão 1.5 do AIR e abaixo, podemos listar algumas de suas vantagens para seu uso:</p>
<p>* Não há necessidade de criação e atualização de tabelas. O FlexORM se encarrega da criação da estrutura do banco, através de um mapeamento feito dentro do próprio objeto a ser persistido;</p>
<p>* Possui suporte as operações CRUD;</p>
<p>* Suporta associações 1:N, N:M, N:1 e 1:1;</p>
<p>* Suporte a atributos transientes;</p>
<p>* Suporte a constraints para consistência de chaves-estrangeiras, através de triggers do SQLite;</p>
<p>* Transações;</p>
<p>* Criação automática de índices;</p>
<p>* Lazy Loading;</p>
<p>* Dentre outras;</p>
<p>Para exemplificar o uso do FlexORM, irei criar um projeto chamado DuckToDo e o objetivo do projeto é que eu possa cadastrar algumas tarefas que eu precise realizar. A aplicação é bem simples no quesito visual, uma vez que o intuito do artigo é o conhecimento do FlexORM.</p>
<p>Para iniciar, iremos criar um projeto no FlexBuilder chamado DuckToDo, conforme a tela abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/01/12.jpg"><img class="aligncenter size-full wp-image-255" title="Novo Projeto" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/01/12.jpg" alt="" width="550" height="478" /></a></p>
<p>Em seguida, vá as propriedades do projeto, e na opção Flex Compiler, adicione a seguinte linha de comando &#8221; -keep-as3-metadata+=Table,Id,Column,ManyToOne,OneToMany,ManyToMany,Transient&#8221;, para que o compilador interprete as Metadatas adicionadas ao mapeamento dos Beans, conforme tela abaixo:</p>
<p><a href="http://www.horochovec.com.br/blog/wp-content/uploads/2010/01/21.jpg"><img class="aligncenter size-full wp-image-257" title="Project Properties" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/01/21.jpg" alt="" width="550" height="364" /></a></p>
<p>Feito isso, você deve fazer o download do FlexORM e adicionar ao seu projeto. Você pode optar por fazer o download do source através de um servidor de versionamento (subversion), ou fazer o download através deste <a href="http://www.horochovec.com.br/blog/flexorm.swc" target="_new">link</a> do arquivo .SWC do projeto FlexORM.</p>
<p>Depois de obter o .SWC, ou por download, ou recompilando o projeto, você deve adicioná-lo a pasta lib/ de seu projeto.</p>
<p>Feito isso, criaremos nossa classe de objeto que será persistida pela nossa aplicação.</p>
<p>Crie uma nova classe actionscript na package &#8220;org.flexduck.model&#8221; chamada Todo, e adicione o código abaixo:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p250code66'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25066"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p250code66"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> org<span style="color: #000066; font-weight: bold;">.</span>flexduck<span style="color: #000066; font-weight: bold;">.</span>model
<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
	<span style="color: #000000;">&#91;</span>Table<span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;TODO&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Todo
	<span style="color: #000000;">&#123;</span>
		<span style="color: #000000;">&#91;</span>Id<span style="color: #000000;">&#93;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> codigo 	<span style="color: #000066; font-weight: bold;">:</span> <a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #000000;">&#91;</span>Column<span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;titulo&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> titulo 	<span style="color: #000066; font-weight: bold;">:</span> <a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #000000;">&#91;</span>Column<span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;descricao&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> descricao <span style="color: #000066; font-weight: bold;">:</span> <a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Neste momento, quem trabalha com Java e utiliza Hibernate ou JPA já percebe uma grande semelhança. Através da Metadata <strong>[Table]</strong> no escopo da classe, definimos a qual tabela este objeto deve ser persistido.</p>
<p>No atributo codigo, foi adicionado a Metadata <strong>[Id]</strong> indicando que esse atributo corresponde a chave primária, ou o identificador, do objeto.</p>
<p>E nos atributos, titulo e descrição, adicionado a Metadata <strong>[Column]</strong> indicando que refere-se a uma coluna. Junto a Metadata também foi adicionado o nome respectivo da coluna na tabela.</p>
<p>Com isso, nosso bean está pronto para ser persistido. Vamos para a sua gravação.</p>
<p>Dentro do arquivo DuckToDo.mxml foi criada a seguinte estrutura de componentes.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p250code67'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25067"><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
</pre></td><td class="code" id="p250code67"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Binding destination=<span style="color: #990000;">&quot;todo.titulo&quot;</span> 		<span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;titulo.text&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>Binding destination=<span style="color: #990000;">&quot;todo.descricao&quot;</span> 	<span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;descricao.text&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;500&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;250&quot;</span> layout=<span style="color: #990000;">&quot;absolute&quot;</span> title=<span style="color: #990000;">&quot;O que tenho para fazer?&quot;</span> horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span> verticalCenter=<span style="color: #990000;">&quot;0&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>ViewStack id=<span style="color: #990000;">&quot;vw&quot;</span> <span style="color: #004993;">top</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">left</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;0&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>Canvas label=<span style="color: #990000;">&quot;Grid&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;100%&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;10&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Título&quot;</span> fontWeight=<span style="color: #990000;">&quot;bold&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>TextInput <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;10&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;29&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;460&quot;</span> id=<span style="color: #990000;">&quot;titulo&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{this.todo.titulo}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;10&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;58&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Descrição&quot;</span> fontWeight=<span style="color: #990000;">&quot;bold&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>TextArea <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;10&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;75&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;460&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;85&quot;</span> id=<span style="color: #990000;">&quot;descricao&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{this.todo.descricao}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;318&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;172&quot;</span> label=<span style="color: #990000;">&quot;Adicionar&quot;</span> id=<span style="color: #990000;">&quot;btnAdd&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;btnAddHandler(event);&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 <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;252&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;172&quot;</span> label=<span style="color: #990000;">&quot;Listar&quot;</span> id=<span style="color: #990000;">&quot;btnListar&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;btnListarHandler(event);&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 <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;189&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;172&quot;</span> label=<span style="color: #990000;">&quot;Novo&quot;</span> id=<span style="color: #990000;">&quot;btnNovo&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;btnNovoHandler(event);&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 <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;406&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;172&quot;</span> label=<span style="color: #990000;">&quot;Excluir&quot;</span> id=<span style="color: #990000;">&quot;btnDel&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;btnDelHandler(event);&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas label=<span style="color: #990000;">&quot;Formulario&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;100%&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>DataGrid 	<span style="color: #004993;">top</span>=<span style="color: #990000;">&quot;5&quot;</span> <span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;5&quot;</span> <span style="color: #004993;">left</span>=<span style="color: #990000;">&quot;5&quot;</span> <span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;30&quot;</span> 
						id=<span style="color: #990000;">&quot;dg&quot;</span> 
						<span style="color: #004993;">doubleClickEnabled</span>=<span style="color: #990000;">&quot;true&quot;</span> 
						<span style="color: #004993;">doubleClick</span>=<span style="color: #990000;">&quot;doubleClickHandler(event);&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>columns<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>DataGridColumn dataField=<span style="color: #990000;">&quot;titulo&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>columns<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>DataGrid<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;Pesquisar&quot;</span> id=<span style="color: #990000;">&quot;btnPesquisar&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;btnPesquisarHandler(event);&quot;</span> <span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;5&quot;</span> <span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;5&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;Cadastrar&quot;</span> id=<span style="color: #990000;">&quot;btnCadastrar&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;btnCadastrarHandler(event);&quot;</span> <span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;5&quot;</span> <span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;90&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>Canvas<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>ViewStack<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>Essa estrutura corresponde a um Panel, contendo um ViewStack com dois Canvas dentro. Para o primeiro Canvas foi adicionado um Grid para conter a lista de tarefas e no segundo Canvas, um pequeno formulário para a manutenção dos registros.</p>
<p><strong>Nesse artigo não irei comentar sobre a estrutura do formulário, considerando apenas como relevante as instruções de uso do FlexORM.</strong></p>
<p>Foi adicionado um evento no <strong>creationComplete</strong> da minha aplicação, para instanciar o banco de dados, conforme declaração abaixo:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p250code68'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25068"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p250code68"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>WindowedApplication 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> 
						creationComplete=<span style="color: #990000;">&quot;initApp(event);&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>E dentro do bloco de programação em ActionScript foi adicionado:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p250code69'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25069"><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
85
86
87
88
89
90
91
92
93
</pre></td><td class="code" id="p250code69"><pre class="actionscript3" style="font-family:monospace;"><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>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>flexduck<span style="color: #000066; font-weight: bold;">.</span>model<span style="color: #000066; font-weight: bold;">.</span>Todo<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">import</span> nz<span style="color: #000066; font-weight: bold;">.</span>co<span style="color: #000066; font-weight: bold;">.</span>codec<span style="color: #000066; font-weight: bold;">.</span>flexorm<span style="color: #000066; font-weight: bold;">.</span>EntityManager<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Objeto de persistencia
 */</span> 
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> genericDAO 	<span style="color: #000066; font-weight: bold;">:</span> EntityManager	= EntityManager<span style="color: #000066; font-weight: bold;">.</span>instance<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Classe para listar
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> todoClass	<span style="color: #000066; font-weight: bold;">:</span> <a href="http://www.google.com/search?q=class%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:class.html"><span style="color: #004993;">Class</span></a>			= Todo<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Bean
 */</span>
<span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> todo		<span style="color: #000066; font-weight: bold;">:</span> Todo			= <span style="color: #0033ff; font-weight: bold;">new</span> Todo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Evento disparado no creationComplete da aplicação para fazer a conexão com o banco de dados
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initApp<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><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> appDataBase <span style="color: #000066; font-weight: bold;">:</span> File = File<span style="color: #000066; font-weight: bold;">.</span>documentsDirectory<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;ducktodo.db&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> sqlConn		<span style="color: #000066; font-weight: bold;">:</span> SQLConnection	= <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>
	sqlConn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">open</span><span style="color: #000000;">&#40;</span>appDataBase<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>genericDAO<span style="color: #000066; font-weight: bold;">.</span>sqlConnection	= sqlConn<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Função disparada no click do botão de &quot;Adicionar&quot;
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> btnAddHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><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;">this</span><span style="color: #000066; font-weight: bold;">.</span>genericDAO<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">save</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>todo<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>dg<span style="color: #000066; font-weight: bold;">.</span>dataProvider	= <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>genericDAO<span style="color: #000066; font-weight: bold;">.</span>findAll<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>todoClass<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Função disparada no click do botão de &quot;Excluir&quot;
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> btnDelHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><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;">this</span><span style="color: #000066; font-weight: bold;">.</span>genericDAO<span style="color: #000066; font-weight: bold;">.</span>remove<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>todo<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>dg<span style="color: #000066; font-weight: bold;">.</span>dataProvider	= <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>genericDAO<span style="color: #000066; font-weight: bold;">.</span>findAll<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>todoClass<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Função disparada no duplo click no grid de pesquisa
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> doubleClickHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><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;">this</span><span style="color: #000066; font-weight: bold;">.</span>todo	= <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>dg<span style="color: #000066; font-weight: bold;">.</span>selectedItem <span style="color: #0033ff; font-weight: bold;">as</span> Todo<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>vw<span style="color: #000066; font-weight: bold;">.</span>selectedIndex	= <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Função disparada no click do botão de &quot;Pesquisar&quot;
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> btnPesquisarHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><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;">this</span><span style="color: #000066; font-weight: bold;">.</span>dg<span style="color: #000066; font-weight: bold;">.</span>dataProvider	= <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>genericDAO<span style="color: #000066; font-weight: bold;">.</span>findAll<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>todoClass<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Função disparada no click do botão de &quot;Cadastrar&quot;
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> btnCadastrarHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><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;">this</span><span style="color: #000066; font-weight: bold;">.</span>vw<span style="color: #000066; font-weight: bold;">.</span>selectedIndex 	= <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Função disparada no click do botão de &quot;Listar&quot;
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> btnListarHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><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;">this</span><span style="color: #000066; font-weight: bold;">.</span>vw<span style="color: #000066; font-weight: bold;">.</span>selectedIndex	= <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Função disparada no click do botão de &quot;Novo&quot;
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> btnNovoHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><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;">this</span><span style="color: #000066; font-weight: bold;">.</span>todo	= <span style="color: #0033ff; font-weight: bold;">new</span> Todo<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;">&#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></pre></td></tr></table></div>

<p>Alguns comentários relevantes:</p>
<p>Na função <strong>initApp</strong>, foi criado uma conexão SQLConnection, e a mesma foi passada para um objeto chamado genericDAO. Este objeto é uma instancia da classe EntityManager do FlexORM, responsável por executar os métodos para manipulação do banco de dados.</p>
<p>Na função <strong>btnAddHandler</strong> foi feita a persistencia do objeto Todo. Perceba que essa função é responsável por gravar e atualizar o objeto, não sendo necessário que o desenvolvedor se preocupe com a operação específica, apenas que em determinado momento, o objeto deve ser persistido, gravando-o ou fazendo sua atualização.</p>
<p>Na função <strong>btnDelHandler</strong> foi solicitado que determinado objeto fosse apagado do banco de dados.</p>
<p>Na função <strong> btnPesquisarHandler</strong> foi solicitado uma busca em todos os registros de determinada Classe, e não um objeto, fique atento a essa situação.</p>
<p>Os demais eventos servem para a navegação da tela, portanto, não serão comentados. </p>
<p>Se você fez corretamente a inclusão de todos os fontes, terá o resultado:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p250code70'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25070"><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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
</pre></td><td class="code" id="p250code70"><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 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> 
						creationComplete=<span style="color: #990000;">&quot;initApp(event);&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
<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>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>flexduck<span style="color: #000066; font-weight: bold;">.</span>model<span style="color: #000066; font-weight: bold;">.</span>Todo<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">import</span> nz<span style="color: #000066; font-weight: bold;">.</span>co<span style="color: #000066; font-weight: bold;">.</span>codec<span style="color: #000066; font-weight: bold;">.</span>flexorm<span style="color: #000066; font-weight: bold;">.</span>EntityManager<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Objeto de persistencia
 */</span> 
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> genericDAO 	<span style="color: #000066; font-weight: bold;">:</span> EntityManager	= EntityManager<span style="color: #000066; font-weight: bold;">.</span>instance<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Classe para listar
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> todoClass	<span style="color: #000066; font-weight: bold;">:</span> <a href="http://www.google.com/search?q=class%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:class.html"><span style="color: #004993;">Class</span></a>			= Todo<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Bean
 */</span>
<span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> todo		<span style="color: #000066; font-weight: bold;">:</span> Todo			= <span style="color: #0033ff; font-weight: bold;">new</span> Todo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Evento disparado no creationComplete da aplicação para fazer a conexão com o banco de dados
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initApp<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><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> appDataBase <span style="color: #000066; font-weight: bold;">:</span> File = File<span style="color: #000066; font-weight: bold;">.</span>documentsDirectory<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;ducktodo.db&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> sqlConn		<span style="color: #000066; font-weight: bold;">:</span> SQLConnection	= <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>
	sqlConn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">open</span><span style="color: #000000;">&#40;</span>appDataBase<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>genericDAO<span style="color: #000066; font-weight: bold;">.</span>sqlConnection	= sqlConn<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Função disparada no click do botão de &quot;Adicionar&quot;
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> btnAddHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><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;">this</span><span style="color: #000066; font-weight: bold;">.</span>genericDAO<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">save</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>todo<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>dg<span style="color: #000066; font-weight: bold;">.</span>dataProvider	= <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>genericDAO<span style="color: #000066; font-weight: bold;">.</span>findAll<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>todoClass<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Função disparada no click do botão de &quot;Excluir&quot;
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> btnDelHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><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;">this</span><span style="color: #000066; font-weight: bold;">.</span>genericDAO<span style="color: #000066; font-weight: bold;">.</span>remove<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>todo<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>dg<span style="color: #000066; font-weight: bold;">.</span>dataProvider	= <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>genericDAO<span style="color: #000066; font-weight: bold;">.</span>findAll<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>todoClass<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Função disparada no duplo click no grid de pesquisa
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> doubleClickHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><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;">this</span><span style="color: #000066; font-weight: bold;">.</span>todo	= <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>dg<span style="color: #000066; font-weight: bold;">.</span>selectedItem <span style="color: #0033ff; font-weight: bold;">as</span> Todo<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>vw<span style="color: #000066; font-weight: bold;">.</span>selectedIndex	= <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Função disparada no click do botão de &quot;Pesquisar&quot;
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> btnPesquisarHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><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;">this</span><span style="color: #000066; font-weight: bold;">.</span>dg<span style="color: #000066; font-weight: bold;">.</span>dataProvider	= <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>genericDAO<span style="color: #000066; font-weight: bold;">.</span>findAll<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>todoClass<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Função disparada no click do botão de &quot;Cadastrar&quot;
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> btnCadastrarHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><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;">this</span><span style="color: #000066; font-weight: bold;">.</span>vw<span style="color: #000066; font-weight: bold;">.</span>selectedIndex 	= <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Função disparada no click do botão de &quot;Listar&quot;
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> btnListarHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><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;">this</span><span style="color: #000066; font-weight: bold;">.</span>vw<span style="color: #000066; font-weight: bold;">.</span>selectedIndex	= <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Função disparada no click do botão de &quot;Novo&quot;
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> btnNovoHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=mouseevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouseevent.html"><span style="color: #004993;">MouseEvent</span></a><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;">this</span><span style="color: #000066; font-weight: bold;">.</span>todo	= <span style="color: #0033ff; font-weight: bold;">new</span> Todo<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;">&#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>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Binding destination=<span style="color: #990000;">&quot;todo.titulo&quot;</span> 		<span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;titulo.text&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>Binding destination=<span style="color: #990000;">&quot;todo.descricao&quot;</span> 	<span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;descricao.text&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;500&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;250&quot;</span> layout=<span style="color: #990000;">&quot;absolute&quot;</span> title=<span style="color: #990000;">&quot;O que tenho para fazer?&quot;</span> horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span> verticalCenter=<span style="color: #990000;">&quot;0&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>ViewStack id=<span style="color: #990000;">&quot;vw&quot;</span> <span style="color: #004993;">top</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">left</span>=<span style="color: #990000;">&quot;0&quot;</span> <span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;0&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>Canvas label=<span style="color: #990000;">&quot;Grid&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;100%&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;10&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Título&quot;</span> fontWeight=<span style="color: #990000;">&quot;bold&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>TextInput <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;10&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;29&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;460&quot;</span> id=<span style="color: #990000;">&quot;titulo&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{this.todo.titulo}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;10&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;58&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Descrição&quot;</span> fontWeight=<span style="color: #990000;">&quot;bold&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>TextArea <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;10&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;75&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;460&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;85&quot;</span> id=<span style="color: #990000;">&quot;descricao&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{this.todo.descricao}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;318&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;172&quot;</span> label=<span style="color: #990000;">&quot;Adicionar&quot;</span> id=<span style="color: #990000;">&quot;btnAdd&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;btnAddHandler(event);&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 <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;252&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;172&quot;</span> label=<span style="color: #990000;">&quot;Listar&quot;</span> id=<span style="color: #990000;">&quot;btnListar&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;btnListarHandler(event);&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 <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;189&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;172&quot;</span> label=<span style="color: #990000;">&quot;Novo&quot;</span> id=<span style="color: #990000;">&quot;btnNovo&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;btnNovoHandler(event);&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 <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;406&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;172&quot;</span> label=<span style="color: #990000;">&quot;Excluir&quot;</span> id=<span style="color: #990000;">&quot;btnDel&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;btnDelHandler(event);&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas label=<span style="color: #990000;">&quot;Formulario&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;100%&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>DataGrid 	<span style="color: #004993;">top</span>=<span style="color: #990000;">&quot;5&quot;</span> <span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;5&quot;</span> <span style="color: #004993;">left</span>=<span style="color: #990000;">&quot;5&quot;</span> <span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;30&quot;</span> 
						id=<span style="color: #990000;">&quot;dg&quot;</span> 
						<span style="color: #004993;">doubleClickEnabled</span>=<span style="color: #990000;">&quot;true&quot;</span> 
						<span style="color: #004993;">doubleClick</span>=<span style="color: #990000;">&quot;doubleClickHandler(event);&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>columns<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>DataGridColumn dataField=<span style="color: #990000;">&quot;titulo&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>columns<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>DataGrid<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;Pesquisar&quot;</span> id=<span style="color: #990000;">&quot;btnPesquisar&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;btnPesquisarHandler(event);&quot;</span> <span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;5&quot;</span> <span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;5&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;Cadastrar&quot;</span> id=<span style="color: #990000;">&quot;btnCadastrar&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;btnCadastrarHandler(event);&quot;</span> <span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;5&quot;</span> <span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;90&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>Canvas<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>ViewStack<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
<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>Basta exportar sua aplicação, e tudo deverá funcionar perfeitamente.</p>
<p>Forte abraço e até a próxima!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.horochovec.com.br/blog/2010/01/27/flexorm-framework-orm-para-persistencia-em-air-1-5/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Flex 4 &#8211; Two-way data binding</title>
		<link>http://www.horochovec.com.br/blog/2010/01/21/flex-4-two-way-data-binding/</link>
		<comments>http://www.horochovec.com.br/blog/2010/01/21/flex-4-two-way-data-binding/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 02:07:39 +0000</pubDate>
		<dc:creator>Stefan Horochovec</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Data Binding]]></category>
		<category><![CDATA[Two-way Data Binding]]></category>

		<guid isPermaLink="false">http://www.horochovec.com.br/blog/?p=241</guid>
		<description><![CDATA[Olá amigos Neste post quero comentar uma nova feature do Flex SDK 4 que é o &#8220;two-way data binding&#8221;, mas o que é e no que isso pode nos auxiliar no dia a dia? Mas afinal, o que é o Data Binding? É a ação de passar valores de um objeto para outro de forma [...]]]></description>
			<content:encoded><![CDATA[<p>Olá amigos</p>
<p>Neste post quero comentar uma nova feature do Flex SDK 4 que é o &#8220;two-way data binding&#8221;, mas o que é e no que isso pode nos auxiliar no dia a dia?</p>
<p><span id="more-241"></span></p>
<p>Mas afinal, o que é o Data Binding? É a ação de passar valores de um objeto para outro de forma automática. Quando um objeto sofre uma alteração em determinada propriedade dele, essa alteração é refletida em algum atributo de um objeto. Esse objeto pode ou não, vir a ser o mesmo objeto que sofreu a primeira alteração.</p>
<p>No Flex 3.x o Data Binding possibilitava o espelhamento de informação de um objeto para outro porém o inverso não ocorria de forma automática, dessa forma, éramos obrigados a criar outro Binding, só que desta vez, fazendo a operação de forma inversa, conforme segue código abaixo:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=241&amp;download=DataBinding.mxml">DataBinding.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p24174"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p241code74"><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>Application 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>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Binding <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;campoA.text&quot;</span> destination=<span style="color: #990000;">&quot;campoB.text&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>Binding <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;campoB.text&quot;</span> destination=<span style="color: #990000;">&quot;campoA.text&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>TextInput id=<span style="color: #990000;">&quot;campoA&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;10&quot;</span> 	<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&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>TextInput id=<span style="color: #990000;">&quot;campoB&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;178&quot;</span> 	<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Application<span style="color: #000066; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>Obviamente que isso dificultava o trabalho do desenvolvedor em seu dia-a-dia, além de aumentar o consumo de memória das aplicações.</p>
<p>No Flex 4.0 a Adobe preparou uma ótima surpresa para auxiliar neste problema &#8211; &#8220;Two-way Data Binding&#8221;.</p>
<p>Mas como ele funciona? Simples, através da declaração adicional <em>twoWay</em> no objeto <em>Binding</em> você pode definir se o binding deve enviar e receber alterações no atributo do objeto de origem.</p>
<p>Veja exemplo abaixo:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=241&amp;download=TwoWayBinding.mxml">TwoWayBinding.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p24175"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p241code75"><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>s<span style="color: #000066; font-weight: bold;">:</span>Application xmlns<span style="color: #000066; font-weight: bold;">:</span>fx=<span style="color: #990000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> 
			   xmlns<span style="color: #000066; font-weight: bold;">:</span>s=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> 
			   xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>fx<span style="color: #000066; font-weight: bold;">:</span>Declarations<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;/</span>fx<span style="color: #000066; font-weight: bold;">:</span>Declarations<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>fx<span style="color: #000066; font-weight: bold;">:</span>Binding <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;campoA.text&quot;</span> destination=<span style="color: #990000;">&quot;campoB.text&quot;</span> twoWay=<span style="color: #990000;">&quot;true&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>TextInput <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;10&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;21&quot;</span> id=<span style="color: #990000;">&quot;campoA&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>TextInput <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;146&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;21&quot;</span> id=<span style="color: #990000;">&quot;campoB&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;/</span>s<span style="color: #000066; font-weight: bold;">:</span>Application<span style="color: #000066; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>Simples, dessa forma já qualquer alteração feita no TextInput &#8220;campoB&#8221; será refletida no TextInput &#8220;campoA&#8221; e vice-versa.</p>
<p>Também é possível fazer a declaração conforme exemplo abaixo, utilizando o @ em conjunto com os {}:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=241&amp;download=TwoWayBinding.mxml">TwoWayBinding.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p24176"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p241code76"><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>s<span style="color: #000066; font-weight: bold;">:</span>Application xmlns<span style="color: #000066; font-weight: bold;">:</span>fx=<span style="color: #990000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> 
			   xmlns<span style="color: #000066; font-weight: bold;">:</span>s=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> 
			   xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>fx<span style="color: #000066; font-weight: bold;">:</span>Declarations<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;/</span>fx<span style="color: #000066; font-weight: bold;">:</span>Declarations<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>fx<span style="color: #000066; font-weight: bold;">:</span>Binding <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;campoA.text&quot;</span> destination=<span style="color: #990000;">&quot;campoB.text&quot;</span> twoWay=<span style="color: #990000;">&quot;true&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>TextInput <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;10&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;21&quot;</span> id=<span style="color: #990000;">&quot;campoA&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>TextInput <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;146&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;21&quot;</span> id=<span style="color: #990000;">&quot;campoB&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>TextInput <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;10&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;65&quot;</span> id=<span style="color: #990000;">&quot;campoC&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;@{campoD.text}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>TextInput <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;150&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;65&quot;</span> id=<span style="color: #990000;">&quot;campoD&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;/</span>s<span style="color: #000066; font-weight: bold;">:</span>Application<span style="color: #000066; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>Eu prefiro a primeira opção, utilizando a declaração do <em>< fx:Binding ></em> para um melhor entendimento e ordenação do código-fonte.</p>
<p>Um abraço e até a próxima.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.horochovec.com.br/blog/2010/01/21/flex-4-two-way-data-binding/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Instalando AIR 2.0 no seu Flash Builder</title>
		<link>http://www.horochovec.com.br/blog/2010/01/12/instalando-air-2-0-no-seu-flash-builder/</link>
		<comments>http://www.horochovec.com.br/blog/2010/01/12/instalando-air-2-0-no-seu-flash-builder/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 05:30:52 +0000</pubDate>
		<dc:creator>Stefan Horochovec</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[AIR 2.0]]></category>
		<category><![CDATA[SDK]]></category>

		<guid isPermaLink="false">http://www.horochovec.com.br/blog/?p=217</guid>
		<description><![CDATA[Olá pessoal, Primeiramente quero desejar um Feliz 2010 a todos os leitores do blog! Esse ano promete, teremos o lançamento no novo Flash Builder 4 com o Flex SDK 4.0, AIR 2.0 e Flash Catalyst, além das novas versões dos softwares da Adobe para a versão CS5, a qual venho testando a alguns meses e [...]]]></description>
			<content:encoded><![CDATA[<p>Olá pessoal, Primeiramente quero desejar um Feliz 2010 a todos os leitores do blog!</p>
<p>Esse ano promete, teremos o lançamento no novo Flash Builder 4 com o Flex SDK 4.0, AIR 2.0 e Flash Catalyst, além das novas versões dos softwares da Adobe para a versão CS5, a qual venho testando a alguns meses e tenho me surpreendido bastante, principalmente com o Flash CS5, agora com recursos para desenvolvimento para Iphone, mas este será um assunto específico para outro post, nesse artigo, iremos tratar apenas da instalação do AIR 2.0 dentro do Flash Builder 4.</p>
<p><span id="more-217"></span></p>
<p>O primeiro passo é fazer o download da nova versão do AIR 2.0 disponível no Adobe Labs. Para fazer o download clique <a href="http://labs.adobe.com/downloads/air2.html" target="_new">aqui</a>. No meu caso, eu fiz o download e salvei o arquivo AIR20_win_sdk_010710.zip dentro da pasta sdks\ da instalação do meu Flash Builder.</p>
<p><img class="aligncenter size-full wp-image-221" title="AIR SKD Download" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/01/11.jpg" alt="AIR SKD Download" width="498" height="369" /></p>
<p>Feito o download, você deve duplicar a pasta 4.0.0 que contem a nova versão do SDK do Flex, e após isso adicionar o conteúdo do SDK da nova versão do AIR para dentro da nova pasta que você acabou de duplicar. No meu caso, antes de copiar os arquivos do SDK do AIR eu alterei o nome da pasta para &#8220;4.0.0 + AIR 2.0.0 Beta&#8221; e depois copiei todos os arquivos do novo SDK do AIR para dentro da nova pasta. Confirmei que todos os arquivos que já existiam com o mesmo nome deveriam ser sobre-escritos.</p>
<p><img class="aligncenter size-full wp-image-223" title="Fusão de pastas = Flex SDK + AIR SDK" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/01/2.jpg" alt="Fusão de pastas = Flex SDK + AIR SDK" width="498" height="369" /></p>
<p>Ok, feito isso, podemos abrir o Flash Builder e fazer a configuração do SDK para utilização.</p>
<p>Ao abrir o Flash Builder, vá ao menu: Window -&gt; Preferences. Nesta janela, iremos adicionar um novo SDK para o Flash Builder, conforme a imagem abaixo:</p>
<p><img class="aligncenter size-full wp-image-226" title="3" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/01/3.jpg" alt="3" width="498" height="369" /></p>
<p>Após clicar em &#8220;Add&#8221;, seguimos com a configuração abaixo. Perceba que eu adicionei ao &#8220;Flex SDK Location&#8221; o caminho do SDK copiado do 4.0.0 e com a adição do SDK no AIR 2.0.0.</p>
<p><img class="aligncenter size-full wp-image-228" title="4" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/01/4.jpg" alt="4" width="514" height="195" /></p>
<p>E como resultado final:</p>
<p><img class="aligncenter size-full wp-image-229" title="5" src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/01/5.jpg" alt="5" width="498" height="369" /></p>
<p>Agora iremos criar um novo projeto, conforme as configurações da tela abaixo. Atente para a opção aonde eu digo que quero usar uma versão específica do SDK e marco o SDK &#8220;<em>4.0.0 + AIR 2.0.0Beta</em>&#8220;. </p>
<p><img src="http://www.horochovec.com.br/blog/wp-content/uploads/2010/01/6.jpg" alt="6" title="6" width="484" height="510" class="aligncenter size-full wp-image-231" /></p>
<p>Clicando em &#8220;Finish&#8221;, uma vez que não será necessário mais nenhuma configuração, nosso projeto está apto a trabalhar com a versão 2.0 do AIR SDK. </p>
<p>Dentro do arquivo, Main-app.xml na segunda linha, podemos ver a indicação da versão do SDK no arquivo de configuração para compilação do projeto.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=217&amp;download=Main-app.xml">Main-app.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21779"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p217code79"><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> standalone=<span style="color: #990000;">&quot;no&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;</span>application xmlns=<span style="color: #990000;">&quot;http://ns.adobe.com/air/application/2.0beta2&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;!--</span> Adobe AIR Application Descriptor File Template<span style="color: #000066; font-weight: bold;">.</span>
&nbsp;
	Specifies <span style="color: #004993;">parameters</span> <span style="color: #0033ff; font-weight: bold;">for</span> identifying<span style="color: #000066; font-weight: bold;">,</span> installing<span style="color: #000066; font-weight: bold;">,</span> and launching AIR applications<span style="color: #000066; font-weight: bold;">.</span>
&nbsp;
	xmlns <span style="color: #000066; font-weight: bold;">-</span> The Adobe AIR <span style="color: #004993;">namespace</span><span style="color: #000066; font-weight: bold;">:</span> http<span style="color: #000066; font-weight: bold;">:</span><span style="color: #009900; font-style: italic;">//ns.adobe.com/air/application/2.0beta2</span>
			The last segment of the <span style="color: #004993;">namespace</span> specifies the <span style="color: #004993;">version</span> 
			of the AIR runtime required <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">this</span> application to run<span style="color: #000066; font-weight: bold;">.</span>
&nbsp;
	minimumPatchLevel <span style="color: #000066; font-weight: bold;">-</span> The minimum patch <span style="color: #004993;">level</span> of the AIR runtime required to run 
			the application<span style="color: #000066; font-weight: bold;">.</span> Optional<span style="color: #000066; font-weight: bold;">.</span>
<span style="color: #000066; font-weight: bold;">--&gt;</span></pre></td></tr></table></div>

<p>Outro teste comum que você poderá encontrar em outros tutoriais com o mesmo objetivo que este é a instância de um objeto do tipo NativeProcess, que é uma classe específica desta versão do AIR, disponível no pacote: <em><strong>flash.desktop.</strong></em>. Você poderá fazer o teste da seguinte forma:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.horochovec.com.br/blog/wp-content/plugins/wp-codebox/wp-codebox.php?p=217&amp;download=Main.mxml">Main.mxml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21780"><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" id="p217code80"><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>s<span style="color: #000066; font-weight: bold;">:</span>WindowedApplication xmlns<span style="color: #000066; font-weight: bold;">:</span>fx=<span style="color: #990000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> 
					   xmlns<span style="color: #000066; font-weight: bold;">:</span>s=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> 
					   xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>fx<span style="color: #000066; font-weight: bold;">:</span>Declarations<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;!--</span> Place non<span style="color: #000066; font-weight: bold;">-</span>visual <span style="color: #004993;">elements</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span>g<span style="color: #000066; font-weight: bold;">.,</span> services<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">value</span> objects<span style="color: #000000;">&#41;</span> here <span style="color: #000066; font-weight: bold;">--&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;/</span>fx<span style="color: #000066; font-weight: bold;">:</span>Declarations<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>fx<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>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> nativeProcess <span style="color: #000066; font-weight: bold;">:</span> NativeProcess<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<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>fx<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>s<span style="color: #000066; font-weight: bold;">:</span>WindowedApplication<span style="color: #000066; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>Bom pessoal, espero ter ajudado a quem quer testar e ainda tinha dúvidas de como proceder a instalação do AIR 2.0 dentro do Flash Builder 4.</p>
<p>Um abraço e até a próxima!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.horochovec.com.br/blog/2010/01/12/instalando-air-2-0-no-seu-flash-builder/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
