<?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 and ActionScript tutorials - flashadvanced &#187; list component</title>
	<atom:link href="http://flashadvanced.com/tag/list-component/feed/" rel="self" type="application/rss+xml" />
	<link>http://flashadvanced.com</link>
	<description>Become an advanced flash developer</description>
	<lastBuildDate>Mon, 11 Jan 2010 22:14:13 +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/advanced-actionscript-3/as3-currency-converter/</link>
		<comments>http://flashadvanced.com/advanced-actionscript-3/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. Open the [...]]]></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/advanced-actionscript-3/as3-currency-converter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Flash CS3 components, Part 1</title>
		<link>http://flashadvanced.com/actionscript-3-basics/using-flash-cs3-components-part-1/</link>
		<comments>http://flashadvanced.com/actionscript-3-basics/using-flash-cs3-components-part-1/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 21:21:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript 3.0 Basics]]></category>
		<category><![CDATA[components]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[list component]]></category>
		<category><![CDATA[ListEvent]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://flashadvanced.com/?p=295</guid>
		<description><![CDATA[


In this collection of tutorials I will show you the power of the Flash CS3 components and how to use them in the best way.
I am going to start with the List component. I will show you how to easily populate XML data into the List.

The Flash components are very useful, powerful and easy to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flashadvanced.com/?p=295"><br />
<img src="http://flashadvanced.com/wp-content/upload/components/comp1.jpg" alt="" /><br />
</a></p>
<p>In this collection of tutorials I will show you the power of the Flash CS3 <strong>components</strong> and how to use them in the best way.<br />
I am going to start with the <strong>List component</strong>. I will show you how to easily <strong>populate XML data</strong> into the List.</p>
<p><span id="more-295"></span></p>
<p>The Flash components are very useful, powerful and easy to customize. Some of them are ComboBox, CheckBox, DataGrid and so on. You can see them in the Components panel by clicking Window -&gt; Components. Now I will show you the best and the fastest way,  in my opinion, to <strong>populate data from an XML file</strong>. We&#8217;ll be using the List component. The List component is a scrollable single- or multiple-selection list box. To add an item to the List you can use addItem() and addItemAt() methods. A List item has two properties: label and data.<br />
Let&#8217;s get started with the example.</p>
<p><span style="color: #ff0000;">1.</span> Open a new Flash CS3 document and save it under &#8220;listXML.fla&#8221;. Set the size to 250 x 350 and for background color choose #CCCCCC. On the top of the document create a static text field and write &#8220;My favourite movies list&#8221;.<br />
<span style="color: #ff0000;">2.</span> Go to the Components panel by clicking Window -&gt; Components and drag a List component on the stage. Make it 250px wide by 300px high. Give it an instance name &#8220;xmlList&#8221;.<br />
<span style="color: #ff0000;">3.</span> Now let&#8217;s create a new XML file. I made an XML with my favourite movies. You can copy it or you can list your favourite movies.</p>
<pre><code>
&lt;?xml version = "1.0" encoding = "UTF-8"?&gt;
&lt;data&gt;
  &lt;movies&gt;
    &lt;movie&gt;
      &lt;title&gt;The Shawshank Redemption&lt;/title&gt;
      &lt;link&gt;http://www.imdb.com/title/tt0111161/&lt;/link&gt;
   &lt;/movie&gt;
   &lt;movie&gt;
     &lt;title&gt;The Godfather&lt;/title&gt;
     &lt;link&gt;http://www.imdb.com/title/tt0068646/&lt;/link&gt;
  &lt;/movie&gt;
  &lt;movie&gt;
    &lt;title&gt;Lock, stock and two smoking barrels&lt;/title&gt;
    &lt;link&gt;http://www.imdb.com/title/tt0120735/&lt;/link&gt;
  &lt;/movie&gt;
  &lt;movie&gt;
    &lt;title&gt;I am Sam&lt;/title&gt;
    &lt;link&gt;http://www.imdb.com/title/tt0277027/&lt;/link&gt;
  &lt;/movie&gt;
  &lt;movie&gt;
    &lt;title&gt;Oldboy&lt;/title&gt;
    &lt;link&gt;http://www.imdb.com/title/tt0364569/&lt;/link&gt;
  &lt;/movie&gt;
  &lt;movie&gt;
    &lt;title&gt;Training day&lt;/title&gt;
    &lt;link&gt;http://www.imdb.com/title/tt0139654/&lt;/link&gt;
  &lt;/movie&gt;
  &lt;movie&gt;
    &lt;title&gt;Live flesh&lt;/title&gt;
    &lt;link&gt;http://www.imdb.com/title/tt0118819/&lt;/link&gt;
  &lt;/movie&gt;
  &lt;movie&gt;
    &lt;title&gt;Liar Liar&lt;/title&gt;
    &lt;link&gt;http://www.imdb.com/title/tt0119528/&lt;/link&gt;
  &lt;/movie&gt;
  &lt;movie&gt;
    &lt;title&gt;Carlito's way&lt;/title&gt;
    &lt;link&gt;http://www.imdb.com/title/tt0106519/&lt;/link&gt;
  &lt;/movie&gt;
  &lt;movie&gt;
    &lt;title&gt;Blow&lt;/title&gt;
    &lt;link&gt;http://www.imdb.com/title/tt0221027/&lt;/link&gt;
  &lt;/movie&gt;
  &lt;movie&gt;
    &lt;title&gt;The bank job&lt;/title&gt;
    &lt;link&gt;http://www.imdb.com/title/tt0200465/&lt;/link&gt;
  &lt;/movie&gt;
  &lt;movie&gt;
    &lt;title&gt;Big fish&lt;/title&gt;
    &lt;link&gt;http://www.imdb.com/title/tt0319061/&lt;/link&gt;
  &lt;/movie&gt;
  &lt;movie&gt;
    &lt;title&gt;25th hour&lt;/title&gt;
    &lt;link&gt;http://www.imdb.com/title/tt0307901/&lt;/link&gt;
  &lt;/movie&gt;
  &lt;movie&gt;
    &lt;title&gt;Scarface&lt;/title&gt;
    &lt;link&gt;http://www.imdb.com/title/tt0086250/&lt;/link&gt;
  &lt;/movie&gt;
  &lt;movie&gt;
    &lt;title&gt;Alfie&lt;/title&gt;
    &lt;link&gt;http://www.imdb.com/title/tt0375173/&lt;/link&gt;
  &lt;/movie&gt;
  &lt;/movies&gt;
&lt;/data&gt;
</code></pre>
<p>Save the file under &#8220;list.xml&#8221;. It should be in the same directory as the .fla file.</p>
<p>The main idea is to populate the XML data into a List component and then set a List event.  On <strong>double click</strong> we will navigate to the movie presentation on <a href="http://imdb.com">IMDB</a> (Internet Movie DataBase) site. </p>
<p><span style="color: #ff0000;">4.</span> Go back to Flash and create a new layer called &#8220;actions&#8221;. Open the Actions Panel.</p>
<pre><code>
//we need a ListEvent for our List
import fl.events.ListEvent;

//we create a variable to store the loaded XML
var xml:XML;
//the path to the xml file
var xmlPath:String = "list.xml";
//we create a loader and when the loading is over we call the xmlLoaded function
var loader:URLLoader = new URLLoader();
//a url request for our loader
var req:URLRequest = new URLRequest(xmlPath);
loader.addEventListener(Event.COMPLETE, xmlLoaded);
loader.load(req);

//adding a double click event handler to the list
xmlList.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, itemDoubleClicked)

function xmlLoaded(event:Event):void{
	//this will be the List item object
	var item:Object;
	xml = new XML(event.target.data);

	//looping through the XML nodes
	for each(var movieItem:XML in xml.movies.movie){
		//creating a new item object
		item = new Object();
		//the part that the user sees
		item.label = movieItem.title.toString();
		//we store the URL for every movie presentation
		item.data = movieItem.link.toString();
		//we add the items to the List
		xmlList.addItem(item);
	}
}

function itemDoubleClicked(event:ListEvent):void{
	//here we store the selected item's link
	var linkTo:String = xmlList.selectedItem.data.toString();
	//on double click we navigate to the movie presentation
	navigateToURL(new URLRequest(linkTo));
}
</code></pre>
<p>That was all!</p>
<h4>See how it looks:</h4>
<p><object width="250" height="350"><param name="movie" value="http://flashadvanced.com/wp-content/upload/components/listXML.swf"><embed src="http://flashadvanced.com/wp-content/upload/components/listXML.swf" width="250" height="350"></embed></object></p>
<p style="text-align: left; margin: 40px 40px 40px 0;"><a href="http://www.flashadvanced.com/wp-content/upload/components/listXML.zip"><img src="http://flashadvanced.com/wp-content/upload/other/download.jpg" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashadvanced.com/actionscript-3-basics/using-flash-cs3-components-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
