<?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>Activetuts+ &#187; Mobile</title>
	<atom:link href="http://active.tutsplus.com/category/tutorials/mobile/feed/" rel="self" type="application/rss+xml" />
	<link>http://active.tutsplus.com</link>
	<description>Flash, Flex &#38; ActionScript Tutorials</description>
	<lastBuildDate>Wed, 17 Mar 2010 20:10:32 +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>Create a Unit Converter Application for Flash Lite Enabled Devices</title>
		<link>http://active.tutsplus.com/tutorials/mobile/create-a-unit-converter-application-for-flash-lite-enabled-devices/</link>
		<comments>http://active.tutsplus.com/tutorials/mobile/create-a-unit-converter-application-for-flash-lite-enabled-devices/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 12:00:07 +0000</pubDate>
		<dc:creator>Carlos Yanez</dc:creator>
				<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">http://flash.tutsplus.com/?p=1797</guid>
		<description><![CDATA[<img src="http://flashtuts.s3.cdn.plus.org/087_unitConverter/Preview/Preview.jpg" alt="">]]></description>
			<content:encoded><![CDATA[<p>Flash Lite is an implementation of the Flash runtime for mobile phones, consumer electronic devices, and Internet-connected digital home devices. According to Adobe, the number of Flash Lite shipped devices will reach 1 billion in 2009 and more than 2.5 billion by the end of 2010, so if you are a Flash Developer it is important to know how this technology works and how it  differs from Flash Player for the desktop.</p>
<p>In this tutorial I&#8217;ll guide you through the basics of Flash Lite using the 1.1 version; sacrificing features, but ensuring compatibility.</p>
<p><span id="more-1797"></span></p>
<div class="tutorial_image">
<a href="http://flashtuts.s3.cdn.plus.org/087_unitConverter/Src.zip" target="_blank"><br />
<img src='http://flashtuts.s3.cdn.plus.org/source.jpg' alt="" style="border:none"></a><br />
<a href="http://flashtuts.s3.cdn.plus.org/087_unitConverter/Src/preview.html" target="_blank"><br />
<img src='http://flashtuts.s3.cdn.plus.org/demo.jpg' alt="" style="border:none"></a>
</div>
<p>Nokia N70 Black Edition Icon by <a href="http://www.vecteezy.com/vf/544-Nokia-N70-Black-Edition" target="_blank">Ito</a></p>
<h2>Step 1: Brief Overview</h2>
<p>Using basic ActionScript 1.0 we&#8217;ll create a Unit Converter application that can be run in almost any Flash Lite enabled device.</p>
<h2>Step 2: Flash Lite Basics</h2>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/087_unitConverter/Tutorial/1.jpg" alt="" /></div>
<p><b>So what is Flash Lite anyway?</b> As i mentioned before, Flash Lite is an implementation of the Flash runtime for devices. It runs on different mobile platforms such as Symbian, Brew, Windows Mobile, Android and more.</p>
<p><b>How do I know which devices can I create content for?</b> You can visit the official Adobe<a href="http://www.adobe.com/mobile/supported_devices/"> supported devices</a> page or you can update the Online Library in Adobe Device Central.</p>
<p><b>How can I implement Flash Lite?</b> There are several ways to implement Flash Lite content; you can create standalone applications, animated wallpapers, screensavers, or display content in the device browser.</p>
<p><b>How many versions are of Flash Lite?</b> There are 3 major versions, 1.1, 2.1 and 3.1. You can check the features of the releases in the Adobe <a href="http://www.adobe.com/products/flashlite/version/">version comparison</a> page.</p>
<p><b>Which tools do I need to start developing for Flash Lite?</b> You just need a version of Flash Professional (8+) which includes device central (CS3+).</p>
<h2>Step 3: Setting up</h2>
<p>Open Flash and create a new Flash File (Mobile).</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/087_unitConverter/Tutorial/2.jpg" alt="" /></div>
<p>Device Central will automatically open and you will have to select a device or a matching size preset. To choose a device just browse the online library and drag it into the device sets panel.</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/087_unitConverter/Tutorial/3.jpg" alt="" /></div>
<p>Be sure to select the 1.1 player version in the top of the Device Central window. When you&#8217;re done click the create button.</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/087_unitConverter/Tutorial/4.jpg" alt="" /></div>
<h2>Step 4: Interface</h2>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/087_unitConverter/Tutorial/5.jpg" alt="" /></div>
<p>The  interface for our app is very simple. As you can see there are two textfields, one to convert from, and one to display the converted amount. Then there is a panel which shows us the names of the units we&#8217;re converting and right next to it is a list of units that we can choose to convert.</p>
<p>Finally, in the bottom of the screen, two textfields indicate the options and the exit button.</p>
<h2>Step 5: Adding Interactivity</h2>
<p>Now that we&#8217;ve designed our interface, it&#8217;s time to make it dynamic. Let&#8217;s start by adding the instance names to the textfields.</p>
<p>In Flash Lite 1.1 instance names are not supported in TextFields, so we set a Variable name in the Properties panel, Options section. Look at the image below to see where TextFields are created and where to enter its Variable name, remember that these are dynamic TextFields.</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/087_unitConverter/Tutorial/6.jpg" alt="" /></div>
<p>You&#8217;ll notice that the bottom text is dynamic too, this is to be able to embed the characters to display them clearly. It&#8217;s worth noting that using embedded fonts will increase the file size of the final document.</p>
<h2>Step 6: Options Panel</h2>
<p>The options panel will let the user choose which units to convert.</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/087_unitConverter/Tutorial/7.jpg" alt="" /></div>
<p>Create your options panel design and convert it to a MovieClip, name it &quot;options&quot; and  place it. No need for Variable names in the TextFields.</p>
<h2>Step 7: Full Screen</h2>
<p>ActionScript time!</p>
<p>The following code will use the Flash Lite specific element &#8220;fscommand2&#8243; to make the application go full screen at launch. Open the Actions Panel and write:</p>
<pre name="code" class="javascript">
fscommand2("FullScreen", true);</pre>
<h2>Step 8: SoftKeys</h2>
<p>A device&#8217;s soft keys are multifunctional keys that use the device&#8217;s display to identify their purpose at any moment. They only display when the application <em>isn&#8217;t</em> in full screen mode, but I&#8217;ll show you how to set them anyway.</p>
<pre name="code" class="javascript">
fscommand2(&quot;SetSoftKeys&quot;, &quot;Options&quot;, &quot;Exit&quot;);
</pre>
<p name="code" class="javascript">These keys are handled by &quot;PageUp&quot; key constant for the left, and &quot;PageDown&quot; constant for the right.</p>
<h2>Step 9: Options</h2>
<p>This code will hide the Options Panel.</p>
<pre name="code" class="javascript">
options._visible = false;
</pre>
<p>As the panel will be activated and deactivated with the same key, we&#8217;ll set a variable to check if it&#8217;s visible or not.</p>
<pre name="code" class="javascript">
pressed = false;
</pre>
<h2>Step 10: Default Values</h2>
<p>We have to set a default conversion unit to handle when the user presses the conversion key without changing the units in the Options Panel.</p>
<pre name="code" class="javascript">from = &quot;in&quot;;
to = &quot;cm&quot;;
</pre>
<p>Remember that these are the names of the variables we set to the textfields, which will be checked later in the code when the user presses the conversion key.</p>
<h2>Step 11: KeyCatcher</h2>
<p>A keyCatcher or keyListener is a Button symbol that listens for key events. This keyCatcher will handle all the key related actions of our application.</p>
<p>Create a button with anything inside and place it out of stage. You can create a text button as I did:</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/087_unitConverter/Tutorial/8.jpg" alt="" /></div>
<h2>Step 12: SoftKeys Actions</h2>
<p>Open the Actions Panel with the keyCatcher button selected to add the code.</p>
<p>By default, the right softKey function is to exit the application, so you can avoid writing the code for it. In any case, this would be the code:</p>
<pre name="code" class="javascript">
on (keyPress "PageDown")
{
	fscommand2(&quot;Quit&quot;);
}</pre>
<p>
And this is the code for the left softKey. It checks for the &quot;pressed&quot; variable and sets the options panel to visible or invisible.</p>
<pre name="code" class="javascript">on (keyPress &quot;&lt;PageUp&gt;&quot;)
{
	if(!pressed)
	{
		pressed = true;
		options._visible = true;
	}
	else
	{
		pressed = false;
		options._visible = false;
	}
}</pre>
<h2>Step 13: Moving the Selection</h2>
<p>This code will check if the options panel is visible and move the gray bar when the up or down keys are pressed.</p>
<pre name="code" class="javascript">
on (keyPress "< Up >")
{
	if(pressed &#038;&#038; options.select._y != 0)
	{
		options.select._y -= 20;
	}
}

on (keyPress "< Down >")
{
	if(pressed &#038;&#038; options.select._y != 80)
	{
		options.select._y += 20;
	}
}</pre>
<h2>Step 14: Choosing a Menu Item</h2>
<p>The following lines will check for the position of the gray bar and the Enter key (the center button of the navigation keys), set the corresponding values to the variables and hide the menu when done.</p>
<pre name="code" class="javascript">on (keyPress &quot;&lt;Enter&gt;&quot;)
{
	if(pressed &amp;&amp; options.select._y == 0)
	{
		fromGraphic = &quot;in&quot;;
		toGraphic = &quot;cm&quot;;

		pressed = false;
		options._visible = false;
	}

	if(pressed &amp;&amp; options.select._y == 20)
	{
		fromGraphic = &quot;m2&quot;;
		toGraphic = &quot;cm2&quot;;

		pressed = false;
		options._visible = false;
	}

	if(pressed &amp;&amp; options.select._y == 40)
	{
		fromGraphic = &quot;gal&quot;;
		toGraphic = &quot;l&quot;;

		pressed = false;
		options._visible = false;
	}

	if(pressed &amp;&amp; options.select._y == 60)
	{
		fromGraphic = &quot;kW&quot;;
		toGraphic = &quot;W&quot;;

		pressed = false;
		options._visible = false;
	}

	if(pressed &amp;&amp; options.select._y == 80)
	{
		fromGraphic = &quot;kg&quot;;
		toGraphic = &quot;lb&quot;;

		pressed = false;
		options._visible = false;
	}</pre>
<h2>Step 15: Conversion</h2>
<p>This code goes inside the last &quot;on&quot; event, it checks the actual value of the conversion variable and performs the neccessary operation. Remember that as the variables changes their value, so are the TextFields.</p>
<pre name="code" class="javascript">
if(!pressed)
	{
		switch(fromGraphic)
		{
			case "in":
				from = "in";
				to = "cm";

				toNumber = fromNumber * 2.54;
				break;
			case "m2":
				from = "m2";
				to = "cm2";

				toNumber = fromNumber * 10000;
				break;
			case "gal":
				from = "gal";
				to = "l";

				toNumber = fromNumber * 3.78;
				break;
			case "kW":
				from = "kW";
				to = "W";

				toNumber = fromNumber * 1000;
				break;
			case "kg":
				from = "kg";
				to = "lb";

				toNumber = fromNumber * 2.20;
				break;
		}
	}
}</pre>
<h2>Step 16: Keys</h2>
<p>In order to write in the &quot;fromNumber&quot; textfield we add an &quot;on&quot; event to handle the number keys.</p>
<pre name="code" class="javascript">
on (keyPress "1")
{
	fromNumber = fromNumber add "1";
}

on (keyPress "2")
{
	fromNumber = fromNumber add "2";
}

on (keyPress "3")
{
	fromNumber = fromNumber add "3";
}

on (keyPress "4")
{
	fromNumber = fromNumber add "4";
}

on (keyPress "5")
{
	fromNumber = fromNumber add "5";
}

on (keyPress "6")
{
	fromNumber = fromNumber add "6";
}

on (keyPress "7")
{
	fromNumber = fromNumber add "7";
}

on (keyPress "8")
{
	fromNumber = fromNumber add "8";
}

on (keyPress "9")
{
	fromNumber = fromNumber add "9";
}

on (keyPress "0")
{
	fromNumber = fromNumber add "0";
}

on (keyPress "*")
{
	fromNumber = substring(fromNumber, 0, length(fromNumber) -1); //This will delete the last number in the field
}</pre>
<h2>Step 17: Test</h2>
<p>Now you&#8217;re ready to test your movie!</p>
<p>Press cmd+return and Device Central will be opened. You can test the application pressing the keys on the test device and see if everything works as expected, if you are finished in the emulator, it&#8217;s time to test your file in the actual device!</p>
<h2>Conclusion</h2>
<p>Be sure to test every aspect and add more functionality to you application, you have a lot of posibilities. Here are some useful links for learning more about the world of Flash Lite:</p>
<ul>
<li><a href="http://sw.nokia.com/id/80560a20-1fb3-4e0c-9842-1dde5c6cc3b1/Flash_Lite_Visual_Guide_v1_0_en.pdf">Flash Lite Visual Guide</a>.</li>
<li><a href="http://www.forum.nokia.com/info/sw.nokia.com/id/0a558dff-46c9-4f30-8a44-3211f7c06118/Flash_Lite_Tips_and_Tricks_v1_0_en.pdf.html">Flash Lite Optimization</a>.</li>
</ul>
<p>I hope you liked this tut!</p>
]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/mobile/create-a-unit-converter-application-for-flash-lite-enabled-devices/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.170 seconds -->
