<?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>Flash, Flex and ActionScript tutorials - flashadvanced &#187; currency converter</title>
	<atom:link href="http://flashadvanced.com/tag/currency-converter/feed/" rel="self" type="application/rss+xml" />
	<link>http://flashadvanced.com</link>
	<description>Become an advanced actionscript developer</description>
	<lastBuildDate>Sun, 30 Jan 2011 21:10:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AS3 Currency Converter</title>
		<link>http://flashadvanced.com/as3-currency-converter/</link>
		<comments>http://flashadvanced.com/as3-currency-converter/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 14:16:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Advanced ActionScript 3]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[components]]></category>
		<category><![CDATA[currency converter]]></category>
		<category><![CDATA[DataProvider]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[list component]]></category>
		<category><![CDATA[TextInput]]></category>

		<guid isPermaLink="false">http://flashadvanced.com/?p=410</guid>
		<description><![CDATA[In this tutorial I will show you how to create a Currency Converter using ActionScript 3 and Flash Components. The calculations are made in runtime, no button clicks needed! 1. Open a new Flash document and save it under &#8220;CurrencyConverter.fla&#8221;. Set the document size to 400 x 250 pixels and for color choose #CCCCCC. 2. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flashadvanced.com/?p=410"><br />
<img src="http://flashadvanced.com/wp-content/upload/converter/converter.jpg" /><br />
</a></p>
<p>In this tutorial I will show you how to create a Currency Converter using ActionScript 3 and Flash Components. The calculations are made in runtime, <strong>no button clicks needed</strong>!</p>
<p><span id="more-410"></span></p>
<p><span style="color: #ff0000;">1.</span> Open a new Flash document and save it under &#8220;CurrencyConverter.fla&#8221;. Set the document size to 400 x 250 pixels and for color choose #CCCCCC.</p>
<p><span style="color: #ff0000;">2.</span> Open the Components Panel by clicking Window -> Copmponents and drag two <strong>List Components</strong>. Make them 145px wide by 100px high. Give the first List component instance name &#8220;fromList&#8221; and the second &#8220;toList&#8221;.</p>
<p><span style="color: #ff0000;">3.</span> Go to the Components Panel again and drag a <strong>TextInput</strong> component. For instance name type &#8220;input_txt&#8221;. Position the TextInput somewhere over the first List component.</p>
<p><span style="color: #ff0000;">4.</span> Take the <strong>Text Tool</strong> and create a dynamic text field somewhere over the second List component. Give the text field instance name &#8220;result_txt&#8221;. Set its properties like this:</p>
<p><img src="http://flashadvanced.com/wp-content/upload/converter/text.jpg" /></p>
<p>I think you got the idea. The user types the amount in the TextInput and selects the currency that he would like to convert from. The result appears in the &#8220;result_txt&#8221; text field.</p>
<p><img src="http://flashadvanced.com/wp-content/upload/converter/structure.jpg" /></p>
<p><span style="color: #ff0000;">5.</span> We are now ready and have to go to ActionScript. Create a new layer called &#8220;actions&#8221; and open the Actions Panel.</p>
<pre><code>
//importing DataProvider class
import fl.data.DataProvider;

//creating a new data provider object
var dp:DataProvider = new DataProvider();
//first we create a variable to store the first value
var fromVal:Number;
//then we create a variable for the second value
var toVal:Number;
//here we store what the user inputs
var inputVal:Number
//the result value
var calculatedVal:Number;
//the user can enter only numbers in the TextInput
input_txt.restrict = "0-9";

//adding items to the Data Provider. The user sees the "label" property.
//For data we set the currency weight. US dollar has weight 1.
//The others are in proportion to US Dollar
dp.addItem( { label: "U.S. Dollars", data:1 });
dp.addItem( { label: "Australian Dollars", data: 0.832114 });
dp.addItem( { label: "Canada Dollars", data: 0.926215 } );
dp.addItem( { label: "Euro", data:1.42643 });
dp.addItem( { label: "United Kingdom Pounds", data:1.65151 });
dp.addItem( { label: "India Rupees", data:0.0207573 });
dp.addItem( { label: "Poland Zlotych", data:0.341955 });
dp.addItem( { label: "Russia Rubles", data:0.0325614 });
dp.addItem( { label: "Philippines Pesos", data:0.02079 });
dp.addItem( { label: "Bulgarian Leva", data:0.729733 });
dp.addItem( { label: "Brazil Reais", data:0.531719 });

//populating the lists
fromList.dataProvider = dp;
toList.dataProvider = dp;

//adding Event Change listeners to all of the components
fromList.addEventListener(Event.CHANGE, calculateResult);
toList.addEventListener(Event.CHANGE, calculateResult);
input_txt.addEventListener(Event.CHANGE, calculateResult);
//we set items that are set by default
fromList.selectedIndex = 0;
toList.selectedIndex = 3;

//initializing "fromVal" and "toVal"
fromVal = fromList.selectedItem.data;
toVal = toList.selectedItem.data;

function calculateResult(e:Event):void{
	fromVal = fromList.selectedItem.data;
	toVal = toList.selectedItem.data;
	//casting String to Number
	inputVal = Number(input_txt.text);
	//calculating the result
	calculatedVal = inputVal * (fromVal / toVal);
	//adding the result to the text field
	result_txt.text = calculatedVal.toString();
}
</pre>
<p></code></p>
<h4>Here is the final result:</h4>
<p><object width="400" height="250"><param name="movie" value="http://flashadvanced.com/wp-content/upload/converter/CurrencyConverter.swf"><embed src="http://flashadvanced.com/wp-content/upload/converter/CurrencyConverter.swf" width="400" height="250"></embed></object></p>
<p style="text-align: left; margin: 40px 40px 40px 0;"><a href="http://www.flashadvanced.com/wp-content/upload/converter/converter.zip"><img src="http://flashadvanced.com/wp-content/upload/other/download.jpg" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashadvanced.com/as3-currency-converter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

