<?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>Coding Color</title>
	<atom:link href="http://www.codingcolor.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codingcolor.com</link>
	<description>is Manuel Gonzalez</description>
	<lastBuildDate>Sat, 26 Jun 2010 04:18:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>An Arduino Pro Mini ultra-sonic beeping thingamajiggy</title>
		<link>http://www.codingcolor.com/microcontrollers/an-arduino-pro-mini-ultra-sonic-beeping-thingamajiggy/</link>
		<comments>http://www.codingcolor.com/microcontrollers/an-arduino-pro-mini-ultra-sonic-beeping-thingamajiggy/#comments</comments>
		<pubDate>Sat, 26 Jun 2010 04:09:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Micro Controllers]]></category>
		<category><![CDATA[8 ohm mini speaker]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Pro Mini 328 - 5V]]></category>
		<category><![CDATA[BlinkM RGB Led]]></category>
		<category><![CDATA[FTDI Basic Breakout - 5V]]></category>
		<category><![CDATA[Parallax's PING)))™ ultrasonic sensor]]></category>
		<category><![CDATA[ultrasonic sensor]]></category>

		<guid isPermaLink="false">http://www.codingcolor.com/?p=2740</guid>
		<description><![CDATA[The other day I received an email from an associate, who inquired if I was familiar with the Polaroid sx70 SONAR module. I replied with a simple NO, but I do have experience working with low-cost ultrasonic sensors like the Parallax&#8217;s PING)))™ ultrasonic sensor, Maxbotix ultrasonic rangefinder and the Devantech SRF02. Sonar or ultrasonic sensors [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I received an email from an associate, who inquired if I was familiar with the Polaroid sx70 SONAR <a href="http://www.acroname.com/robotics/parts/R11-6500.html" target="blank"><u>module</u></a>. I replied with a simple NO, but I do have experience working with low-cost ultrasonic sensors like the <a href="http://www.parallax.com/tabid/768/ProductID/92/Default.aspx" target="blank"><u>Parallax&#8217;s PING)))™ ultrasonic sensor</u></a>, <a href="http://www.maxbotix.com/BUY_NOW.html#LV-EZ" target="blank"><u>Maxbotix ultrasonic rangefinder</u></a> and the <a href="http://www.acroname.com/robotics/parts/R287-SRF02.html" target="blank"><u>Devantech SRF02</u></a>. Sonar or ultrasonic sensors are often used in mobile robotics for obstacle avoidance, navigation, map building and in interactive art installations where you need to detect an object in a room or space. Ultrasonic range sensors work by emitting a short burst of ultrasonic sound, which is reflected by objects in front of the device and returned to the detector. The receiver amplifier sends these reflected signals (echoes) to a micro-controller which times them to determine how far away the objects are, in other words measures the distance.  </p>
<p>So, in the spirit of teaching I decided to write a post on the Arduino Pro Mini and the Parallax Ultrasonic sensor. I went the extra mile and added audio feedback via a 8-ohm mini speaker, visual feedback via a BlinkM Led and included an external power source. </p>
<p>You will need the following components to build an ultra-sonic beeping thingamajiggy:</p>
<li><a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9218" target="blank"><u>Arduino Pro Mini 328 &#8211; 5V/16MHz</u></a></li>
<li><a href="http://www.sparkfun.com/commerce/product_info.php?products_id=116" target="blank"><u>Break Away Headers &#8211; Straight</u></a></li>
<li><a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9115" target="blank"><u>FTDI Basic Breakout &#8211; 5V</u></a> or <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9718" target="blank"><u>FTDI Cable 5V</u></a></li>
<li><a href="http://www.sparkfun.com/commerce/product_info.php?products_id=8579"><u>BlinkM RGB Led</u></a></li>
<li><a href="http://www.parallax.com/tabid/768/ProductID/92/Default.aspx" target="blank"><u>Parallax&#8217;s PING)))™ ultrasonic sensor</u></a></li>
<li><a href="http://www.radioshack.com/product/index.jsp?productId=2062406" target="blank"><u>8-ohm mini speaker</u></a></li>
<li><a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9567" target="blank"><u>Basic breadboard</u></a></li>
<li><a href="http://www.radioshack.com/product/index.jsp?productId=2062253" target="blank"><u>Enclosed 4 &#8220;AA&#8221; battery holder</u></a></li>
<li><a href="http://www.sparkfun.com/commerce/product_info.php?products_id=124" target="blank"><u>Jumper wire</u></a></li>
<p>Lets start by addressing the Arduino Pro Mini.<br />
The <a href="http://www.arduino.cc/en/Main/ArduinoBoardProMini" target="blank"><u>Arduino Pro Mini</u></a> is intended for advanced users who require flexibility, low-cost, and small size. Please note that there are two versions of the board, one that operates at 5V (like most Arduino boards), and one that operates at 3.3V. Both boards come with the minimum of components (no on-board USB or pin headers) to keep the cost down.  The <a href="http://www.arduino.cc/" target="blank"><u>Arduino Site</u></a> has an overview on the <a href="http://www.arduino.cc/en/Main/ArduinoBoardProMini" target="blank"><u>Arduino Pro Mini</u></a>, I suggest you at least review the <a href="http://www.arduino.cc/en/Main/ArduinoBoardProMini" target="blank"><u>page</u></a> to get familiar with the Inputs and Outputs of the board. The Arduino Pro Mini is programmed using a FTDI Cable or in my case a FTDI Basic Breakout board. </p>
<p>Since we are using a breadboard to prototype the ultra-sonic beeping thingamajiggy, I suggest you solder the break away headers to the Arduino, in fact, I always suggest creating connectors for sensors rather than just soldering them to the Arduino. A quick soldering tip is to stick the headers into a breadboard and place the Arduino board on top. Then solder all headers. Make sure you also solder headers to Analog 4 and 5, which you will find on the board near the ATmega328 chip. You should now have something that resembles this:</p>
<p><img src="http://www.codingcolor.com/wp-content/uploads/2010/06/Arduino_pro_mini.jpg" alt="" title="Arduino_pro_mini" width="550" height="413" class="aligncenter size-full wp-image-2815" /></p>
<p>Now, lets hook up some power. This part is very important, you don&#8217;t want to fry your board so pay close attention. Locate The power pins on your Arduino Pro Mini:</p>
<p>* RAW. For supplying a raw (unregulated) voltage to the board.<br />
* VCC. The regulated 3.3 or 5 volt supply.<br />
* GND. Ground pins.</p>
<p>The VCC pin on the Arduino Pro Mini is bypassing the regulator and you should NOT CONNECT ANY POWER SUPPLY ABOVE 5 VOLTS to this pin. In most cases you will use the RAW pin to connect a power supply (up to 12V) in need of regulation.</p>
<p>The <a href="http://www.radioshack.com/product/index.jsp?productId=2062253" target="blank"><u>enclosed 4 &#8220;AA&#8221; battery holder</u></a> from Radio Shack, has a voltage of 6 volts, therefore I have no other choice but to connect it to the unregulated RAW pin. </p>
<p>ONLY USE THE VCC PIN IF YOU ARE SURE YOU HAVE A REGULATED 5 VOLT POWER SOURCE. </p>
<p>I took the battery enclosure and added a <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=8432" target="blank"><u>2 pin screw terminal</u></a> to the end of the wires to make the connection to the breadboard easier.</p>
<p><img src="http://www.codingcolor.com/wp-content/uploads/2010/06/Enclosed_battery.jpg" alt="" title="Enclosed_battery" width="550" height="413" class="aligncenter size-full wp-image-2822" /></p>
<p>Make sure the battery enclosure switch is on the OFF state and then connect the power supply to the breadboard.<br />
Add the ground (black) wire from the battery enclosure to the blue rail of the breadboard.<br />
Add the power (red) wire from the battery enclosure to the red rail of the breadboard.</p>
<p><img src="http://www.codingcolor.com/wp-content/uploads/2010/06/arduino_battery.jpg" alt="" title="arduino_battery" width="550" height="413" class="aligncenter size-full wp-image-2825" /></p>
<p>Grab some jumper wires and connect a wire from the blue rail of the breadboard to the GND pin on the Arduino (green wire in image below). Connect a wire from the red rail of the breadboard to the RAW pin on the Arduino (blue wire in image below).</p>
<p><img src="http://www.codingcolor.com/wp-content/uploads/2010/06/Pro_mini_powered.jpg" alt="" title="Pro_mini_powered" width="550" height="413" class="aligncenter size-full wp-image-2834" /></p>
<p>Next lets connect the ultrasonic sensor.<br />
<img src="http://www.codingcolor.com/wp-content/uploads/2010/06/pRS1C-4174483w345.jpg" alt="" title="pRS1C-4174483w345" width="345" height="235" class="aligncenter size-full wp-image-2837" /><br />
You will notice the sensor only has 3 pins, the 5V pin, the GND pin and the SIG (signal) pin. You can easily place the senor onto your breadboard and wire it up. I had some extra <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9385" target="blank"><u>Male/Female jumper wires</u></a>, so I utilized them to free up some space on the breadboard.<br />
Connect the GND pin of the sensor to the blue rail on the breadboard (black wire in image below).<br />
Connect the 5V pin of the sensor to the red rail on the breadboard (red wire in image below).<br />
Connect the SIG pin of the sensor to pin 7 of the Arduino (blue wire in image below).</p>
<p><img src="http://www.codingcolor.com/wp-content/uploads/2010/06/ultrasonic_sensor.jpg" alt="" title="ultrasonic_sensor" width="550" height="413" class="aligncenter size-full wp-image-2840" /></p>
<p>If connecting the sensor is all you cared about, you could stop here. All you have left to do is connect the FTDI Cable or FTDI Basic breakout board to the Arduino Pro Mini. Open up the Arduino IDE:<br />
Select Tools -> Serial Port<br />
and select the correct usb port (mac) /dev/tty.usbserial-XXXXXXXX.<br />
Select Tools->Board<br />
and select Lilypad Arduino w/Atmega328 (I&#8217;m running Arduino IDE 018 and for some unknown reason this selection is the only one which enables an upload without errors).<br />
Select File-> Examples->Sensors->Ping<br />
and upload the sketch.<br />
Your done! If you open up the Serial Monitor, it will display the distance being detected from the sensor in inches and cm&#8217;s. </p>
<p>Moving forward, lets add the BlinkM RGB Led. If you read my previous post on the <a href="http://www.codingcolor.com/microcontrollers/using-an-arduino-to-control-a-blinkm-with-a-photocell/" target="blank"><u>BlinkM</u></a> you will be familiar with the process.  If not, grab your BlinkM and lets get familar with it.</p>
<p><img src="http://www.codingcolor.com/wp-content/uploads/2010/06/tm_blinkm_getone.jpg" alt="" title="tm_blinkm_getone" width="300" height="225" class="aligncenter size-full wp-image-2551" /></p>
<p>The BlinkM is a networkable and programmable full-color RGB LED. It has a small AVR micro-controller on board to allow a user to digitally control the LED over a simple I2C interface. The Arduino will communicate with the BlinkM, using the Wire library so we don’t have to worry about the details of I2C. If you haven&#8217;t already checked out the BlinkM <a href="http://thingm.com/products/blinkm/quick-start-guide.html" target="blank"><u>support</u></a> page please do so, it has a bunch of perks you should be aware of. Take a look at the print on the board itself. You will notice PWR and I2C printed directly on the board, take mental note because that&#8217;s what we will be interfacing with shortly.  BlinkM needs two wires for power and two for data. We will be connecting to the Arduino analog pins 4 &#038; 5 which double as the I2C data signal (“SDA”) and clock signal (“SCL”), respectively.</p>
<p>Place the BlinkM onto your breadboard and connect a wire (red wire in image below) from the red rail on the breadboard to the positive (+) symbol printed on the BlinkM. Connect a wire (brown wire in image below) from the blue rail on the breadboard to the ground (-) symbol printed on the BlinkM. </p>
<p><img src="http://www.codingcolor.com/wp-content/uploads/2010/06/blinkm_powered.jpg" alt="" title="blinkm_powered" width="550" height="413" class="aligncenter size-full wp-image-2864" /></p>
<p>Proceed by connecting a wire (blue wire in image below) to analog 4 of the Arduino Pro Mini. Connect the other end of the wire to the ‘d’ (I2C SDA) symbol printed on the BlinkM.<br />
Connect another wire (green wire in image below) to analog 5 of the Arduino Pro Mini. Connect the other end of the wire to the ‘c’ (I2C SCL) symbol printed on the BlinkM.</p>
<p><a href="http://www.codingcolor.com/wp-content/uploads/2010/06/BlinkM_connected.jpg"><img src="http://www.codingcolor.com/wp-content/uploads/2010/06/BlinkM_connected.jpg" alt="" title="BlinkM_connected" width="550" height="413" class="aligncenter size-full wp-image-2867" /></a></p>
<p>Next, lets hook up the 8 ohm mini speaker for audio feedback.<br />
Simply connect the black wire from the speaker to the blue rail of the breadboard. Connect the red wire from the speaker to digital pin 7 on the Arduino Pro Mini.</p>
<p><img src="http://www.codingcolor.com/wp-content/uploads/2010/06/thingamajiggy.jpg" alt="" title="thingamajiggy" width="550" height="404" class="aligncenter size-full wp-image-2870" /></p>
<p>And there you have it. We have completed our simple circuit for an ultra-sonic beeping thingamajiggy.<br />
Lets move onto the code.</p>
<p>The first thing you are going to want to do is connect the FTDI Cable or FTDI Basic breakout board to the Arduino Pro Mini. There are pros and cons to the FTDI Cable vs the FTDI Basic breakout board . The breakout board has TX and RX LEDs that allow you to actually see serial traffic on the LEDs to verify if the board is working, but the board requires a miniB cable. The FTDI Cable is well protected against the elements, but is large and cannot be embedded into a project as easily. The FTDI Basic breakout board uses DTR to cause a hardware reset where the FTDI Cable uses the RTS signal.</p>
<p>I prefer to use the FTDI Basic breakout board to connect to the Arduino pro Mini. Anyhow, connect either the FTDI Cable or Basic breakout board to the Arduino and open up the Arduino IDE.<br />
Select Tools -> Serial Port<br />
and select the correct usb port (mac) /dev/tty.usbserial-XXXXXXXX.<br />
Select Tools->Board<br />
and select Lilypad Arduino w/Atmega328.<br />
Select File->New<br />
and copy the following code to the sketch:<br />
<strong>*NOTE you can download my source below*</strong></p>
<p><code class="codecolorer c mac-classic"><span class="c"><span style="color: #808080; font-style: italic;">/*<br />
Code under (cc) by Manuel Gonzalez, www.codingcolor.com<br />
http://creativecommons.org/license/cc-gpl<br />
Digital pin 7 Parallax Ultrasonic Range Finder<br />
Digital Pin 4 8-ohm mini speaker<br />
Analog pins 4 (SDA),5(SCL) I2C communication with BlinkM<br />
*/</span><br />
<span style="color: #339933;">#include &lt;Wire.h&gt;</span><br />
<span style="color: #339933;">#include &quot;BlinkM_funcs.h&quot;</span><br />
<br />
<br />
<br />
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> pingPin <span style="color: #339933;">=</span> <span style="color: #0000dd;">7</span><span style="color: #339933;">;</span><br />
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> speakerPin <span style="color: #339933;">=</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span><br />
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> blinkm_addr <span style="color: #339933;">=</span> <span style="color: #0000dd;">9</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//address to blinkM</span><br />
byte r<span style="color: #339933;">,</span>g<span style="color: #339933;">,</span>b<span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp;<span style="color: #666666; font-style: italic;">// Serial.begin(9600);</span><br />
&nbsp; pinMode<span style="color: #009900;">&#40;</span>speakerPin<span style="color: #339933;">,</span>OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; BlinkM_beginWithPower<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; BlinkM_stopScript<span style="color: #009900;">&#40;</span>blinkm_addr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//stop the BlinkM </span><br />
&nbsp; BlinkM_setFadeSpeed<span style="color: #009900;">&#40;</span>blinkm_addr<span style="color: #339933;">,</span> <span style="color: #0000dd;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//set up fade param</span><br />
&nbsp; BlinkM_fadeToRGB<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span><span style="color: #208080;">0x00</span><span style="color: #339933;">,</span><span style="color: #208080;">0x00</span><span style="color: #339933;">,</span><span style="color: #208080;">0x00</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//fade all to black</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; <span style="color: #993333;">long</span> duration<span style="color: #339933;">,</span> inches<span style="color: #339933;">;</span><br />
&nbsp; pinMode<span style="color: #009900;">&#40;</span>pingPin<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; digitalWrite<span style="color: #009900;">&#40;</span>pingPin<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; delayMicroseconds<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; digitalWrite<span style="color: #009900;">&#40;</span>pingPin<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; delayMicroseconds<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; digitalWrite<span style="color: #009900;">&#40;</span>pingPin<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; pinMode<span style="color: #009900;">&#40;</span>pingPin<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; duration <span style="color: #339933;">=</span> pulseIn<span style="color: #009900;">&#40;</span>pingPin<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// convert the time into a distance</span><br />
&nbsp; inches <span style="color: #339933;">=</span> microsecondsToInches<span style="color: #009900;">&#40;</span>duration<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #808080; font-style: italic;">/*<br />
&nbsp; Serial.print(inches);<br />
&nbsp; Serial.print(&quot;in, &quot;);<br />
&nbsp; Serial.println(); <br />
&nbsp; */</span><br />
&nbsp; displayColor<span style="color: #009900;">&#40;</span>inches<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">void</span> displayColor<span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> inches<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>inches <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">12</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;r <span style="color: #339933;">=</span> <span style="color: #0000dd;">255</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;g <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;b <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; beep<span style="color: #009900;">&#40;</span>speakerPin<span style="color: #339933;">,</span> <span style="color: #0000dd;">2500</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;r <span style="color: #339933;">=</span> <span style="color: #0000dd;">9</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;g <span style="color: #339933;">=</span> <span style="color: #0000dd;">249</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;b <span style="color: #339933;">=</span> <span style="color: #0000dd;">17</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <br />
&nbsp; &nbsp;BlinkM_fadeToRGB<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> r<span style="color: #339933;">,</span> &nbsp;g<span style="color: #339933;">,</span> &nbsp;b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #993333;">void</span> beep<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> targetPin<span style="color: #339933;">,</span> <span style="color: #993333;">long</span> frequency<span style="color: #339933;">,</span> <span style="color: #993333;">long</span> length<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #993333;">long</span> delayValue <span style="color: #339933;">=</span> <span style="color: #0000dd;">1000000</span><span style="color: #339933;">/</span>frequency<span style="color: #339933;">/</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// calculate the delay value between transitions</span><br />
&nbsp; <span style="color: #993333;">long</span> numCycles <span style="color: #339933;">=</span> frequency <span style="color: #339933;">*</span> length<span style="color: #339933;">/</span> <span style="color: #0000dd;">1000</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// calculate the number of cycles for proper timing</span><br />
&nbsp;<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> numCycles<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; digitalWrite<span style="color: #009900;">&#40;</span>targetPin<span style="color: #339933;">,</span>HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; delayMicroseconds<span style="color: #009900;">&#40;</span>delayValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; digitalWrite<span style="color: #009900;">&#40;</span>targetPin<span style="color: #339933;">,</span>LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; delayMicroseconds<span style="color: #009900;">&#40;</span>delayValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">long</span> microsecondsToInches<span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> microseconds<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// According to Parallax's datasheet for the PING))), there are</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// second). &nbsp;This gives the distance travelled by the ping, outbound</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// and return, so we divide by 2 to get the distance of the obstacle.</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf</span><br />
&nbsp; <span style="color: #b1b100;">return</span> microseconds <span style="color: #339933;">/</span> <span style="color: #0000dd;">74</span> <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></span></code></p>
<p>Take note of the include.<br />
<code class="codecolorer c mac-classic"><span class="c"><span style="color: #339933;">#include &quot;BlinkM_funcs.h&quot;</span></span></code><br />
It&#8217;s a BlinkM Arduino library written by <a href="http://thingm.com/" target="blank">Tod E. Kurt</a>.  You will need the BlinkM_funcs.h library which is also availbe in my download.</p>
<p>Upload the code to your Arduino Pro Mini disconnect the FTDI Cable or Basic breakout board and turn the power on.</p>
<p>If all went well, you should have an ultra-sonic beeping thingamajiggy.</p>
<p><a href="http://www.codingcolor.com/microcontrollers/an-arduino-pro-mini-ultra-sonic-beeping-thingamajiggy/"><em>Click here to view the embedded video.</em></a></p>
<p>Enjoy!<br />
<strong>Download Source:</strong><br />
<a class="downloadlink" href="http://www.codingcolor.com/downloads/UltraSonicBlinkM.zip" title="Version1.0 downloaded 5 times" >Ultra-Sonic beeping thingamajiggy (5)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingcolor.com/microcontrollers/an-arduino-pro-mini-ultra-sonic-beeping-thingamajiggy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Swarming Light</title>
		<link>http://www.codingcolor.com/interactive-art/swarming-light/</link>
		<comments>http://www.codingcolor.com/interactive-art/swarming-light/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 18:26:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[Interactive Art]]></category>
		<category><![CDATA[interactive]]></category>
		<category><![CDATA[Light]]></category>
		<category><![CDATA[rAndom International]]></category>
		<category><![CDATA[Swarm]]></category>
		<category><![CDATA[Swarm Light]]></category>

		<guid isPermaLink="false">http://www.codingcolor.com/?p=2731</guid>
		<description><![CDATA[rAndom International is a creative studio out of London with a mission to develop a new artistic vocabulary. Founded in 2002 by Stuart Wood, Flo Ortkrass and Hannes Koch the studios work fringes on art, design, science and architecture. The studio creates installations that re-interpret the nature of digital-based work and emphasizes on the interaction [...]]]></description>
			<content:encoded><![CDATA[<p>rAndom International is a creative studio out of London with a mission to develop a new artistic vocabulary. Founded in 2002 by Stuart Wood, Flo Ortkrass and Hannes Koch the studios work fringes on art, design, science and architecture. The studio creates installations that re-interpret the nature of digital-based work and emphasizes on the interaction between human presence and the inanimate object, bringing the two into a powerful sense of aesthetic relation.</p>
<p>The ‘Swarm Light‘ is a light installation with a real ‚collective consciousness.  It&#8217;s a contemporary example of how the arbitrary boundaries of fine and decorative art, design and utility are no longer of immediate aesthetic relevance. Sounds or movement captured as light and shadow create a type of participatory and performative synthesis that culminates in an instinctual perception of the space, rather than a cerebral judgment.</p>
<p><object width="550" height="309"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=12525044&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=636363&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=12525044&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=636363&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="550" height="309"></embed></object></p>
<p>Check out more projects by <a href="http://www.random-international.com/projects/" traget="blank"><u>rAndom International</u></a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingcolor.com/interactive-art/swarming-light/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Obscuring network data with base64</title>
		<link>http://www.codingcolor.com/as3/obscuring-network-data-with-base64/</link>
		<comments>http://www.codingcolor.com/as3/obscuring-network-data-with-base64/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 23:18:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.codingcolor.com/?p=2621</guid>
		<description><![CDATA[When meeting with clients and potential employers, I&#8217;m often asked If I have experience working with API&#8217;s (application programming interface). The answer is yes, and then I follow up with, &#8220;Have you reviewed my blog?&#8221;  Just recently, I was asked the API question in an interview and a few minutes later the interviewer wrote [...]]]></description>
			<content:encoded><![CDATA[<p>When meeting with clients and potential employers, I&#8217;m often asked If I have experience working with API&#8217;s (application programming interface). The answer is yes, and then I follow up with, &#8220;Have you reviewed my blog?&#8221;  Just recently, I was asked the API question in an interview and a few minutes later the interviewer wrote this pseudo code on the dry erase board.</p>
<p><code class="codecolorer actionscript3 mac-classic"><span class="actionscript3"><span style="color: #6699cc; font-weight: bold;">var</span> _username<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> _password<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> _apiUrl<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> logIn<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> path<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = _apiUrl <span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;&amp;&quot;</span><span style="color: #000066; font-weight: bold;">+</span>_username <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;&amp;&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> _password<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> request<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLRequest</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span>_path<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
_loader = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLLoader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
_loader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>request<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <br />
<span style="color: #000000;">&#125;</span></span></code></p>
<p>Then proceeded to ask, &#8220;What&#8217;s wrong with this code?&#8221;  Well, I looked over the method and pointed out that the code wasn&#8217;t complete, but the engineer replied, just assume that the syntax is correct and all variables needed are present. The only thing that came to mind, when dealing with API&#8217;s, is that there is usually some type of security measure, usually in the form of a user token or session variable. I felt like I was being tricked, the only other answer I could provide was to encrypt the string to secure the data  passing over the network, and in short, that&#8217;s the answer they were looking for. They should have asked, &#8220;How would you protect the users login data when submitting it to an API?&#8221;  Thanks for the trick question, guys, but as you know almost every API has a different strategy in handling security.</p>
<p>Creating secure SWF applications is not an easy task. The best way to protect your sensitive data is to leverage the HTTPS protocol for sending encrypted data instead of performing the encryption within ActionScript code. Unfortunately, we cant always hide behind HTTPS and It is not advisable to permit HTTP content to access HTTPS content.</p>
<p>There are several strategies to encrypt data in SWF web applications. The most popular are hashing algorithms and symmetric and asymmetric ciphers. Hashing algorithms is a method for performing non-reversible encryption that transforms the original text into a unique string, or hash. The hash is non-reversible, meaning it can not be decrypted and is usually stored on disk. This method is usually used as password authentication and storage. Symmetric and asymmetric ciphers are useful when you want to create a reversible encryption of data, however, the secret and private keys for these tools are usually stored in the SWF, which can be exposed using a decompiler. You can try to hide the key from a decompiler by using a flash obfuscation software, tho I have never implemented this method, I can not advise doing so.</p>
<p>This post is not about Flash security, because I&#8217;m not a security expert, it&#8217;s about base64 encoding. </p>
<p>Exactly what is Base64 encoding? Base64 encoding is a scheme that encodes arbitrary binary data as a string composed from a set of 64 characters. The exact character set can be any 64 distinct ASCII characters, but by far the most common set is &#8220;A&#8221; through &#8220;Z,&#8221; &#8220;a&#8221; through &#8220;z,&#8221; &#8220;0&#8243; through &#8220;9,&#8221; &#8220;+,&#8221; and &#8220;/.&#8221;  Base64 encoding is used by many applications to &#8220;obscure&#8221; data when it travels across the network. Base64 encoding does not implement a cryptographic algorithm to protect sensitive information, yet is often used in many networks and end-user applications to my amazement.</p>
<p>I recently developed a sweepstakes micro-site for a client, which prerequisite was to obscure users personal data over the network. Since base encoding visually hides otherwise easily recognized information, It satisfied the prerequisite, with an understanding that it was not a secure method and the client signed off on it.</p>
<p>I scripted up a quick little demo app which shows you how to use Base64 encoding. </p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_base64example_530344270"
			class="flashmovie"
			width="400"
			height="250">
	<param name="movie" value="http://www.codingcolor.com/wp-content/uploads/2010/06/base64example.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.codingcolor.com/wp-content/uploads/2010/06/base64example.swf"
			name="fm_base64example_530344270"
			width="400"
			height="250">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>The demo gathers the users input, encodes it in a JSON object, encodes the object using base64, and passes it to the server where a php script receives it, decodes the base64 JSON object and then passes it back to the flash app. As you noticed, I may have added a complexity by using JSON. JSON is your friend, the JSON format is often used for serializing  and transmitting structured data over a network connection. It is primarily used to transmit data between a server and web application, serving as an alternative to XML. I have become accustomed to using it over the years, so I just left it in my code, just for clarification you can use a simple string.</p>
<p>Lets take a look at the demo. I created this app in CS4 using the UI flash components. As most flash apps start out, I created a Main document class:</p>
<p><strong>Main.as</strong><br />
<code class="codecolorer actionscript3 mac-classic"><span class="actionscript3"><span style="color: #3f5fbf;">/****************************<br />
* Manuel Gonzalez &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* design@stheory.com &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* www.stheory.com &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* www.codingcolor.com &nbsp; &nbsp; &nbsp; *<br />
*****************************/</span><br />
<span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>Button<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>TextArea<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFieldAutoSize</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFormat</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>stheory<span style="color: #000066; font-weight: bold;">.</span>view<span style="color: #000066; font-weight: bold;">.</span>LoginForm<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>stheory<span style="color: #000066; font-weight: bold;">.</span>business<span style="color: #000066; font-weight: bold;">.</span>LoginProxy<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span><br />
<br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _logInView<span style="color: #000066; font-weight: bold;">:</span>LoginForm<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _logInProxy<span style="color: #000066; font-weight: bold;">:</span>LoginProxy<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _traceField<span style="color: #000066; font-weight: bold;">:</span>TextArea<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _okButton<span style="color: #000066; font-weight: bold;">:</span>Button<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showLoginView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: showLoginView<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> showLoginView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInView = <span style="color: #0033ff; font-weight: bold;">new</span> LoginForm<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInView<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInView<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInView<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span>submitData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_logInView<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: removeLoginView<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> removeLoginView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInView<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span>submitData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInView<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>_logInView<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: submitData<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event:Event<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> submitData<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removeLoginView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createTraceField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> loginObj<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span>=<span style="color: #000000;">&#123;</span>username<span style="color: #000066; font-weight: bold;">:</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span>username<span style="color: #000066; font-weight: bold;">,</span>password<span style="color: #000066; font-weight: bold;">:</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span>password<span style="color: #000066; font-weight: bold;">,</span>remember<span style="color: #000066; font-weight: bold;">:</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span>rememberMe<span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy=LoginProxy<span style="color: #000066; font-weight: bold;">.</span>getInstance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span>logInComplete<span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CANCEL</span><span style="color: #000066; font-weight: bold;">,</span>logInError<span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy<span style="color: #000066; font-weight: bold;">.</span>submitFormData<span style="color: #000000;">&#40;</span>loginObj<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: logInComplete<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event:Event<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> logInComplete<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> results=event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span>scriptResult<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _traceField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=results<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span>logInComplete<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CANCEL</span><span style="color: #000066; font-weight: bold;">,</span>logInError<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> logInError<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> results= event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span>errorEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _traceField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=results<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span>logInComplete<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CANCEL</span><span style="color: #000066; font-weight: bold;">,</span>logInError<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: createTraceField<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createTraceField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _traceField = <span style="color: #0033ff; font-weight: bold;">new</span> TextArea<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _traceField<span style="color: #000066; font-weight: bold;">.</span>setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">350</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _traceField<span style="color: #000066; font-weight: bold;">.</span>move<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">25</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">25</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_traceField<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton = <span style="color: #0033ff; font-weight: bold;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span>=<span style="color: #000000; font-weight:bold;">75</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton<span style="color: #000066; font-weight: bold;">.</span>move<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">300</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">135</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton<span style="color: #000066; font-weight: bold;">.</span>label=<span style="color: #990000;">&quot;OK&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;textFormat&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Arial&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton<span style="color: #000066; font-weight: bold;">.</span>toggle=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> okClick<span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_okButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: okClick<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event:MouseEvent<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> okClick<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removeTraceField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showLoginView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: removeTraceField<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> removeTraceField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span>okClick<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>_traceField<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>_okButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
<br />
<br />
<br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></span></code></p>
<p>The Main.as class simply instantiates a logIn view, logIn proxy and creates a trace/log view to print out the interactions with the server.  I&#8217;m going to skip the logIn view, just assume that all it does is set up the login UI and dispatches an event when the Submit button is pressed. The class that we will focus on is the LogInProxy.as. I utilize <a href="http://dynamicflash.com/goodies/base64/" target="blank"><u>Steve Websters</u></a> base64 encoder/decoder class and the <a href="http://code.google.com/p/as3corelib/" target="blank"><u>AS3CoreLib</u></a> developed by Mike Chambers, Daniel Dura and Christian Cantrell for the JSON encoding.<br />
<strong>LogInProxy.as</strong><br />
<code class="codecolorer actionscript3 mac-classic"><span class="actionscript3"><span style="color: #3f5fbf;">/****************************<br />
* Manuel Gonzalez &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* design@stheory.com &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* www.stheory.com &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* www.codingcolor.com &nbsp; &nbsp; &nbsp; *<br />
*****************************/</span><br />
<span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>stheory<span style="color: #000066; font-weight: bold;">.</span>business<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">EventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IEventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SecurityErrorEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLLoader</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLLoaderDataFormat</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLRequest</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLRequestMethod</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLVariables</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>adobe<span style="color: #000066; font-weight: bold;">.</span>serialization<span style="color: #000066; font-weight: bold;">.</span>json<span style="color: #000066; font-weight: bold;">.</span>JSON<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>utils<span style="color: #000066; font-weight: bold;">.</span>Base64<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LoginProxy <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> static &nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> _instance<span style="color: #000066; font-weight: bold;">:</span>LoginProxy<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _loader<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLLoader</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _formObj<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _encryption<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _path<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;http://www.stheory.com/stheory/downloads/scripts/securityTest.php&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _errorEvent<span style="color: #000066; font-weight: bold;">:*;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _testScriptResult<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> LoginProxy<span style="color: #000000;">&#40;</span>singletonEnforcer<span style="color: #000066; font-weight: bold;">:</span>SingletonEnforcer<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: getInstance<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: AppServices <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static &nbsp;<span style="color: #339966; font-weight: bold;">function</span> getInstance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>LoginProxy <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_instance == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _instance=<span style="color: #0033ff; font-weight: bold;">new</span> LoginProxy<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> SingletonEnforcer &nbsp;<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _instance<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">////////////// Getters ///////////////////////</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> scriptResult<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #990000;">&quot;base64 to server :<span style="">\n</span>&quot;</span> <span style="color: #000066; font-weight: bold;">+</span>_encryption <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span><span style="">\n</span>Results from Server :<span style="">\n</span>&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> _testScriptResult<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> errorEvent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _errorEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//////////////////////////////////////////</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: submitFormData<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;inObj:Object<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> submitFormData<span style="color: #000000;">&#40;</span>inObj<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _formObj = inObj<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; encodeAndEncryptData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: encodeAndEncryptData<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> encodeAndEncryptData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> jStr<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = JSON<span style="color: #000066; font-weight: bold;">.</span>encode<span style="color: #000000;">&#40;</span>_formObj<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _encryption &nbsp;= Base64<span style="color: #000066; font-weight: bold;">.</span>encode<span style="color: #000000;">&#40;</span>jStr<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: sendData<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> sendData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> dataVars<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLVariables</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLVariables</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataVars<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span> = &nbsp;_encryption<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> request<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLRequest</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span>_path<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; request<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">method</span> = <span style="color: #004993;">URLRequestMethod</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">POST</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; request<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span> = dataVars<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _loader = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLLoader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; configureListeners<span style="color: #000000;">&#40;</span>_loader<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">try</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _loader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>request<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">catch</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Error</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Unable to load URL&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _errorEvent = <span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CANCEL</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: configureListeners<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dispatcher:IEventDispatcher<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> configureListeners<span style="color: #000000;">&#40;</span>dispatcher<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">IEventDispatcher</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> completeHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">SecurityErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SECURITY_ERROR</span><span style="color: #000066; font-weight: bold;">,</span> securityErrorHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IO_ERROR</span><span style="color: #000066; font-weight: bold;">,</span> ioErrorHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: removeListeners<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dispatcher:IEventDispatcher<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> removeListeners<span style="color: #000000;">&#40;</span>dispatcher<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">IEventDispatcher</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> completeHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">SecurityErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SECURITY_ERROR</span><span style="color: #000066; font-weight: bold;">,</span> securityErrorHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IO_ERROR</span><span style="color: #000066; font-weight: bold;">,</span> ioErrorHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: completeHandler<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event:Event<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> completeHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> result = _loader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">try</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _testScriptResult = result<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">catch</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Error</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _errorEvent = <span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CANCEL</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removeListeners<span style="color: #000000;">&#40;</span>_loader<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _loader=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: securityErrorHandler<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event:SecurityErrorEvent<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> securityErrorHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">SecurityErrorEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//trace(&quot;securityErrorHandler: &quot; + event + &quot; \n\n&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _errorEvent = event<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CANCEL</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: ioErrorHandler<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event:IOErrorEvent<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> ioErrorHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//trace(&quot;ioErrorHandler: &quot; + event + &quot; \n\n&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _errorEvent = event<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CANCEL</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">internal</span> <span style="color: #9900cc; font-weight: bold;">class</span> SingletonEnforcer <span style="color: #000000;">&#123;</span><br />
<span style="color: #000000;">&#125;</span></span></code></p>
<p>I created the LogInProxy class as a<a href="http://en.wikipedia.org/wiki/Singleton_pattern" target="blank"><u> Singleton pattern</u></a>, because I only want to make one object which will handle the data transaction between the client side and the server. LoginProxy is responsible for  the base64 encoding, it also submits the data and reports the results. Review the encodeAndEncryptData() method:</p>
<p><code class="codecolorer actionscript3 mac-classic"><span class="actionscript3">&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> encodeAndEncryptData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> jStr<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = JSON<span style="color: #000066; font-weight: bold;">.</span>encode<span style="color: #000000;">&#40;</span>_formObj<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _encryption &nbsp;= Base64<span style="color: #000066; font-weight: bold;">.</span>encode<span style="color: #000000;">&#40;</span>jStr<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp;<span style="color: #000000;">&#125;</span></span></code></p>
<p>this is where all the magic happens. You can revise this method to meet your needs, for example remove the option of using JSON and just use a simple string. The SendData method, does what it implies, pretty straight forward. Now, lets take a look at the Php.</p>
<p>The Php script is really simple and was created just for this demo:<br />
<code class="codecolorer php mac-classic"><span class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000088;">$data</span><span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$decoded</span> <span style="color: #339933;">=</span> <span style="color: #990000;">base64_decode</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$decoded</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></span></code></p>
<p>It receives the base64 encoded data, decodes it and prints it back to Flash.  </p>
<p>Now, for a sanity check, I would recommend using a packet sniffer that captures network traffic, like <a href="http://kevinlangdon.com/serviceCapture/"><u>Service Capture</u></a>. Here&#8217;s a screenshot of the demo app in action:</p>
<p><img src="http://www.codingcolor.com/wp-content/uploads/2010/06/packetSniffer.jpg" alt="" title="packetSniffer" width="500" height="404" class="aligncenter size-full wp-image-2717" /></p>
<p>As you can see, we successfully passed an encoded string to the Php script, which in return passed back a JSON object.<br />
Its really that easy! I could have gone the extra mile and re-encoded a response in base64 and had Flash decode it, but I&#8217;ll leave that up to you.<br />
Enjoy!</p>
<p><strong>Download Source:</strong><br />
<a class="downloadlink" href="http://www.codingcolor.com/downloads/base64.zip" title="Version1.0 downloaded 0 times" >Base64 encoding example (0)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingcolor.com/as3/obscuring-network-data-with-base64/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sun Boxes</title>
		<link>http://www.codingcolor.com/inspiration/sun-boxes/</link>
		<comments>http://www.codingcolor.com/inspiration/sun-boxes/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 01:26:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[Inspiration]]></category>
		<category><![CDATA[Craig Colorusso]]></category>
		<category><![CDATA[environment]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[sound]]></category>
		<category><![CDATA[speakers]]></category>
		<category><![CDATA[Sun Boxes]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.codingcolor.com/?p=2614</guid>
		<description><![CDATA[Sun Boxes is an outdoor sound installation created by Boston artist Craig Colorusso.  It&#8217;s comprised of twenty speakers operating independently, each powered by solar panels. There is a different loop set to play a guitar note in each box continuously. These guitar notes collectively make a Bb chord. The sound loops are different in [...]]]></description>
			<content:encoded><![CDATA[<p>Sun Boxes is an outdoor sound installation created by Boston artist <a href="http://muudmusic.blogspot.com/" target="blank"><u>Craig Colorusso</u></a>.  It&#8217;s comprised of twenty speakers operating independently, each powered by solar panels. There is a different loop set to play a guitar note in each box continuously. These guitar notes collectively make a Bb chord. The sound loops are different in length, and continually overlap and slowly evolve over time. Sun Boxes is a perfect composition of technology and environment to help or crazed culture slow down.<br />
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/988tCKKKc_8&#038;hl=en_US&#038;fs=1&#038;rel=0&#038;color1=0x006699&#038;color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/988tCKKKc_8&#038;hl=en_US&#038;fs=1&#038;rel=0&#038;color1=0x006699&#038;color2=0x54abd6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<p><a href="http://www.sun-boxes.com/" target="blank"><strong>www.sun-boxes.com</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingcolor.com/inspiration/sun-boxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
