<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="http://feedproxy.google.com/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feedproxy.google.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>The Tech Labs » XML</title>
	
	<link>http://www.thetechlabs.com</link>
	<description>Adobe Air, Flash and Flex Tutorials</description>
	<pubDate>Thu, 23 Oct 2008 22:58:12 +0000</pubDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feedproxy.google.com/TheTechLabs_xml" type="application/rss+xml" /><item>
		<title>Simulating PicLens with Flex and Away3D – Part 3</title>
		<link>http://feedproxy.google.com/~r/TheTechLabs_xml/~3/7_m_KGon7n0/</link>
		<comments>http://www.thetechlabs.com/xml/simulating-piclens-with-flex-and-away3d-%e2%80%93-part-3/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 22:57:17 +0000</pubDate>
		<dc:creator>Alejandro Santander</dc:creator>
		
		<category><![CDATA[3D]]></category>

		<category><![CDATA[Flex]]></category>

		<category><![CDATA[Interfaces]]></category>

		<category><![CDATA[Latest]]></category>

		<category><![CDATA[XML]]></category>

		<category><![CDATA[adobe flash]]></category>

		<category><![CDATA[adobe flex]]></category>

		<category><![CDATA[as3]]></category>

		<category><![CDATA[Away3D]]></category>

		<category><![CDATA[caurina]]></category>

		<category><![CDATA[loading images]]></category>

		<category><![CDATA[oop]]></category>

		<category><![CDATA[photo viewer]]></category>

		<category><![CDATA[PicLens]]></category>

		<category><![CDATA[planes]]></category>

		<category><![CDATA[scene]]></category>

		<category><![CDATA[skinning]]></category>

		<category><![CDATA[tutorial]]></category>

		<category><![CDATA[tweener]]></category>

		<category><![CDATA[web-design]]></category>

		<category><![CDATA[web-development]]></category>

		<guid isPermaLink="false">http://www.thetechlabs.com/?p=121</guid>
		<description><![CDATA[<p>Step by step guide for creating a PicLens type 3D photo viewer with Flex and Away3d. This is step 3, of a 3 part tutorial that will sweep many useful techniques used in web application design, Flex, and Flash 3D design.</p>
<small><em>posted in <a href="http://www.thetechlabs.com/category/3d/">3D</a> by Alejandro Santander <a href="http://www.thetechlabs.com/xml/simulating-piclens-with-flex-and-away3d-%e2%80%93-part-3/#comments">Leave A Comment</a><br />&copy;2008 <a href="http://www.thetechlabs.com">The Tech Labs</a>. All Rights Reserved.</em></small>]]></description>
			<content:encoded><![CDATA[<p>Step by step guide for creating a PicLens type 3D photo viewer with Flex and Away3d. This is step 3, of a 3 part tutorial that will sweep many useful techniques used in web application design, Flex, and Flash 3D design. You will make <a title="See the final Application" href="http://thetechlabs.com/tutorials/files/flex/asantander/PicLensAway3D/Final/Demos/Finished/"  target="_blank">this</a>.</p>
<p><strong>Requirements:</strong></p>
<ul>
<li><a title="Try / Buy Adobe Flash CS3" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.adobe.com/products/flash/');" href="http://www.adobe.com/products/flash/" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.adobe.com/products/flash/');" target="_blank">Adobe Flash CS3</a></li>
<li><a title="Try / Buy Adobe Flex Builder 3" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.adobe.com/products/flex/?promoid=BPDEQ');" href="http://www.adobe.com/products/flex/?promoid=BPDEQ" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.adobe.com/products/flex/?promoid=BPDEQ');" target="_blank">Adobe Flex Builder 3</a></li>
<li><a title="Download Away3D Library" onclick="javascript:pageTracker._trackPageview('downloads/tutorials/files/flex/asantander/PicLensAway3D/Final/Downloads/away3d.zip');" href="http://www.thetechlabs.com/tutorials/files/flex/asantander/PicLensAway3D/Final/Downloads/away3d.zip" onclick="javascript:pageTracker._trackPageview('downloads/tutorials/files/flex/asantander/PicLensAway3D/Final/Downloads/away3d.zip');" target="_blank">Away3d Library</a> (I recommend using the version I used)</li>
<li><a title="Download Tweener Library" onclick="javascript:pageTracker._trackPageview('downloads/tutorials/files/flex/asantander/PicLensAway3D/Final/Downloads/caurina.zip');" href="http://www.thetechlabs.com/tutorials/files/flex/asantander/PicLensAway3D/Final/Downloads/caurina.zip" onclick="javascript:pageTracker._trackPageview('downloads/tutorials/files/flex/asantander/PicLensAway3D/Final/Downloads/caurina.zip');" target="_blank">Tweener Library</a></li>
<li><a title="Download Source Files" onclick="javascript:pageTracker._trackPageview('downloads/tutorials/files/flex/asantander/PicLensAway3D/Final/Sources/Part1.zip');" href="http://www.thetechlabs.com/tutorials/files/flex/asantander/PicLensAway3D/Final/Sources/Finished.zip" onclick="javascript:pageTracker._trackPageview('downloads/tutorials/files/flex/asantander/PicLensAway3D/Final/Sources/Finished.zip');" target="_blank">Source Files</a></li>
</ul>
<p><strong>Pre Requisites:</strong></p>
<ul>
<li>Having done Part 1 and 2 of this tutorial.</li>
<li>Intermediate programming skills.</li>
<li>Moderate knowledge of AS3.</li>
<li>Basic Familiarity with OOP.</li>
<li>Basic knowledge of Flash CS3.</li>
</ul>
<p style="text-align: center;"><img class="aligncenter" src="http://www.thetechlabs.com/wp-content/uploads/2008/09/image0011.jpg" alt="Pic Lens" width="541" height="196" /></p>
<h3>Step 0:</h3>
<p>This is the last section of the tutorial we’ve been working on. We’re going to wrap up everything we’ve done so far and make our work a solid, working application, which we can use and even extend in the future. First, we will centralize all arbitrary parameters into what’s known as a model, then, we’re going to connect the photo gallery into an external xml so we can load images dynamically, and finally we’re going to enhance our graphics a little bit by adding a reflection effect to the 3D scene.</p>
<h3>Step 1 – Centralizing data:</h3>
<p>As I stated before, we will start by creating a place holder for all arbitrary variables used so far. With arbitrary variables I mean values that we’ve chosen such as the camera’s tween time in the “moveTo()” method within CameraController, or the Z position of the cameraTarget that can greatly affect the nature of the camera’s motion. All these will be placed in a class that will hold these static constants and will also be used to hold dynamic variables further on, so they can be accessed easily from anywhere in the application. So, go ahead and create a new folder next to “view” called “model”. In it, create a new Actionscript Class called “Model.as”.</p>
<p>Now, I need you to work alone for a while. The job to do is recognise all the values you have used so far throughout the application, that you think would be a good idea to name into a variable and control from this central class. Then, all these variables will be declared in Model.as as static constants. This is how my class looks after doing just that:</p>
<pre>package  com.li.photoviewer.model

{ 

     public class Model

     {

          public static const  CAMERA_Z:Number = -2000;

          public static const  CAMERA_Z_ZOOMED:Number = -1500;

          public static const  CAMERA_ZOOM_TIME:Number = 1;

          public static const  CAMERA_ZOOM_EASE:String = "easeoutexpo";

          public static const  CAMERATARGET_FRICTION:Number = 0.95;

          public static const  CAMERATARGET_BOUNCE_FACTOR:Number = 0.5;

          public static const  CAMERATARGET_DRAG_FACTOR:Number = 0.1;

          public static const CAMERATARGET_SPEED_FACTOR:Number  = 0.05;

          public static const  CAMERATARGET_Z:Number = -100;

          public static const  CAMERATARGET_MOVETO_TIME:Number = 1;

          public static const  CAMERATARGET_MOVETO_EASE:String = "easeoutexpo";

          public static const  PHOTO_PLANE_SEGMENTS:Number = 3;

          public static const  PHOTO_MATERIAL_SMOOTH:Boolean = true;

          public static const  PHOTO_FADEIN_TIME:Number = 0.25;

          public static const  PHOTO_SPACING:Number = 750;

          public static const  BG_COLOR1:uint = 0x222222;

          public static const  BG_COLOR2:uint = 0x000000;

          public static const  BG_COLOR_RATIO:uint = 80

          public function Model()

          {

          }

     }

}</pre>
<p>“public  static const” is a way to declare a variable that will be accessible from the  outside of the class, can be accessed without instantiating the holder class,  and will not change. If you don’t what Im talking about, you should see how we  are going to use these variables and then come back to what I’ve just said and  you should get it right away.</p>
<h3>Step 2 – Connecting to the centralized  data:</h3>
<p>So far all  this is completely useless unless we connect our classes to Model.as, so that  the constants can be used. This is done very easily; for instance to connect  the “0.05” value representing a camera velocity factor, we do as in the  following code:</p>
<pre>private function followTarget(evt:Event):void

{

     camera.lookAt(cameraTarget.position);

     var dX:Number = cameraTarget.x - camera.x;

     camera.x  += dX*0.05;

...</pre>
<p>Simply change  to:</p>
<pre>private function followTarget(evt:Event):void

{

     camera.lookAt(cameraTarget.position);

     var dX:Number = cameraTarget.x - camera.x;

     camera.x  += dX*Model.CAMERATARGET_SPEED_FACTOR;

     ...</pre>
<p>As long as the  model has been imported in CameraController of course:</p>
<pre>import com.li.photoviewer.model.Model;</pre>
<p>So this is  what you should do next. Import Model.as in all the view and controller  classes, and connect the values to it. If you’ve imported the model into a  class first, you should get useful codehints from Flex to help you complete  this task. When you’re done, you’ll have the power to very precisely tweak the entire  application from Model.as. You should play around with this to tune it to your  liking.</p>
<h3>Step 3 – Setting up an external XML:</h3>
<p>Now that  our model is set up and working, we will read data from an external xml, and  also use the model to store the data contained in the xml. We will trigger a  service that will read an xml and detail the images that will be loaded in our  application, and once this service is done, the 3D scene will build itself  based on this data. For this, lets start by designing our xml. Create a folder  named “data” and in it a new file named “data.xml”. The folder should be next  to “com” or  “away3d” folders. Then  design the xml structure of data.xml like this:</p>
<pre>&lt;?xml  version="1.0"?&gt;

&lt;imgs&gt;

     &lt;img name="testImage.jpg"/&gt;

     &lt;img  name="1.jpg"/&gt;

     &lt;img  name="2.jpg"/&gt;

     &lt;img  name="3.jpg"/&gt;

     &lt;img  name="4.jpg"/&gt;

     &lt;img  name="5.jpg"/&gt;

     &lt;img  name="6.jpg"/&gt;

     &lt;img  name="7.jpg"/&gt;

     &lt;img  name="8.jpg"/&gt;

     &lt;img  name="9.jpg"/&gt;

     &lt;img  name="10.jpg"/&gt;

&lt;/imgs&gt;</pre>
<p>The xml is extremely  simple, it just contains the name of each image.</p>
<h3>Step 4 – Creating an XML Reader:</h3>
<p>We should  continue by creating a folder called “services” next to “view” and in it a new  Actionscript Class called “XmlReader”, which will take care of extracting the  data from the xml. This class should have two variables in its constructor,  “xmlPath” as a string and “onComplete” as a function, It will also have a  “loader” variable as a URLoader:</p>
<pre>private var xmlPath:String;

private var onComplete:Function;

private var loader:URLLoader;

public function XmlReader(xmlPath:String,  onComplete:Function)

{

     this.xmlPath = xmlPath;

     this.onComplete = onComplete;

     loader = new URLLoader();

     loader.addEventListener(Event.COMPLETE,  completeHandler);

     loader.load(new URLRequest(xmlPath));

}</pre>
<p>The path of  the xml file is stored, (as well as “onComplete” which we will see in a  minute), then the loader is initialized and triggered. The function  “completeHandler()” will, as its name says, handle the loader once it’s done:</p>
<pre>private function completeHandler(evt:Event):void

{

     var xmlDocument:XMLDocument = new  XMLDocument();

     xmlDocument.ignoreWhite  = true;

     var xml:XML = new XML(evt.target.data);

     xmlDocument.parseXML(xml.toString());

     for(var i:uint; i&lt;xmlDocument.firstChild.childNodes.length;  i++)

          Model.data.push(xmlDocument.firstChild.childNodes[i].attributes.name);

     onComplete();

}</pre>
<p>The handler  parses all the data in the xml and injects it in the model. Of course, we need  to go back to Model.as and declare this “data” variable that we are referring  to. Just add it after all the constants:</p>
<pre>public static var data:Array = [];</pre>
<p>Finally  (referring again to the completeHandler method), “onComplete()” gets called as  soon as all the parsing is done. Remember that we designed this XmlReader to  receive a reference to this external function when it is instantiated. This  will simply be the function to be called when the reader has finished its job.</p>
<h3>Step 5 – Using the reader:</h3>
<p>Lets  implement this now in the application’s main class, PhotoViewer3D.as. Carefully  study these modifications:</p>
<pre>package

{

     import com.li.photoviewer.services.XmlReader;

     import com.li.photoviewer.view.PhotoScene;

     import flash.display.Sprite;

     import flash.display.StageAlign;

     import flash.display.StageScaleMode;

     [SWF(backgroundColor="0x000000", frameRate="30")]

     public class PhotoViewer3D extends Sprite

     {

          public function PhotoViewer3D()

          {

               stage.scaleMode  = StageScaleMode.NO_SCALE;

               stage.align  = StageAlign.TOP_LEFT;

               var reader:XmlReader = new XmlReader(&#8221;data/data.xml&#8221;, init);

          }

          private function init():void

          {

               var photoScene:PhotoScene = new PhotoScene();

               addChild(photoScene);

          }

     }

}</pre>
<p>I’ve just  instantiated an XmlReader, pointed it to the xml path, put the creation of the  scene in its own separate method, and also pointed the reader to this method so  its called as soon as its done.</p>
<h3>Step 6 – Loading the images:</h3>
<p>The next  step is pretty obvious. We now have the data array containing all the names of  our images, waiting for us in the model and we’ve also delayed the creation of  the 3D scene till after this data has been obtained. So we just need to alter  the “initObjects()” method of PhotoScene.as to read this data. It’s too simple  actually:</p>
<pre>private function initObjects():void

{

     for(var i:uint; i&lt;Model.data.length; i++)

     {

          var photo:PhotoLoader = new PhotoLoader("imgs/" + Model.data[i]);

          photo.x  = i*Model.PHOTO_SPACING;

          scene.addChild(photo);

          cameraController.maxX  = photo.x;

          photo.addOnMouseDown(photoClickHandler);

     }

}</pre>
<p>That’s it.  Test the application and see how it now loads all the corresponding different  images. We’re practically done now, I just want to add an additional effect to  the app…</p>
<h3>Step 7 – Adding a reflection:</h3>
<p>As it is  usual in many open source projects, many people share their code in classes  that can be very handy and easy to use. You can very often download a class  that does a particular thing, use it, and never know how it actually works. So  that’s what we’ll do, we will greatly enhance the look of our application by  downloading a class, and I will make my point of showing how great it is to use  other people’s classes, or even design classes yourself to be reusable in this  way.</p>
<p><a title="Download Reflection.as" href="http://www.thetechlabs.com/tutorials/files/flex/asantander/PicLensAway3D/Final/Downloads/reflection.zip" onclick="javascript:pageTracker._trackPageview('downloads/tutorials/files/flex/asantander/PicLensAway3D/Final/Downloads/reflection.zip');" target="_self">Download Reflection.as</a> and paste it  in the view folder.</p>
<p>The class  should be ready to work, except that its package path is all wrong. This is  pretty logical, since I’ve just used it for another project and it was placed  completely on a different place. Correct this path to the class’ current  location. You can also look into the class, now or later, to understand how it  works and maybe learn new things that could motivate you to other uses or even  new ideas with Away3D.</p>
<h3>Step 8 – Plugging in the reflection:</h3>
<p>Go back to  PhotoScene.as and declare the reflection instance (we don’t need to import  Reflection.as since it is in the same package as PhotoScene.as):</p>
<pre>private var  reflection:Reflection;</pre>
<p>Then, in the “initScene()” method, initialize  it and add it to the display list:</p>
<pre>reflection = new Reflection(scene, camera);
addChild(reflection);</pre>
<p>And  finally, in “renderScene()” add a call to the reflections rendering method:</p>
<pre>private function renderScene(evt:Event):void

{

reflection.render();

view.render();

}</pre>
<p>I also took  the time to connect the Reflection class to the model and drop its arbitrary  variables there. I even set up a USE_REFLECTION constant in the model and  applied this Boolean value in the initialization of the reflection in  “initScene()” and the “renderScene()” method too. All this allows you to, not  only tweak the app to look good, but also to consider performance issues. With  the values that you should have in the model after you do this, you can really  optimize the application.</p>
<pre>public static const USE_REFLECTION:Boolean = false;

public static const REFLECTION_OFFSET:Number = -525;

public static const REFLECTION_BLUR:Number = 8;

public static const REFLECTION_ALPHA:Number = 0.25;

public static const REFLECTION_SCALING:Number = 2;</pre>
<p>So, that’s  it! The application is flexible enough to be extended easily. Maybe a  horizontal scroller could be a good idea, for example… I leave that to your  creativity. I wanted to keep the MVC architecture as simple as I could by  avoiding custom events, singleton classes, etc, but those could be good things  to investigate for future projects. On the other hand, I really recommend  playing with the Away3D engine, the possibilities with it are endless!!</p>
<p>I hope  you’ve enjoyed the tutorial. I’m looking forward to make another one when I can  =)</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=Simulating%20PicLens%20with%20Flex%20and%20Away3D%20%E2%80%93%20Part%203&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fxml%2Fsimulating-piclens-with-flex-and-away3d-%25e2%2580%2593-part-3%2F" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=Simulating%20PicLens%20with%20Flex%20and%20Away3D%20%E2%80%93%20Part%203&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fxml%2Fsimulating-piclens-with-flex-and-away3d-%25e2%2580%2593-part-3%2F');"><img src="http://www.thetechlabs.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Save/Bookmark"/></a>

	</p><img src="http://feedproxy.google.com/~r/TheTechLabs_xml/~4/7_m_KGon7n0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.thetechlabs.com/xml/simulating-piclens-with-flex-and-away3d-%e2%80%93-part-3/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.thetechlabs.com/xml/simulating-piclens-with-flex-and-away3d-%e2%80%93-part-3/</feedburner:origLink></item>
		<item>
		<title>Extending the AS3/Flash9 Slideshow with XML</title>
		<link>http://feedproxy.google.com/~r/TheTechLabs_xml/~3/kTabWLNQ_pg/</link>
		<comments>http://www.thetechlabs.com/xml/extending-the-as3flash9-slideshow-with-xml/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 22:34:00 +0000</pubDate>
		<dc:creator>Rafael Nuenlist</dc:creator>
		
		<category><![CDATA[Effects]]></category>

		<category><![CDATA[Flash]]></category>

		<category><![CDATA[Interfaces]]></category>

		<category><![CDATA[Latest]]></category>

		<category><![CDATA[XML]]></category>

		<category><![CDATA[adobe flash]]></category>

		<category><![CDATA[as3]]></category>

		<category><![CDATA[caurinas engine]]></category>

		<category><![CDATA[how-to]]></category>

		<category><![CDATA[slideshow]]></category>

		<category><![CDATA[tutorial]]></category>

		<category><![CDATA[tweener]]></category>

		<guid isPermaLink="false">http://www.thetechlabs.com/?p=105</guid>
		<description><![CDATA[<p>In this second part tutorial we&#8217;re going to add some more features to the slideshow application.</p>
<p>Those would be forwarding and rewinding slides, play and pause the slideshow and linkable slides. If you haven&#8217;t read the first part tutorial yet, you should do it before continue. You can read it here.</p>
<small><em>posted in <a href="http://www.thetechlabs.com/category/effects/">Effects</a> by Rafael Nuenlist <a href="http://www.thetechlabs.com/xml/extending-the-as3flash9-slideshow-with-xml/#comments">Leave A Comment</a><br />&copy;2008 <a href="http://www.thetechlabs.com">The Tech Labs</a>. All Rights Reserved.</em></small>]]></description>
			<content:encoded><![CDATA[<p>In this second part tutorial we&#8217;re going to add some more features to <a title="Extended Slideshow" href="http://www.thetechlabs.com/tutorials/files/flash/rnunlist/slideshow2/"  target="_blank">the slideshow application</a>.</p>
<p>Those would be forwarding and rewinding slides, play and pause the slideshow and linkable slides. If you haven&#8217;t read the first part tutorial yet, you should do it before continue. You can read it <a title="Create a AS3 Slideshow with XML Tutorial" href="http://www.thetechlabs.com/xml/create-a-as3-slideshow-with-xml/"  target="_blank">here</a>.</p>
<h3>Requirements</h3>
<p>Adobe Flash CS3</p>
<p><a title="Try / buy" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.adobe.com/products/flash/');" href="http://www.adobe.com/products/flash/" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.adobe.com/products/flash/');" target="_blank">Try / Buy</a></p>
<p>Sample files:</p>
<p><a title="Source Files" onclick="javascript:pageTracker._trackPageview('downloads/tutorials/files/cardflip_fp10/CardFlip_FP10_source_files.zip');" href="http://thetechlabs.com/tutorials/files/flash/rnunlist/slideshow2/slideshowprt2.zip" onclick="javascript:pageTracker._trackPageview('downloads/tutorials/files/flash/rnunlist/slideshow2/slideshowprt2.zip');" target="_self">slideshowprt2.zip</a></p>
<h3>Adjust XML structure</h3>
<p>To store the link of each slide, we just add it as an attribute to the xml file, or to be more accurate, on the image nodes. We also set the target window of the link, which might be neccesary to set in some cases. So, our xml is looking now like this:</p>
<pre>&lt;slideshow&gt;
	&lt;image src="images/fly.jpg" desc="Fly" link="http://www.wikipedia.org" target="_self"/&gt;
	&lt;image src="images/mouse.jpg" desc="Computer mouse" link="http://www.google.com" target="_blank"/&gt;
	&lt;image src="images/country.jpg" desc="Country" link="http://www.thetechlabs.com" target="_self"/&gt;
	&lt;image src="images/rope.jpg" desc="Rope" link="http://www.amazon.com" target="_blank"/&gt;
	&lt;image src="images/flower.jpg" desc="Flower" link="http://www.adobe.com" target="_self"/&gt;
&lt;/slideshow&gt;</pre>
<h3>Adding new objects</h3>
<p>Since we know, how the xml looks like, we can move on to the knew stuff on the stage. In the mcInfo movieclip we&#8217;ve added 4 new buttons. Pause/Play and Forward/Rewind, which will later be assigned to event listeners. On the main stage is a invisible button as big as the size of the slides which will be used to open the links defined in the xml.<br />
Alright, that&#8217;s already enough to go on with the coding part.</p>
<h3>Adding new variables</h3>
<p>First of all, we need to add some new variables to our script.</p>
<p>To know, if the slideshow is currently playing or paused, we set a flag:</p>
<pre>var bolPlaying:Boolean = true;</pre>
<p>And we also store the current slide link and target window in a variable:</p>
<pre>var strLink:String = "";
var strTarget:String = "";</pre>
<h3>Init function</h3>
<p>This is all we need for the variable. Now let&#8217;s take a look about what&#8217;s changing in the init function of the slideshow. We added the following two lines at the beginning of the function to prevent the user to click any button as long as the xml file hasn&#8217;t been loaded completely:</p>
<pre>	mcInfo.visible = false;
	btnLink.visible = false;</pre>
<p>We&#8217;ve also changed the function that will be called once the slideTimer event is fired. Now the function nextSlide() will be called, which we&#8217;ll create later:</p>
<pre>	slideTimer.addEventListener(TimerEvent.TIMER, nextSlide);</pre>
<p>On the last line of the initSlideshow() function we add the event listeners for the buttons. The play and button pause event listeners will be assigned to the same function togglePause(). The next and previous button will be asssigned to the nextSlide() and previousSlide() function. And last of all, we connect the invisible link button that covers the slide area with the goToWebsite() function. And since our slideshow will automatically be playing at the beginning, we hide the play button.</p>
<pre>	btnLink.addEventListener(MouseEvent.CLICK, goToWebsite);
	mcInfo.btnPlay.addEventListener(MouseEvent.CLICK, togglePause);
	mcInfo.btnPause.addEventListener(MouseEvent.CLICK, togglePause);
	mcInfo.btnNext.addEventListener(MouseEvent.CLICK, nextSlide);
	mcInfo.btnPrevious.addEventListener(MouseEvent.CLICK, previousSlide);
	mcInfo.btnPlay.visible = false;</pre>
<h3>onXMLLoadComplete function</h3>
<p>Once the xml is completely loaded, we need to show the mcInfo and the button link again. So we add the following two line of code to the function onXMLLoadComplete()</p>
<pre>	mcInfo.visible = true;
	btnLink.visible = true;</pre>
<p>And since our switchSlide() function will now need to have the index number of the slide, we add a zero as the parameter. We&#8217;ll explain the changes in the switchSlide() function later.</p>
<pre>	switchSlide(0);</pre>
<h3>NextSlide/PreviousSide function</h3>
<p>Let&#8217;s take a look at the nextSlide() and previousSlide() functions. They are called when clicking the next and previous button and the nextSlide() function is also called when the Timer event of the sliderTimer has been fired.<br />
The nextSlide() function checks, if there are any slides left to move on. If so, the current switchSlide() function will be called with the next slide index. If there are no more slides left, then the parameter will be zero standing for the first slide.<br />
The previousSlide() function works the same way. If there are slide we can go back, then the switchSlide() function will be called with the previous slide index. If we&#8217;re already on the first slide, then we start the slideshow from the last slide with calling the switchSlide() function with the parameter of the total slide count minus one since the array count begins with zero.</p>
<pre>function nextSlide(e:Event = null):void {
	if(intCurrentSlide + 1 &lt; intSlideCount)
		switchSlide(intCurrentSlide + 1);
	else
		switchSlide(0);

}

function previousSlide(e:Event = null):void {
	if(intCurrentSlide - 1 &gt;= 0)
		switchSlide(intCurrentSlide - 1);
	else
		switchSlide(intSlideCount - 1);
}</pre>
<h3>SwitchSlide function</h3>
<p>Since the nextSlide() and previousSlide() functions are now handling the checking for the slides, we can take out this part in the switchSlide() function.<br />
To prevent the user from clicking too fast on the next and previous button, we check, if the tweener is still fading in the slides. If so, we just ignore the action. We&#8217;re doing this by adding the following if-statement to the first line of the switchSlide() function.</p>
<pre>	if(!Tweener.isTweening(currentContainer)) {</pre>
<p>Now we only need to set the new link and the target of it. This will be done exactly the same way as setting the description of the slide.</p>
<pre>		strLink		= xmlSlideshow..image[intCurrentSlide].@link;
		strTarget	= xmlSlideshow..image[intCurrentSlide].@target;</pre>
<h3>FadeSideIn function</h3>
<p>The fadeSlideIn() function has also a small addition. We check if the slideshow is currently playing and show the number of seconds to the next slide. If the slideshow is paused, we show a status message. The text will be assigned to the lbl_info label.</p>
<pre>	if(bolPlaying) {
		mcInfo.lbl_loading.text = "Next slide in " + TIMER_DELAY / 1000 + " sec.";
	} else {
		mcInfo.lbl_loading.text = "Slideshow paused";
	}</pre>
<h3>OnSlideFadeIn function</h3>
<p>On the onSlideFadeIn() function we now need to check, if the slideshow is playing. If so, we can start the timer again:</p>
<pre>	if(bolPlaying &amp;&amp; !slideTimer.running)
		slideTimer.start();</pre>
<h3>TogglePause function</h3>
<p>The togglePause() function will be called when the user clicks on the play and pause button. First, we check, if the slideshow is playing, if so, we show the play button, set the bolPlaying variable to false, change the status message of the lbl_info label to &#8220;Slideshow paused&#8221; and stop the timer.<br />
If the slideshow is currently paused, we show the pause button, set the bolPlaying variable to true again, show the time to the next slide and restart the timer.</p>
<pre>function togglePause(e:MouseEvent):void {
	if(bolPlaying) {
		mcInfo.btnPlay.visible = true;
		mcInfo.btnPause.visible = false;

		bolPlaying = false;
		mcInfo.lbl_loading.text = "Slideshow paused";
		slideTimer.stop();
	} else {
		mcInfo.btnPlay.visible = false;
		mcInfo.btnPause.visible = true;

		bolPlaying = true;
		mcInfo.lbl_loading.text = "Next slide in " + TIMER_DELAY / 1000 + " sec.";
		slideTimer.reset();
		slideTimer.start();
	}
}</pre>
<h3>GotToWebsite function</h3>
<p>The last function we need to define is the goToWebsite() function. This function will be called once the user clicks on the invisible button. It will check, if the strLink variable is empty or null. If not, the link will be opened.</p>
<pre>function goToWebsite(e:MouseEvent):void {
	if(strLink != "" &amp;&amp; strLink != null) {
		navigateToURL(new URLRequest(strLink), strTarget);
	}
}</pre>
<p>We&#8217;ve already reached the end of the second part of the slideshow tutorial. We hope that you enjoyed reading it and we appreciate any kind of feedback.</p>
<h3>Note</h3>
<p>The feature for clicking the invisible button only works, when you&#8217;re running the flash on a webserver or in the flash sdk.</p>
<h3>Full code with comments</h3>
<pre>// import tweener
import caurina.transitions.Tweener;

// delay between slides
const TIMER_DELAY:int = 5000;
// fade time between slides
const FADE_TIME:Number =	1;

// flag for knowing if slideshow is playing
var bolPlaying:Boolean = true;
// reference to the current slider container
var currentContainer:Sprite;
// index of the current slide
var intCurrentSlide:int = -1;
// total slides
var intSlideCount:int;
// timer for switching slides
var slideTimer:Timer;
// slides holder
var sprContainer1:Sprite;
var sprContainer2:Sprite;
// slides loader
var slideLoader:Loader;
// current slide link
var strLink:String = "";
// current slide link target
var strTarget:String = "";
// url to slideshow xml
var strXMLPath:String = "slideshow-data.xml";
// slideshow xml loader
var xmlLoader:URLLoader;
// slideshow xml
var xmlSlideshow:XML;

function initSlideshow():void {
	// hide buttons, labels and link
	mcInfo.visible = false;
	btnLink.visible = false;

	// create new urlloader for xml file
	xmlLoader = new URLLoader();
	// add listener for complete event
	xmlLoader.addEventListener(Event.COMPLETE, onXMLLoadComplete);
	// load xml file
	xmlLoader.load(new URLRequest(strXMLPath));

	// create new timer with delay from constant
	slideTimer = new Timer(TIMER_DELAY);
	// add event listener for timer event
	slideTimer.addEventListener(TimerEvent.TIMER, nextSlide);

	// create 2 container sprite which will hold the slides and
	// add them to the masked movieclip
	sprContainer1 = new Sprite();
	sprContainer2 = new Sprite();
	mcSlideHolder.addChild(sprContainer1);
	mcSlideHolder.addChild(sprContainer2);

	// keep a reference of the container which is currently
	// in the front
	currentContainer = sprContainer2;

	// add event listeners for buttons
	btnLink.addEventListener(MouseEvent.CLICK, goToWebsite);
	mcInfo.btnPlay.addEventListener(MouseEvent.CLICK, togglePause);
	mcInfo.btnPause.addEventListener(MouseEvent.CLICK, togglePause);
	mcInfo.btnNext.addEventListener(MouseEvent.CLICK, nextSlide);
	mcInfo.btnPrevious.addEventListener(MouseEvent.CLICK, previousSlide);

	// hide play button
	mcInfo.btnPlay.visible = false;
}

function onXMLLoadComplete(e:Event):void {
	// show buttons, labels and link
	mcInfo.visible = true;
	btnLink.visible = true;	

	// create new xml with the received data
	xmlSlideshow = new XML(e.target.data);
	// get total slide count
	intSlideCount = xmlSlideshow..image.length();
	// switch the first slide without a delay
	switchSlide(0);
}

function fadeSlideIn(e:Event):void {
	// add loaded slide from slide loader to the
	// current container
	currentContainer.addChild(slideLoader.content);
	// clear preloader text
	mcInfo.lbl_loading.text = "";

	// check if the slideshow is currently playing
	// if so, show time to the next slide. If not, show
	// a status message
	if(bolPlaying) {
		mcInfo.lbl_loading.text = "Next slide in " + TIMER_DELAY / 1000 + " sec.";
	} else {
		mcInfo.lbl_loading.text = "Slideshow paused";
	}

	// fade the current container in and start the slide timer
	// when the tween is finished
	Tweener.addTween(currentContainer, {alpha:1, time:FADE_TIME, onComplete:onSlideFadeIn});
}

function onSlideFadeIn():void {
	// check, if the slideshow is currently playing
	// if so, start the timer again
	if(bolPlaying &amp;&amp; !slideTimer.running)
		slideTimer.start();
}

function togglePause(e:MouseEvent):void {
	// check if the slideshow is currently playing
	if(bolPlaying) {
		// show play button
		mcInfo.btnPlay.visible = true;
		mcInfo.btnPause.visible = false;

		// set playing flag to false
		bolPlaying = false;
		// set status message
		mcInfo.lbl_loading.text = "Slideshow paused";
		// stop the timer
		slideTimer.stop();
	} else {
		// show pause button
		mcInfo.btnPlay.visible = false;
		mcInfo.btnPause.visible = true;

		// set playing flag to true
		bolPlaying = true;
		// show time to next slide
		mcInfo.lbl_loading.text = "Next slide in " + TIMER_DELAY / 1000 + " sec.";
		// reset and start timer
		slideTimer.reset();
		slideTimer.start();
	}
}

function switchSlide(intSlide:int):void {
	// check if the last slide is still fading in
	if(!Tweener.isTweening(currentContainer)) {
		// check, if the timer is running (needed for the
		// very first switch of the slide)
		if(slideTimer.running)
			slideTimer.stop();

		// change slide index
		intCurrentSlide = intSlide;

		// check which container is currently in the front and
		// assign currentContainer to the one that's in the back with
		// the old slide
		if(currentContainer == sprContainer2)
			currentContainer = sprContainer1;
		else
			currentContainer = sprContainer2;

		// hide the old slide
		currentContainer.alpha = 0;
		// bring the old slide to the front
		mcSlideHolder.swapChildren(sprContainer2, sprContainer1);

		// create a new loader for the slide
		slideLoader = new Loader();
		// add event listener when slide is loaded
		slideLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, fadeSlideIn);
		// add event listener for the progress
		slideLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
		// load the next slide
		slideLoader.load(new URLRequest(xmlSlideshow..image[intCurrentSlide].@src));

		// show description of the next slide
		mcInfo.lbl_description.text = xmlSlideshow..image[intCurrentSlide].@desc;

		// set link and link target variable of the slide
		strLink		= xmlSlideshow..image[intCurrentSlide].@link;
		strTarget	= xmlSlideshow..image[intCurrentSlide].@target;

		// show current slide and total slides
		mcInfo.lbl_count.text = (intCurrentSlide + 1) + &#8221; / &#8221; + intSlideCount + &#8221; Slides&#8221;;
	}
}

function showProgress(e:ProgressEvent):void {
	// show percentage of the bytes loaded from the current slide
	mcInfo.lbl_loading.text = &#8220;Loading&#8230;&#8221; + Math.ceil(e.bytesLoaded * 100 / e.bytesTotal) + &#8220;%&#8221;;
}

function goToWebsite(e:MouseEvent):void {
	// check if the strLink is not empty and open the link in the
	// defined target window
	if(strLink != &#8220;&#8221; &amp;&amp; strLink != null) {
		navigateToURL(new URLRequest(strLink), strTarget);
	}
}

function nextSlide(e:Event = null):void {
	// check, if there are any slides left, if so, increment slide
	// index
	if(intCurrentSlide + 1 &lt; intSlideCount)
		switchSlide(intCurrentSlide + 1);
	// if not, start slideshow from beginning
	else
		switchSlide(0);

}

function previousSlide(e:Event = null):void {
	// check, if there are any slides left, if so, decrement slide
	// index
	if(intCurrentSlide - 1 &gt;= 0)
		switchSlide(intCurrentSlide - 1);
	// if not, start slideshow from the last slide
	else
		switchSlide(intSlideCount - 1);
}

// init slideshow
initSlideshow();</pre>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=Extending%20the%20AS3%2FFlash9%20Slideshow%20with%20XML&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fxml%2Fextending-the-as3flash9-slideshow-with-xml%2F" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=Extending%20the%20AS3%2FFlash9%20Slideshow%20with%20XML&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fxml%2Fextending-the-as3flash9-slideshow-with-xml%2F');"><img src="http://www.thetechlabs.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Save/Bookmark"/></a>

	</p><img src="http://feedproxy.google.com/~r/TheTechLabs_xml/~4/kTabWLNQ_pg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.thetechlabs.com/xml/extending-the-as3flash9-slideshow-with-xml/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.thetechlabs.com/xml/extending-the-as3flash9-slideshow-with-xml/</feedburner:origLink></item>
		<item>
		<title>Create a AS3 Slideshow with XML</title>
		<link>http://feedproxy.google.com/~r/TheTechLabs_xml/~3/-893iznruTA/</link>
		<comments>http://www.thetechlabs.com/xml/create-a-as3-slideshow-with-xml/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 21:02:04 +0000</pubDate>
		<dc:creator>Rafael Nuenlist</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<category><![CDATA[Interfaces]]></category>

		<category><![CDATA[XML]]></category>

		<category><![CDATA[adobe flash]]></category>

		<category><![CDATA[as3]]></category>

		<category><![CDATA[caurinas engine]]></category>

		<category><![CDATA[loader]]></category>

		<category><![CDATA[slideshow]]></category>

		<category><![CDATA[tweener]]></category>

		<guid isPermaLink="false">http://www.thetechlabs.com/?p=84</guid>
		<description><![CDATA[<p>This tutorial shows you how to create a simple slideshow using as3/flash and xml</p>
<small><em>posted in <a href="http://www.thetechlabs.com/category/flash/">Flash</a> by Rafael Nuenlist <a href="http://www.thetechlabs.com/xml/create-a-as3-slideshow-with-xml/#comments">Leave A Comment</a><br />&copy;2008 <a href="http://www.thetechlabs.com">The Tech Labs</a>. All Rights Reserved.</em></small>]]></description>
			<content:encoded><![CDATA[<p>This tutorial shows you how to create a simple slideshow using as3/flash and xml like <a href="http://www.thetechlabs.com/tutorials/files/flash/rnunlist/slideshow/slideshow.html"  target="_blank">this one</a>.</p>
<p>In order to complete this tutorial you can download the source files <a title="download source files" href="http://www.thetechlabs.com/tutorials/files/flash/rnunlist/slideshow_tut.zip" onclick="javascript:pageTracker._trackPageview('downloads/tutorials/files/flash/rnunlist/slideshow_tut.zip');" target="_self">here.</a></p>
<p>In our xml file, we want to store the path to the slides and a description for each of it. So let&#8217;s take a look at the example file</p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

  &lt;slideshow&gt;

&lt;image src="images/fly.jpg" desc="Fly"/&gt;

&lt;image src="images/mouse.jpg" desc="Computer mouse"/&gt;

&lt;image src="images/country.jpg" desc="Country"/&gt;

&lt;image src="images/rope.jpg" desc="Rope"/&gt;

&lt;image src="images/flower.jpg" desc="Flower"/&gt;

&lt;/slideshow&gt;</pre>
<p>On the first line we describe the version and the encoding of the file. Flash uses UTF-8 for encoding, so we should edit the file in UTF-8 only to avoid character encoding problems.</p>
<p>The first node defines the root node of the xml file and contains further nodes. These are the images with the attributes src and desc. Okey, that&#8217;s how the structure of the xml looks like, let&#8217;s move on to the flash file.<br />
The stage has a movieclip which contains the textfields which will show us the description of the slides, the loading process and the slide count later. Under it you will find a mask layer which masks an empty movieclip, where our slides will be loaded into. And on our first layer we have the whole script, at wich we&#8217;ll take a look now.</p>
<p>As always, we need to import the necessary librarys first. In our case, we only have caurinas tweener engine which will later be used to fade in the slides.</p>
<pre>import caurina.transitions.Tweener;</pre>
<p>Then we define two constants. One for the delay between the slides in milliseconds and the other one for the fade time between the slides in seconds. You can change them freely according to your needs</p>
<pre>const TIMER_DELAY:int = 5000;
const FADE_TIME:int =	1;</pre>
<p>Now we need to set some variables for the slideshow. We&#8217;re beginning with a variable, that holds a reference to the current container which holds the slide and is in the front</p>
<pre>var currentContainer:Sprite;</pre>
<p>To know which slide is currently active, we set a integer. We start at -1 because the function switchSlide will go to the first slide, which is 0.</p>
<pre>var intCurrentSlide:int = -1;</pre>
<p>The total count of the slides will be stored in a integer variable</p>
<pre>var intSlideCount:int;</pre>
<p>Then we need to define a timer, which calls the switchSlide function after the delay time we set in the constant</p>
<pre>var slideTimer:Timer;</pre>
<p>To have a nice fade effect, we need two containers for the slides. Each one will contain one slide</p>
<pre>var sprContainer1:Sprite;
var sprContainer2:Sprite;</pre>
<p>Next we set a variable for loading our slides</p>
<pre>var slideLoader:Loader;</pre>
<p>The next variable defines the path to the xml file</p>
<pre>var strXMLPath:String = "slideshow-data.xml";</pre>
<p>xmlLoader will be used to load the xml file</p>
<pre>var xmlLoader:URLLoader;</pre>
<p>And finally we need a variable to store the xml stuff</p>
<pre>var xmlSlideshow:XML;</pre>
<p>Now we need to initialize the whole slideshow. First, we create a new urlloader for the slideshow xml file, add an event listener when it&#8217;s completly and load it</p>
<pre>xmlLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, onXMLLoadComplete);
xmlLoader.load(new URLRequest(strXMLPath));</pre>
<p>Then we create the time with the delay from the constant and add an event listener for the timer event</p>
<pre>slideTimer = new Timer(TIMER_DELAY);
slideTimer.addEventListener(TimerEvent.TIMER, switchSlide);</pre>
<p>Next we create 2 container sprite which will hold the slides and add them to the masked movieclip</p>
<pre>sprContainer1 = new Sprite();
sprContainer2 = new Sprite();
mcSlideHolder.addChild(sprContainer1);
mcSlideHolder.addChild(sprContainer2);</pre>
<p>And last of all, we keep a reference of the container which is currently in the front</p>
<pre>currentContainer = sprContainer2;</pre>
<p>Once our xml file is fully loaded, the function onXMLLoadComplete will be called. This function assigns the received data to xmlSlideshow, gets the total slide count and stores it in the variable intSlideCount. Then it&#8217;ll call the function switchSlide which will immadiately load the next slide without waiting on the timer event.</p>
<pre>xmlSlideshow = new XML(e.target.data);
intSlideCount = xmlSlideshow..image.length();
switchSlide(null);</pre>
<p>Ok, let&#8217;s move on to the switchSlide function. This function will be called every time the timer has reached the delay and fires the timer event. First of all, we check, if the timer is running and stop it, because we need to wait until the next slide will be loaded and faded in. Then we check if there are any slides left. If not, we go back to the beginning. Now we need to figure out, wich container is currently in the front and assign currentContainer to the one, that&#8217;s in the back containing the old slide. Next we hide the old slide and bring it to the front.</p>
<pre>if(slideTimer.running)
	slideTimer.stop();

if(intCurrentSlide + 1 &lt; intSlideCount)
	intCurrentSlide++;
else
	intCurrentSlide = 0;

if(currentContainer == sprContainer2)
	currentContainer = sprContainer1;
else
	currentContainer = sprContainer2;

currentContainer.alpha = 0;
mcSlideHolder.swapChildren(sprContainer2, sprContainer1);</pre>
<p>Then we create a new loader for the slide. We add an event listener when it&#8217;s loaded and an event listener for the progress of the loading. Next we load the picture with a urlrequest that contains the source path to the current image. And last of all, we show the description of the slide on the lbl_description and update the current number of the slide on lbl_count.</p>
<pre>slideLoader = new Loader();
slideLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, fadeSlideIn);
slideLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
slideLoader.load(new URLRequest(xmlSlideshow..image[intCurrentSlide].@src));

mcInfo.lbl_description.text = xmlSlideshow..image[intCurrentSlide].@desc;
mcInfo.lbl_count.text = (intCurrentSlide + 1) + &#8221; / &#8221; + intSlideCount + &#8221; Slides&#8221;;</pre>
<p>The showProgress function is quite small. It&#8217;s just one line that calculates the percentage of the bytes loaded from the current slide and displays it on the lbl_loading</p>
<pre>mcInfo.lbl_loading.text = "Loading..." + Math.ceil(e.bytesLoaded * 100 / e.bytesTotal) + "%";</pre>
<p>The last function is fadeSlideIn and will be called once the picture is fully loaded. First, we add the loaded slide from the slideLoader to the current container. Then we clear the preloader text. And finally, we fade the current container in with caurinas tweener engine and start the slide timer when the tween is finished. Like this, we&#8217;ll have an endless loop, which will switch the slides.</p>
<pre>currentContainer.addChild(slideLoader.content);
mcInfo.lbl_loading.text = "";
Tweener.addTween(currentContainer, {alpha:1, time:FADE_TIME, onComplete:function(){ slideTimer.start();} });
}</pre>
<p>That was already it. I hope you enjoyed reading the tutorial. Please feel free to ask questions or leave a feedback.</p>
<p>Full code with comments</p>
<pre>// import tweener
import caurina.transitions.Tweener;

// delay between slides
const TIMER_DELAY:int = 5000;
// fade time between slides
const FADE_TIME:int =	1;

// reference to the current slider container
var currentContainer:Sprite;
// index of the current slide
var intCurrentSlide:int = -1;
// total slides
var intSlideCount:int;
// timer for switching slides
var slideTimer:Timer;
// slides holder
var sprContainer1:Sprite;
var sprContainer2:Sprite;
// slides loader
var slideLoader:Loader;
// url to slideshow xml
var strXMLPath:String = "slideshow-data.xml";
// slideshow xml loader
var xmlLoader:URLLoader;
// slideshow xml
var xmlSlideshow:XML;

function init():void {
	// create new urlloader for xml file
	xmlLoader = new URLLoader();
	// add listener for complete event
	xmlLoader.addEventListener(Event.COMPLETE, onXMLLoadComplete);
	// load xml file
	xmlLoader.load(new URLRequest(strXMLPath));

	// create new timer with delay from constant
	slideTimer = new Timer(TIMER_DELAY);
	// add event listener for timer event
	slideTimer.addEventListener(TimerEvent.TIMER, switchSlide);

	// create 2 container sprite which will hold the slides and
	// add them to the masked movieclip
	sprContainer1 = new Sprite();
	sprContainer2 = new Sprite();
	mcSlideHolder.addChild(sprContainer1);
	mcSlideHolder.addChild(sprContainer2);

	// keep a reference of the container which is currently
	// in the front
	currentContainer = sprContainer2;

}

function onXMLLoadComplete(e:Event):void {
	// create new xml with the received data
	xmlSlideshow = new XML(e.target.data);
	// get total slide count
	intSlideCount = xmlSlideshow..image.length();
	// switch the first slide without a delay
	switchSlide(null);
}

function fadeSlideIn(e:Event):void {
	// add loaded slide from slide loader to the
	// current container
	currentContainer.addChild(slideLoader.content);
	// clear preloader text
	mcInfo.lbl_loading.text = "";
	// fade the current container in and start the slide timer
	// when the tween is finished
	Tweener.addTween(currentContainer, {alpha:1, time:FADE_TIME, onComplete:function() { slideTimer.start(); }});
}

function switchSlide(e:Event):void {
	// check, if the timer is running (needed for the
	// very first switch of the slide)
	if(slideTimer.running)
		slideTimer.stop();

	// check if we have any slides left and increment
	// current slide index
	if(intCurrentSlide + 1 &lt; intSlideCount)
		intCurrentSlide++;
	// if not, start slideshow from beginning
	else
		intCurrentSlide = 0;

	// check which container is currently in the front and
	// assign currentContainer to the one that's in the back with
	// the old slide
	if(currentContainer == sprContainer2)
		currentContainer = sprContainer1;
	else
		currentContainer = sprContainer2;

	// hide the old slide
	currentContainer.alpha = 0;
	// bring the old slide to the front
	mcSlideHolder.swapChildren(sprContainer2, sprContainer1);

	// create a new loader for the slide
	slideLoader = new Loader();
	// add event listener when slide is loaded
	slideLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, fadeSlideIn);
	// add event listener for the progress
	slideLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
	// load the next slide
	slideLoader.load(new URLRequest(xmlSlideshow..image[intCurrentSlide].@src));

	// show description of the next slide
	mcInfo.lbl_description.text = xmlSlideshow..image[intCurrentSlide].@desc;
	// show current slide and total slides
	mcInfo.lbl_count.text = (intCurrentSlide + 1) + &#8221; / &#8221; + intSlideCount + &#8221; Slides&#8221;;
}

function showProgress(e:ProgressEvent):void {
	// show percentage of the bytes loaded from the current slide
	mcInfo.lbl_loading.text = &#8220;Loading&#8230;&#8221; + Math.ceil(e.bytesLoaded * 100 / e.bytesTotal) + &#8220;%&#8221;;
}

// init slideshow
init();</pre>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=Create%20a%20AS3%20Slideshow%20with%20XML&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fxml%2Fcreate-a-as3-slideshow-with-xml%2F" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=Create%20a%20AS3%20Slideshow%20with%20XML&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fxml%2Fcreate-a-as3-slideshow-with-xml%2F');"><img src="http://www.thetechlabs.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Save/Bookmark"/></a>

	</p><img src="http://feedproxy.google.com/~r/TheTechLabs_xml/~4/-893iznruTA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.thetechlabs.com/xml/create-a-as3-slideshow-with-xml/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.thetechlabs.com/xml/create-a-as3-slideshow-with-xml/</feedburner:origLink></item>
		<item>
		<title>How to build a contact manager in AIR using XML - Part 2</title>
		<link>http://feedproxy.google.com/~r/TheTechLabs_xml/~3/t1GsW73rOeI/</link>
		<comments>http://www.thetechlabs.com/xml/how-to-build-a-contact-manager-in-air-using-xml-part-2/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 22:36:15 +0000</pubDate>
		<dc:creator>Pedro Furtado</dc:creator>
		
		<category><![CDATA[AIR]]></category>

		<category><![CDATA[Interfaces]]></category>

		<category><![CDATA[XML]]></category>

		<category><![CDATA[adobe air]]></category>

		<category><![CDATA[binding]]></category>

		<category><![CDATA[components]]></category>

		<category><![CDATA[contact manager]]></category>

		<category><![CDATA[data]]></category>

		<category><![CDATA[datagrid]]></category>

		<category><![CDATA[mxml]]></category>

		<guid isPermaLink="false">http://www.thetechlabs.com/?p=82</guid>
		<description><![CDATA[<p>In this second, and final, part we&#8217;ll be learning how to save and edit the file and how to setup the bindings between the xml and our component.</p>
<small><em>posted in <a href="http://www.thetechlabs.com/category/air/">AIR</a> by Pedro Furtado <a href="http://www.thetechlabs.com/xml/how-to-build-a-contact-manager-in-air-using-xml-part-2/#comments">Leave A Comment</a><br />&copy;2008 <a href="http://www.thetechlabs.com">The Tech Labs</a>. All Rights Reserved.</em></small>]]></description>
			<content:encoded><![CDATA[<p>Its finally time for the second part of the AIR Contact Manager.</p>
<p>In this second, and final, part we&#8217;ll be learning how to save and edit the file and how to setup the bindings between the xml and our component.</p>
<p><a title="Download Source Files" href="http://www.thetechlabs.com/tutorials/files/Air/pfurtado/FEXMLContacts.zip" onclick="javascript:pageTracker._trackPageview('downloads/tutorials/files/Air/pfurtado/FEXMLContacts.zip');" target="_self"><strong>Download the source files</strong></a></p>
<p>On a side note, we&#8217;ll be using the application storage folder to save the data because AIR doesn&#8217;t allow us to write to the application folder itself.</p>
<pre>&lt;mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" initialize="{init()}"
	layout="absolute" height="451" width="542"&gt;
&lt;!-- // --&gt;
	&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.collections.XMLListCollection;
			private var myXml:XML;
			private var myLoader:URLLoader;
			[Bindable]
			private var myContactsCol:XMLListCollection;</pre>
<p>Note the introduction of the [Bindable] above &#8216;private var myContactsCol:XMLListCollection;&#8217; this tells the Flex components that they can use this variable to listen to changes and to change it&#8217;s values.</p>
<pre>public function init():void
			{
				var dataFile:File = new File('app-storage:/data.xml');
				if(dataFile.exists){
					var myReq:URLRequest = new URLRequest('app-storage:/data.xml');
					myLoader = new URLLoader()
					myLoader.addEventListener(Event.COMPLETE, dataComplete);
					myLoader.load(myReq);
				}else{
					createFile()
				}

			}</pre>
<p>We start by initializing the application, as we saw in the previous part, but this time we need to check if the XML file already exists in our<br />
application storage. And if it doesn&#8217;t we need to create it.<br />
Note: You&#8217;ll notice that we&#8217;re referencing the file as app-storage:/data.xml, app-storage is a shortcut that AIR give you to your local storage location on the users machine.</p>
<pre>private function createFile():void
			{
				var xmlToSave:XML = new XML('&lt;flashEnabled&gt;&lt;contacts&gt;' +
						'&lt;contact&gt;' +
						'&lt;name&gt;Contact1&lt;/name&gt;' +
						'&lt;telephone&gt;&lt;/telephone&gt;' +
						'&lt;email&gt;&lt;/email&gt;' +
						'&lt;/contact&gt;' +
						'&lt;/contacts&gt;' +
						'&lt;/flashEnabled&gt;')
				var saveStr:String = xmlToSave.toXMLString();

				var file:File = new File('app-storage:/data.xml');
				var fs:FileStream = new FileStream();
				fs.open(file, FileMode.WRITE);

				fs.writeUTFBytes(saveStr);
				fs.close();
				init();
			}</pre>
<p>Since the file wasn&#8217;t found we&#8217;ll create it, we start by creating our base XML object and retrieving a string with xml identation, then we open a File reference to it and finally<br />
we write the file using writeUTFBytes that will automatically save our string to the XML file with UTF-8.</p>
<pre>private function dataComplete(e:Event):void
			{
				myXml = new XML(myLoader.data.toString());
				myContactsCol = new XMLListCollection(myXml..contact);

			}

			private function updateList():void
			{
				myContactsCol = new XMLListCollection(myXml..contact.(name.toLowerCase().indexOf(search_txt.text.toLowerCase()) != -1 ))
			}</pre>
<p>Here you&#8217;ll also notice that we no longer need to invalidate the list or reset the datagrid&#8217;s dataprovider, this is because we now use Binding.</p>
<pre>private function saveData(e:Event):void
			{
				var xmlToSave:XML = new XML('&lt;flashEnabled&gt;&lt;contacts&gt;'+myContactsCol.toXMLString()+'&lt;/contacts&gt;&lt;/flashEnabled&gt;')
				var saveStr:String = xmlToSave.toXMLString();

				var file:File = new File('app-storage:/data.xml');
				var fs:FileStream = new FileStream();
				fs.open(file, FileMode.WRITE);

				fs.writeUTFBytes(saveStr);
				fs.close();
			}</pre>
<p>This is where we&#8217;ll save the file, it&#8217;s essentially the same as create file, but with the contents of our current contact xml collection as nodes.</p>
<pre>private function addItem():void
			{
				myContactsCol.addItem(new XML('&lt;contact&gt;' +
						'&lt;name&gt;Contact1&lt;/name&gt;' +
						'&lt;telephone&gt;&lt;/telephone&gt;' +
						'&lt;email&gt;&lt;/email&gt;' +
						'&lt;/contact&gt;'))
			}

			private function removeItem():void
			{
				myContactsCol.removeItemAt(myDg.selectedIndex);
			}

		]]&gt;
	&lt;/mx:Script&gt;</pre>
<p>Here we have the add and remove item from our collection. So first lets go over adding an item, we essentially need to create an empty node and add it to the xml collection.<br />
This can be achieved in a myriad of ways, but I reckon this might be the easiest.<br />
Then for the removing part it&#8217;s as easy as removing the item that corresponds to the current index of the data grid.</p>
<p>Design</p>
<pre>&lt;mx:DataGrid bottom="60" top="10" left="10" id="myDg" dataProvider="{myContactsCol}" editable="true" right="10"&gt;
		&lt;mx:columns&gt;
			&lt;mx:DataGridColumn headerText="Name" dataField="name"/&gt;
			&lt;mx:DataGridColumn headerText="Telphone" dataField="telephone"/&gt;
			&lt;mx:DataGridColumn headerText="Email" dataField="email"/&gt;
		&lt;/mx:columns&gt;
	&lt;/mx:DataGrid&gt;
	&lt;mx:Label x="10" text="Search:" bottom="10"/&gt;
	&lt;mx:TextInput x="65" id="search_txt" bottom="10"/&gt;
	&lt;!-- Code block 9 --&gt;
	&lt;mx:Button x="233" label="Go!" id="go_btn" click="{updateList()}" bottom="10"/&gt;
	&lt;mx:Button label="Save" click="{saveData(event)}" id="saveButton" bottom="10" right="10"/&gt;
	&lt;mx:Button x="286" label="Add" click="{addItem()}" bottom="10"/&gt;
	&lt;mx:Button x="343" label="Remove" click="{removeItem()}" bottom="10"/&gt;

&lt;/mx:WindowedApplication&gt;</pre>
<p>With all the UI elements in place we can now set the two properties we need for the datagrid to work properly, the editable=&#8221;true&#8221; so that we can edit the contents of each item,<br />
and the to set the dataprovider to myContactsCol so that it will bind to it.</p>
<p>Afterward we just have the normal buttons and layout to call the appropriate methods on click and you&#8217;re all set.</p>
<p>I hope that this will help you get some insight on how to use Bindings and how to modify and write files using AIR so that you can apply it to your own projects,<br />
in the previous part of this article we mentioned the application self update, but since then Adobe has release the air update framework and therefore there&#8217;s no longer<br />
need to use our own library to achieve a self updating application.</p>
<p>If you have any questions feel free to expose them here and I&#8217;ll address them as soon as I can.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=How%20to%20build%20a%20contact%20manager%20in%20AIR%20using%20XML%20-%20Part%202&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fxml%2Fhow-to-build-a-contact-manager-in-air-using-xml-part-2%2F" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=How%20to%20build%20a%20contact%20manager%20in%20AIR%20using%20XML%20-%20Part%202&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fxml%2Fhow-to-build-a-contact-manager-in-air-using-xml-part-2%2F');"><img src="http://www.thetechlabs.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Save/Bookmark"/></a>

	</p><img src="http://feedproxy.google.com/~r/TheTechLabs_xml/~4/t1GsW73rOeI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.thetechlabs.com/xml/how-to-build-a-contact-manager-in-air-using-xml-part-2/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.thetechlabs.com/xml/how-to-build-a-contact-manager-in-air-using-xml-part-2/</feedburner:origLink></item>
		<item>
		<title>Creating a Weather Widget with XML and AS3</title>
		<link>http://feedproxy.google.com/~r/TheTechLabs_xml/~3/pxYdTWz7MLg/</link>
		<comments>http://www.thetechlabs.com/xml/creating-a-weather-widget-with-xml-and-as3/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 23:15:24 +0000</pubDate>
		<dc:creator>Fausto Carrera</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<category><![CDATA[Webservices]]></category>

		<category><![CDATA[XML]]></category>

		<category><![CDATA[adobe flash]]></category>

		<category><![CDATA[API]]></category>

		<category><![CDATA[as3]]></category>

		<category><![CDATA[how-to]]></category>

		<category><![CDATA[tutorial]]></category>

		<category><![CDATA[weather service]]></category>

		<guid isPermaLink="false">http://www.thetechlabs.com/?p=80</guid>
		<description><![CDATA[<p>In this tutorial I&#8217;m presenting you a little weather widget, that could come handy for travel websites, or our personal page. If you make some changes on the code, you could show a different interface on your website, according to the weather on your city. Pretty cool stuff. We gonna connect weather.com XML data file with our flash widget. Weather.com offers us a free service to do that.</p>
<small><em>posted in <a href="http://www.thetechlabs.com/category/flash/">Flash</a> by Fausto Carrera <a href="http://www.thetechlabs.com/xml/creating-a-weather-widget-with-xml-and-as3/#comments">Leave A Comment</a><br />&copy;2008 <a href="http://www.thetechlabs.com">The Tech Labs</a>. All Rights Reserved.</em></small>]]></description>
			<content:encoded><![CDATA[<p>In this tutorial I&#8217;m presenting you a little weather widget, that could come handy for travel websites, or our personal page. If you make some changes on the code, you could show a different interface on your website, according to the weather on your city. Pretty cool stuff. We gonna connect weather.com XML data file with our flash widget. Weather.com offers us a free service to do that.</p>
<h3>Requirements</h3>
<p><strong>Adobe Flash CS3</strong></p>
<p><a title="Try / buy" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.adobe.com/products/flash/');" href="http://www.adobe.com/products/flash/" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.adobe.com/products/flash/');" target="_blank">Try / Buy</a></p>
<p><strong>Source Files</strong></p>
<p><a title="Download Source Files" onclick="javascript:pageTracker._trackPageview('/downloads/tutorials/files/flash/fcarrera/flickrsearchengine/flickrsearchengine_sfiles.zip');" href="http://thetechlabs.com/tutorials/files/flash/fcarrera/weather/tutorial_weather_ xml_as3.rar"  target="_self">Download</a></p>
<h3>Sign up to weather.com</h3>
<p>The first thing we gonna do is login in our weather.com account:</p>
<p><a href="https://registration.weather.com/ursa/profile" onclick="javascript:pageTracker._trackPageview('oclicks/https://registration.weather.com/ursa/profile');">https://registration.weather.com/ursa/profile</a></p>
<p><img class="alignnone size-full wp-image-70" title="001" src="http://www.thetechlabs.com/wp-content/uploads/2008/07/001.png" alt="" width="499" height="193" /></p>
<p>Or if we already don&#8217;t have an account we could register for free in here:</p>
<p><a href="https://registration.weather.com/ursa/profile/new?" onclick="javascript:pageTracker._trackPageview('oclicks/https://registration.weather.com/ursa/profile/new?');">https://registration.weather.com/ursa/profile/new?</a></p>
<p><img class="alignnone size-full wp-image-71" title="002" src="http://www.thetechlabs.com/wp-content/uploads/2008/07/002.png" alt="" width="500" height="309" /></p>
<h3>Registering for weather.com XML Data Feed</h3>
<p>Once we are in our account, we gonna have a page like this one, where on the left we gonna have all the services we are subscribed<br />
and on the right, all the available services, the XML data feed is not there, it&#8217;s a little bit tricky.</p>
<p><img class="alignnone size-full wp-image-72" title="003" src="http://www.thetechlabs.com/wp-content/uploads/2008/07/003.png" alt="" width="500" height="355" /></p>
<p>So, we gonna signup to the XML data feed on this page</p>
<p><a href="https://registration.weather.com/ursa/xmloap/" onclick="javascript:pageTracker._trackPageview('oclicks/https://registration.weather.com/ursa/xmloap/');">https://registration.weather.com/ursa/xmloap/</a></p>
<p>Where we gonna tell to weather.com in which way we gonna use the data. If it&#8217;s for personal purpose, there&#8217;s no problem, but<br />
if it&#8217;s commercial purpose, you have to contact them, but everything is better explained on the mail you are going to receive.</p>
<p><img class="alignnone size-full wp-image-73" title="004" src="http://www.thetechlabs.com/wp-content/uploads/2008/07/004.png" alt="" width="500" height="436" /></p>
<p>So if our registration it&#8217;s oki, we gonna receive an email like this one (check on the spam inbox too, just in case).</p>
<p><img class="alignnone size-full wp-image-74" title="005" src="http://www.thetechlabs.com/wp-content/uploads/2008/07/005.png" alt="" width="500" height="94" /></p>
<p>The email explains us about the service, and there&#8217;s three important things to see in here:</p>
<ul>
<li>Where to download the weather.com SDK (http://download.weather.com/web/xml/sdk.zip)</li>
<li>The weather.com XML Partner ID &amp; License Key</li>
<li>How to make a properly formatted XML request for the service</li>
</ul>
<p><img class="alignnone size-full wp-image-75" title="006" src="http://www.thetechlabs.com/wp-content/uploads/2008/07/006.png" alt="" width="500" height="202" /></p>
<h3>Contents of the wheater.com SDK</h3>
<p>On this package you gonna find a PDF, with the license agreement and some useful information about how to make a request for the services,<br />
and two folder, one with the weather.com logos, and the other with the weather icons we gonna use on this tutorial as reference.<br />
There&#8217;s 3 type of icon sizes, for this tutorial we gonna use the 93&#215;93 icons.</p>
<p>The icons are not too fancy, so we could download a free cool set of weather icons from here:</p>
<p><a href="http://liquidweather.net/icons.php#iconsets" onclick="javascript:pageTracker._trackPageview('oclicks/http://liquidweather.net/icons.php#iconsets');">http://liquidweather.net/icons.php#iconsets</a></p>
<p>This iconsets and backgrounds are from the Liquid Weather++ appi.</p>
<h3>Setting up our api key</h3>
<p>We could put all our data inside flash, like the code of our city, our partner id, and so on, but it&#8217;s gonna be a pain in the ass every time we want to change it.<br />
So, it&#8217;s much better if we load this type of data externally form an XML file. The XML structure should looks like this:</p>
<pre>	ARBA0009
XXXXXXXXX
	XXXXXXXXXX
	m</pre>
<h3>Loading our data in Flash</h3>
<p>Now our hands on AS.</p>
<p>We gonna do all the programming in just 2 frames, pretty easy.</p>
<p>On the first frame, we load all the data to use it when we call the weather.com xml service.</p>
<p>On the second frame, called &#8220;weather&#8221;, we load the weather.com xml and display the data.</p>
<p>So, in our first frame:</p>
<ul>
<li>We define the variables we gonna use</li>
<li>We call the xml that holds our data</li>
<li>Then we pass the data from the xml to our variables</li>
<li>And if everything it&#8217;s oki, we could go to the weather frame</li>
</ul>
<p><img class="alignnone size-full wp-image-76" title="007" src="http://www.thetechlabs.com/wp-content/uploads/2008/07/007.png" alt="" width="301" height="208" /></p>
<pre>stop();

//=================
//ini variables
//=================

//we define our variables to be loaded

var city:String;
var par_id:String;
var key:String;
var units:String;

//call the xml with our data

var data_xml_url:String = "data.xml";
var user_data:XML = new XML();
var data_url:URLRequest = new URLRequest(data_xml_url);
var dataLoader:URLLoader = new URLLoader(data_url);

dataLoader.addEventListener(Event.COMPLETE, dataLoaded);

function dataLoaded(e:Event):void
{
	user_data = XML(dataLoader.data);

	//pass the data from the XML to our variables

	city = user_data.city.toString();
	par_id  = user_data.parid.toString();
	key  = user_data.key.toString();
	units  = user_data.units.toString();

	//if everything it's oki, we could go to the weather frame

	gotoAndStop("weather");
}</pre>
<h3>The weather icons</h3>
<p>To display the different type of weather, we need a movieClip that holds all the possible weathers, there&#8217;s not too much, just 47.<br />
So, we create a new movieclip and call it &#8220;icons_mc&#8221;, and inside the icons_mc we import all the icons from the Weather.com SDK icons folder,<br />
or from the cool icons from liquidweather. There&#8217;s a lil bit differences between the Weather.com SDK icons and the liquidweather icons.<br />
On the weather.com SDK, the icons 25 and 44 are N/A, if you gonna use the liquidweather icons, just replace the 25 and 44 icons with the N/A png.</p>
<p>Don&#8217;t forget to put a stop(); in the first frame of the icons_mc, so the MC start stopped.</p>
<p><img class="alignnone size-full wp-image-77" title="008" src="http://www.thetechlabs.com/wp-content/uploads/2008/07/008.png" alt="" width="500" height="491" /></p>
<h3>Loading the weather.com xml service</h3>
<p>Now we could load the data from weather.com</p>
<p>We allow our swf to make calls from the domain &#8220;xoap.weather.com&#8221;, we make the icons_mc MovieClip invisible, because we don&#8217;t know which icon use yet, and we compose the weather xml url with the variables from the frame 1.</p>
<pre>stop();
//=================
//allow domains
//=================
Security.allowDomain("*", "xoap.weather.com");
//=================
//ini settings
//=================
icons_mc.visible = false;
//=================
//XML
//=================
var weather_xml_url:String = "http://xoap.weather.com/weather/local/"+city+"?cc=*&amp;link=xoap&amp;par="+par_id+"&amp;key="+key+"&amp;unit="+units;</pre>
<p>The xml from weather.com have this structure with some interesting data. As you can see there&#8217;s a lot of useful data to load, but we gonna load just the necessary by now.</p>
<p>Later you could play with it and make an advanced one.</p>
<pre>    en_US
<form>MEDIUM</form>

    C
    km
    km/h
    mb
    mm

    Buenos Aires, Argentina
    1:39 PM
    -34.61
    -58.37
    8:01 AM
    5:52 PM
    -3

    6/27/08 1:00 PM Local Time
    Buenos Aires Air Park, Argentina
    13
    13
    Fog
    20

      1021.0
      falling

      11
      N/A
      360
      N

    82
    2.5

      <em>2</em>
      Low

    10

      23
      Waning Crescent</pre>
<h3>Displaying the data</h3>
<p>To display the data, we have three different sprites:</p>
<ul>
<li>The icons MovieClip</li>
<li>A dynamic text field to load the outside temp called &#8220;temp_txt&#8221;</li>
<li>A dynamic text filed in the bottom to make a lil speech about how feels to be outside called &#8220;info_txt&#8221;</li>
</ul>
<p><img class="alignnone size-full wp-image-77" title="009" src="http://www.thetechlabs.com/wp-content/uploads/2008/07/009.png" alt="" width="500" height="491" /></p>
<p>Our main interest is on the XML file on the icon number, so we could show the right icon.</p>
<p>We load the xml using our well formatted &#8220;weather_xml_url&#8221;, and traverse the xml three to find what we are looking for.</p>
<p>In this step we:</p>
<ul>
<li>we load the temp on the temp_txt text field</li>
<li>make the icons visible, load the icon number and tell the icons:mc to stopn on thet icon frame</li>
<li>and finally we set the complementary text</li>
</ul>
<pre>var weather:XML = new XML();
var weather_url:URLRequest = new URLRequest(weather_xml_url);
var weatherLoader:URLLoader = new URLLoader(weather_url);

weatherLoader.addEventListener(Event.COMPLETE, weatherLoaded);

function weatherLoaded(e:Event):void
{
	weather = XML(weatherLoader.data);

	//we load the temp on the temp_txt text field
	temp_txt.text = weather.cc.tmp;

	//we make the icons visible, load the icon number and tell the icons:mc to stopn on thet icon frame
	icons_mc.visible = true;

	var weather_icon:int = Number(weather.cc.icon.toString())+1;
	icons_mc.gotoAndStop(weather_icon);

	//and finally we set the complementary text
	var ud:String = weather.head.ud;
	var us:String = weather.head.us;

	var city:String = weather.loc.dnam;
	var time:String = weather.loc.tm;
	var temp:String = weather.cc.tmp;
	var flik:String = weather.cc.flik;
	var term:String;

	if (temp == flik)
	{
		term = "and it feels like "+flik+" degrees,";
	} else {
		term = "but it feels like "+flik+" degrees,";
	}

	var wind_v:String = weather.cc.wind.s;
	var wind_gust:String = weather.cc.wind.gust;
	var wind_d:String = weather.cc.wind.d;
	var wind_t:String = weather.cc.wind.t;

	var hmid:String = weather.cc.hmid;
	var vis:String = weather.cc.vis;

	info_txt.text = "It's "+time+" here in "+city+". It's "+temp+" degrees out there "+term+" the wind blows from the "+wind_t+" at "+wind_v+" "+us+", the humidity is "+hmid+"% and the visibility is "+vis+" "+ud+".";
}</pre>
<p><img class="alignnone size-full wp-image-79" title="010" src="http://www.thetechlabs.com/wp-content/uploads/2008/07/010.png" alt="" width="212" height="258" /></p>
<p>Now we could export our movie and if it&#8217;s cold outside, it&#8217;s good to be inside.</p>
<h3>Final thoughts</h3>
<p>We gonna need to know the international code of our city, so we could go to</p>
<p><a href="http://www.weather.com/common/welcomepage/world.html" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.weather.com/common/welcomepage/world.html');">http://www.weather.com/common/welcomepage/world.html</a></p>
<p>Search for our city, and find the code on our address bar. I know it&#8217;s a lil bit tricky but it works fine.</p>
<p><img class="alignnone size-full wp-image-69" title="011" src="http://www.thetechlabs.com/wp-content/uploads/2008/07/011.png" alt="" width="353" height="72" /></p>
<p>Hope you enjoyed this lil tutorial as much as I enjoyed writing for you.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=Creating%20a%20Weather%20Widget%20with%20XML%20and%20AS3&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fxml%2Fcreating-a-weather-widget-with-xml-and-as3%2F" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=Creating%20a%20Weather%20Widget%20with%20XML%20and%20AS3&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fxml%2Fcreating-a-weather-widget-with-xml-and-as3%2F');"><img src="http://www.thetechlabs.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Save/Bookmark"/></a>

	</p><img src="http://feedproxy.google.com/~r/TheTechLabs_xml/~4/pxYdTWz7MLg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.thetechlabs.com/xml/creating-a-weather-widget-with-xml-and-as3/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.thetechlabs.com/xml/creating-a-weather-widget-with-xml-and-as3/</feedburner:origLink></item>
		<item>
		<title>Make your own Flickr search engine with Flash and AS3</title>
		<link>http://feedproxy.google.com/~r/TheTechLabs_xml/~3/hcC0Kmkhvy4/</link>
		<comments>http://www.thetechlabs.com/xml/make-your-own-flickr-search-engine-with-flash-and-as3/#comments</comments>
		<pubDate>Sat, 21 Jun 2008 15:53:14 +0000</pubDate>
		<dc:creator>Fausto Carrera</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<category><![CDATA[XML]]></category>

		<category><![CDATA[actionscript 3]]></category>

		<category><![CDATA[adobe]]></category>

		<category><![CDATA[as3]]></category>

		<category><![CDATA[flickr search-engine]]></category>

		<category><![CDATA[how-to]]></category>

		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.thetechlabs.com/?p=55</guid>
		<description><![CDATA[<p>Flickr stores on their servers, photos form all their users around the world, and they have an open api so you could interact with it, and make your own developments, like PicNik.com, the photos online editor, where you could import your Flickr photos and make it look really cool.</p>
<p>Now in this tutorial I&#8217;m gonna show you how to interact with the flickr data base, making your own photo search engine, looking for tags on the photos.</p>
<small><em>posted in <a href="http://www.thetechlabs.com/category/flash/">Flash</a> by Fausto Carrera <a href="http://www.thetechlabs.com/xml/make-your-own-flickr-search-engine-with-flash-and-as3/#comments">Leave A Comment</a><br />&copy;2008 <a href="http://www.thetechlabs.com">The Tech Labs</a>. All Rights Reserved.</em></small>]]></description>
			<content:encoded><![CDATA[<p>One of the best things about the internet is that you could search an unimaginable universe of information, text, images, videos, podcasts, blogs, newspapers.</p>
<p>With web 2.0, the community websites come to life, and one of the most famous web2.0 community websites is Flickr.</p>
<p>Flickr stores on their servers, photos form all their users around the world, and they have an open api so you could interact with it, and make your own developments, like PicNik.com, the photos online editor, where you could import your Flickr photos and make it look really cool.</p>
<p>Now in this tutorial I&#8217;m gonna show you how to interact with the flickr data base, making your own photo search engine, looking for tags on the photos.</p>
<h3>Requirements</h3>
<p><strong>Adobe Flash CS3</strong></p>
<p><a title="Try / buy" href="http://www.adobe.com/products/flash/" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.adobe.com/products/flash/');" target="_blank">Try / Buy</a></p>
<p><strong>Source Files</strong></p>
<p><a title="Download Source Files" href="http://www.thetechlabs.com/tutorials/files/flash/fcarrera/flickrsearchengine/flickrsearchengine_sfiles.zip" onclick="javascript:pageTracker._trackPageview('downloads/tutorials/files/flash/fcarrera/flickrsearchengine/flickrsearchengine_sfiles.zip');" target="_self">Download</a></p>
<h3>Step 1</h3>
<p>The first thing we have to do is have a flickr account, so you could sign up fot an API key, necessary to connect with the Flickr data base.</p>
<p>To sign up, we have to go to http://www.flickr.com, if you already have a yahoo! account, just use it!</p>
<p>Once you have your account, you could start uploading your pics to share with your friends, but that another story, by now we gonna sign up for the API key!</p>
<h3>Step 2</h3>
<p>So, go to http://www.flickr.com/services/, where you gonna find this options:</p>
<p><img src="http://thetechlabs.com/wp-content/uploads/2008/06/001.png" border="0" alt="" /></p>
<p>The number 4 is what we are looking for.</p>
<p>Once there we have to provide our name, email and the type of license we are applying. I recommend start with the Non commercial license. <img src='http://www.thetechlabs.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img src="http://thetechlabs.com/wp-content/uploads/2008/06/002.png" border="0" alt="" width="524" height="273" /></p>
<p>Once you sign up, you could check you API id on the Your API Keys section.</p>
<p>The code you need is on the Key, the secret is used for more complex stuff, like callback data from you api to the server, but for this tutorial we don&#8217;t gonna need it.</p>
<p>Take note of your key, we gonna use it later.</p>
<p><img src="http://thetechlabs.com/wp-content/uploads/2008/06/003.png" border="0" alt="" width="524" height="305" /></p>
<h3>Step 3</h3>
<p>Now we gonna interact with the flickr DB and know what kinda data we gonna read from flash.</p>
<p>For this we go to the Flickr API documentation http://www.flickr.com/services/api/</p>
<p>In here we gonna find all the functions have to interact with the flickr data base, we gonna use a common one, the flickr.photos.search.</p>
<p><img src="http://thetechlabs.com/wp-content/uploads/2008/06/004.png" border="0" alt="" /></p>
<p>If we see the documentation about this function, we have a description and a list of parameters that we could pass to find pictures on the Flcikr data base.</p>
<p>By now we gonna go to the end of the page and Explore the API (API Explorer : flickr.photos.search)</p>
<p><img src="http://thetechlabs.com/wp-content/uploads/2008/06/005.png" border="0" alt="" width="525" height="117" /></p>
<p>In here we gonna find a common html form, pretty basic. The item we concern is tags, we gonna fill the tags field with any word:</p>
<p><img src="http://thetechlabs.com/wp-content/uploads/2008/06/006.png" border="0" alt="" /></p>
<p>Go to the end of the page and first select Don&#8217;t sign the call, so we could see the full url of the call, and make the call:</p>
<p><img src="http://thetechlabs.com/wp-content/uploads/2008/06/007.png" border="0" alt="" /></p>
<p>And there you go, here&#8217;s the data Flickr returns us with this call, we are calling to the page http://api.flickr.com/services/rest/<br />
and passing this variables:</p>
<ul>
<li>method=flickr.photos.search</li>
<li>api_key=45e88791aa46e06efe64fea743f3868c</li>
<li>tags=westie</li>
</ul>
<p>The api key in here is a test api key used just for test purpose, the key change every day, so you better use your own key.</p>
<p>As you could notice, Flickr return us an XML with some data</p>
<p><img src="http://thetechlabs.com/wp-content/uploads/2008/06/008.png" border="0" alt="" width="525" height="297" /></p>
<p>There&#8217;s two important things in here, the stat that tells us if the service is running (ok) of if it&#8217;s offline (error), all that you can check it on the documentation.</p>
<p>The second one is the data flickr returns us about the photos, the XML provide us data about:</p>
<ul>
<li>The page number where we are</li>
<li>The number of pages according with the number of photos per page call</li>
<li>The total number of pics we call, the default is 100</li>
<li>The total number of photos with this tag</li>
</ul>
<p>And then the Photos data, giving us info about</p>
<ul>
<li>Photo id</li>
<li>Owner Flickr code</li>
<li>The secret</li>
<li>The server where the pic is located</li>
<li>The farm where is located</li>
<li>The Photo title</li>
<li>If the photo is public</li>
</ul>
<h3>Step 4</h3>
<p>Now with all this new knowledge, we could go to Flash and make our own Flickr search engine.</p>
<p>First we start with a new Flash file (actionScript 3);</p>
<h3>Step 5</h3>
<p>Start with an actions layer, and our search layer.</p>
<p>Our flash file gonna have 2 keyframes, one for the search, and the second to display the images, called &#8220;search&#8221;</p>
<h3>Step 6</h3>
<p>First we create an empty movieclip and we call it &#8220;search_mc&#8221;, put it on the first frame of the search layer.</p>
<p>The instance name of our input textfield must be &#8220;tags_txt&#8221; and the instance name of the button must be &#8220;search_btn&#8221;</p>
<p>Inside of our search movieclip we have an input field and a search button, it could looks like this</p>
<p><img src="http://thetechlabs.com/wp-content/uploads/2008/06/009.png" border="0" alt="" /></p>
<p>Now we could add some code to our first frame on the main time line.</p>
<p>First we set the tag variables</p>
<p>Then we add a mouse event to our search button, if the input field is empty, nothing happens, but if we entered a tag, flash goes to the second frame, the &#8220;search&#8221; frame.</p>
<pre>stop();

//===================================
// get the tag to search
//===================================

var tag:String;

search_mc.search_btn.addEventListener(MouseEvent.CLICK, searchListener);
function searchListener(e:MouseEvent):void
{
	if(search_mc.tags_txt.text != "")
	{
		tag = search_mc.tags_txt.text;
		gotoAndStop("search");
	}
}</pre>
<h3>Step 6</h3>
<p>Oki, so now we are passing our tag from the frame 1 to our search frame.</p>
<p>In here we gonna have an empty movieclip, in our display layer, we gonna call it &#8220;container_mc&#8221;, and inside this movieclip we gonna load our photos.</p>
<p>Now we gonna create our square holder, it must be a square of 75px width and 75px height, that&#8217;s the image size of the thumbnails on flickr.</p>
<p>Inside the square, we have an invisible button, called &#8220;go_btn&#8221;, this is the button that gonna take us to the flickr photo page, and it&#8217;s located on the 0x,0y of the square holder.</p>
<p>it also contains an empty movieclip called &#8220;holder_mc&#8221;, where we gonna load the photo, and it&#8217;s located, like the &#8220;go_btn&#8221; on the 0x,0y of the square holder.</p>
<p><img src="http://thetechlabs.com/wp-content/uploads/2008/06/010.png" border="0" alt="" /></p>
<p>Cool! So, we could add some code on the first frame of the square holder, to load the image comming from the Flickr XML.</p>
<p>To make a cool load we gonna use Caurina transitions tweener, an used to create tweenings and other transitions via ActionScript code for projects built on the Flash platform. It&#8217;s released and maintained for these versions:</p>
<ul>
<li>ActionScript 2.0, for Flash 7+ and Flash Lite 2.0+</li>
<li>ActionScript 2.0, for Flash 8+</li>
<li>ActionSctipt 3.0, for Flash 9+</li>
</ul>
<p>And you can download the last version here: http://code.google.com/p/tweener/</p>
<p>Ok, so let&#8217;s start with the image loader:</p>
<p>first import the classes</p>
<pre>//first we import the necessary class to work
import flash.display.*;
import flash.net.URLRequest;
import flash.events.*;
import caurina.transitions.*;</pre>
<p>Now, let&#8217;s make the load class:</p>
<p>We pass the image source to the function, the function creates a new Loader, to load that image on the<br />
holder_mc movieclip, the we set the alpha of the holder_mc to 0 so we could make a nice alpha transition from 0 to 100 with the caurina class.</p>
<p>I&#8217;m not setting a preloader, but with the progressListener you could set up your own easily.</p>
<pre>function loadImage(img_src:String)
{
	var loader:Loader = new Loader();
	var img_url:String = img_src;
	var request_url:URLRequest = new URLRequest(img_url);
	loader.load(request_url);
	loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);
	loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeListener);

	function progressListener(e:ProgressEvent)
	{
		var bl:int = e.bytesLoaded;
		var bt:int = e.bytesTotal;
		var percent:int = Math.ceil((bl*100)/bt);
	}
	function completeListener(e:Event)
	{
		holder_mc.addChild(loader.content);
		holder_mc.alpha = 0;
		Tweener.addTween(holder_mc, {alpha:1, time:1, transition:"linear"});
	}
}</pre>
<h3>Step 7</h3>
<p>Now, we linkage the square that we gonna load the pictures, as the class Square:</p>
<p><img src="http://thetechlabs.com/wp-content/uploads/2008/06/011.png" border="0" alt="" /></p>
<p>Now we could add some code in our search frame, so we could connect with the Flickr data base, but first we have to know how call that pics:</p>
<p>In this url http://www.flickr.com/services/api/misc.urls.html, you gonna found how format the data flickr provide to call a picture.</p>
<p><img src="http://thetechlabs.com/wp-content/uploads/2008/06/012.png" border="0" alt="" width="524" height="133" /></p>
<p>We gonna use the url</p>
<p>http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}_t.jpg</p>
<p>to call the thumbnails.</p>
<h3>Step 8</h3>
<p>On our search frame, in our main timeline:</p>
<pre>//=================
//import the neccesary classes
//=================
import flash.display.*;
import flash.events.*;
import flash.net.*;
//=================
//allow domains
//=================
Security.allowDomain("*", "api.flickr.com");</pre>
<p>Now we set the ini variables that we gonna need:</p>
<ul>
<li>xpos: the ini x pos of the squares</li>
<li>ypos: the ini y pos of the squares</li>
<li>dif: the difference between an square and the other</li>
<li>totalCols: the total number of columns</li>
<li>count: the count so we could know how much columns we are having</li>
<li>i: the counter</li>
<li>squares_arr: the array that&#8217;s gonna holds the square duplications names</li>
</ul>
<pre>//=================
//ini variables
//=================
var xpos:Number = 0;
var ypos:Number = 0;
var dif:Number = 75;
var totalCols:int = 10;
var count:int = 1;
var i:int = 0;
var squares_arr:Array = [];</pre>
<p>Now we set the flickr ini variables, like your flickr api key:</p>
<p>In here we construct the function url using the variables and the tag provided on the first frame. We start with the page 1 and we gonna load just 50 images.</p>
<pre>//=================
//flickr variable
//=================
var key:String = ""; //your flickr api key
var per_page:int = 50;
var page:int = 1;
var xml_url:String = "http://api.flickr.com/services/rest/?method=flickr.photos.search&amp;api_key="+key+"&amp;tags="+tag+"&amp;per_page="+per_page+"&amp;page="+page;</pre>
<p>And we read the result just like any other XML data, we gonna use the ini variables to make a return while FLash populate the Squares inside the &#8220;container_mc&#8221;</p>
<p>As you can see in the code, we use the data provided by the Flickr XML to construct the image source and load it using the function on the Square movieclip</p>
<pre>//=================
//XML
//=================
var pics:XML = new XML();
var pics_url:URLRequest = new URLRequest(xml_url);
var picsLoader:URLLoader = new URLLoader(pics_url);
picsLoader.addEventListener(Event.COMPLETE, picsLoaded);
function picsLoaded(e:Event):void
{
	pics = XML(picsLoader.data);

	var stat:String = pics.@stat.toString();
	var totalPages:int = pics.photos.@pages;
	var totalPics:int = pics.photos.@total;

	/*
	trace("status: "+stat);
	trace("Total pages: "+totalPages);
	trace("Total pics: "+totalPics);
	trace("-=-=-=-=-=-=-=-=-=-=-=");
	*/

	var allPics:XMLList = pics.photos.*;
	for each (var photo:XML in allPics)
	{
		var pic_src:String = "http://farm"+photo.@farm+".static.flickr.com/"+photo.@server+"/"+photo.@id+"_"+photo.@secret+"_s.jpg";
		/*
		trace("title: "+photo.@title+" owner: "+photo.@owner);
		trace("Source: "+pic_src);
		trace("-=-=-=-=-=-=-=-=-=-=-=");
		*/
		//
		var newName:String = "square_"+i;
		var my_square:Square = new Square();
		my_square.name = newName;
		my_square.x = xpos;
		my_square.y = ypos;
		my_square.loadImage(pic_src);
		//
		my_square.photo_id = photo.@id;
		my_square.photo_owner = photo.@owner;
		//
		squares_arr.push(my_square);
		container_mc.addChild(my_square);
		//
		if (count &lt; totalCols)
		{
			xpos += dif;
			count++;
		}
		else
		{
			xpos = 0;
			ypos += dif;
			count = 1;
		}
		i++;
	}
}</pre>
<h3>Step 9</h3>
<p>the last thing to do is pass the owner and the photo id to our photo holder, so we could set the right url to go</p>
<p>If you see this two lines in our previous code:</p>
<pre>my_square.photo_id = photo.@id;
my_square.photo_owner = photo.@owner;</pre>
<p>We already passed the variables to our holder.</p>
<p>Now on our photo holder, we set the necessary variables and add the event to our &#8220;go_btn&#8221;</p>
<pre>//================================
// flickr photo page
//================================
var photo_id:String;
var photo_owner:String;
var photo_url:String = "http://www.flickr.com/photos/";
//================================
//add evento to the button
//================================
go_btn.addEventListener(MouseEvent.CLICK, goListener);
function goListener(e:MouseEvent):void
{
	var url:String = photo_url+"/"+photo_owner+"/"+photo_id;
	var req:URLRequest = new URLRequest(url);
	navigateToURL(req, "_blank");
}</pre>
<h3>Step 10</h3>
<p>Now you are ready to ctrl+enter and see how it works.</p>
<p>On the source files you gonna find that I set the first search as &#8220;westie&#8221;, it&#8217;s my favorite dog, but you could leave it blank if you want.</p>
<p>At the end you should have something like this:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="524" height="290" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="quality" value="best" /><param name="scale" value="showall" /><param name="src" value="/tutorials/files/flash/fcarrera/flickrsearchengine/demo/flickr.swf" /><param name="align" value="top" /><embed type="application/x-shockwave-flash" width="524" height="290" src="/tutorials/files/flash/fcarrera/flickrsearchengine/demo/flickr.swf" align="top" scale="showall" quality="best"></embed></object></p>
<p>Feel free to explore the flickr api service and look all the cool stuff yahoo! is sharing with all of us.</p>
<p>Here&#8217;s some cool examples and resources:</p>
<ul>
<li><a href="http://www.picnik.com/" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.picnik.com/');" target="_blank">Picnik - edit photos the easy way, online in your browser</a></li>
<li><a href="http://www.airtightinteractive.com/projects/related_tag_browser/app/" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.airtightinteractive.com/projects/related_tag_browser/app/');" target="_blank">Flickr Related Tag Browser</a></li>
<li><a href="http://www.airtightinteractive.com/projects/tiltviewer/app/" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.airtightinteractive.com/projects/tiltviewer/app/');" target="_blank">TiltViewer is a free, customizable 3D Flash image viewing application</a></li>
<li><a href="http://stunningnikon.com/d80/" onclick="javascript:pageTracker._trackPageview('oclicks/http://stunningnikon.com/d80/');" target="_blank">stunning nikon - dslr</a></li>
<li><a href="http://www.flickrbits.com/" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.flickrbits.com/');" target="_blank">Flickr Tools on Flickrbits » The definitive collection of Flickr tools, plugins and API applications</a></li>
<li><a href="http://code.google.com/p/as3flickrlib/" onclick="javascript:pageTracker._trackPageview('oclicks/http://code.google.com/p/as3flickrlib/');" target="_blank">The Flickr library is an ActionScript 3.0 API for the online photo sharing application, Flickr. It provides access to the entire Flickr API</a></li>
</ul>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=Make%20your%20own%20Flickr%20search%20engine%20with%20Flash%20and%20AS3&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fxml%2Fmake-your-own-flickr-search-engine-with-flash-and-as3%2F" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=Make%20your%20own%20Flickr%20search%20engine%20with%20Flash%20and%20AS3&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fxml%2Fmake-your-own-flickr-search-engine-with-flash-and-as3%2F');"><img src="http://www.thetechlabs.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Save/Bookmark"/></a>

	</p><img src="http://feedproxy.google.com/~r/TheTechLabs_xml/~4/hcC0Kmkhvy4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.thetechlabs.com/xml/make-your-own-flickr-search-engine-with-flash-and-as3/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.thetechlabs.com/xml/make-your-own-flickr-search-engine-with-flash-and-as3/</feedburner:origLink></item>
		<item>
		<title>How to build a contact manager in AIR using XML</title>
		<link>http://feedproxy.google.com/~r/TheTechLabs_xml/~3/I6XsYC60ipc/</link>
		<comments>http://www.thetechlabs.com/xml/how-to-build-a-contact-manager-in-air-using-xml/#comments</comments>
		<pubDate>Sat, 24 May 2008 22:39:17 +0000</pubDate>
		<dc:creator>Pedro Furtado</dc:creator>
		
		<category><![CDATA[AIR]]></category>

		<category><![CDATA[Flex]]></category>

		<category><![CDATA[XML]]></category>

		<category><![CDATA[adobe]]></category>

		<category><![CDATA[contact manager]]></category>

		<category><![CDATA[how-to]]></category>

		<category><![CDATA[ria]]></category>

		<guid isPermaLink="false">http://thetechlabs.com/?p=3</guid>
		<description><![CDATA[<p>This will be the first part of our first tutorial: How to build a contact manager in AIR using XML. For the first part of this tutorial we’ll be reading, parsing and searching an XML into an AIR application and going through the whole getting it to compile and exporting a release version.</p>
<small><em>posted in <a href="http://www.thetechlabs.com/category/air/">AIR</a> by Pedro Furtado <a href="http://www.thetechlabs.com/xml/how-to-build-a-contact-manager-in-air-using-xml/#comments">Leave A Comment</a><br />&copy;2008 <a href="http://www.thetechlabs.com">The Tech Labs</a>. All Rights Reserved.</em></small>]]></description>
			<content:encoded><![CDATA[<p>Hello from <a href="http://www.dreaminginflash.com/" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.dreaminginflash.com/');" target="_blank">Dreaming in flash’s team</a></p>
<p>We’ve been invited by Carlos to make some tutorials on what we know best, Flash and Flex.</p>
<p>This will be the first part of our first tutorial: How to build a contact manager in AIR using XML.</p>
<p>For the first part of this tutorial we’ll be reading, parsing and searching an XML into an AIR application and going through the whole getting it to compile and exporting a release version. So first things first, you’ll need Flex 3 SDK, or Flex 3 IDE, that you can get for free over at Adobe, or the 30 day trial if you go for the builder.</p>
<p>After you’ve installed it we’re good to go. Open Flex, and create a new Flex Project. Select the Desktop Application option and we’re all set to start coding.</p>
<p style="text-align: center;"><img class="alignnone size-thumbnail wp-image-1349" style="border: 0pt none; vertical-align: top; margin-top: 10px; margin-bottom: 10px;" src="http://flashenabled.files.wordpress.com/2008/05/new-air-project.jpg?w=225&amp;h=196" alt="" width="225" height="196" /></p>
<p style="text-align: left;">
<p>First we must start by adding an initialize handler to our application so that we know when we can start working.</p>
<pre>&lt;mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" initialize="{init()}" layout="absolute" viewSourceURL="srcview/index.html" height="451"&gt;
&lt;!-- // --&gt;
&lt;mx:Script&gt;
&lt;![CDATA[
<strong>import</strong> mx.collections.XMLListCollection;</pre>
<p>Then we create our variables and initiate them, set an Event handler to handle the loading of the XML File, and start the loading process.</p>
<pre><strong>private</strong> <strong>var</strong> myXml:XML;
<strong>private</strong> <strong>var</strong> myLoader:URLLoader;
<strong>private</strong> <strong>var</strong> myContactsCol:XMLListCollection;</pre>
<p>The handler is simple, it casts the received data to an XML Object and initializes the XMLListCollection to our full data. (More on why we use a XmlListCollection on part 2)</p>
<pre><strong>public</strong> <strong>function</strong> init():<strong>void</strong>
{
<strong>var</strong> myReq:URLRequest = <strong>new</strong> URLRequest(<strong>'data.xml'</strong>);
myLoader = <strong>new</strong> URLLoader()
myLoader.addEventListener(Event.COMPLETE, dataComplete);
myLoader.load(myReq);
}</pre>
<p>Now here's where the 'magic' happens the search and updating of our datagrid.</p>
<pre><strong>private</strong> <strong>function</strong> dataComplete(e:Event):<strong>void</strong>
{
myXml = <strong>new</strong> XML(myLoader.data.toString());
myContactsCol = <strong>new</strong> XMLListCollection(myXml..contact);
myDg.dataProvider = myContactsCol;
myDg.invalidateList()
}</pre>
<p>I know this line might look scary but it really isn't, it's simple E4X at work, what we do is to get an XMLList out of our xml where the name node of each contact node matches our expression, in this case any name that contains our search string. And then we refresh the visual part of the datagrid.</p>
<pre><strong>private</strong> <strong>function</strong> updateList():<strong>void</strong>
{
myContactsCol = <strong>new</strong> XMLListCollection(myXml..contact.(name.toLowerCase().indexOf(search_txt.text.toLowerCase()) != -1 ))
myDg.dataProvider = myContactsCol;
myDg.invalidateList()
}
]]&gt;
&lt;/mx:Script&gt;</pre>
<p>Now for the MXML part of our application, it’s simple enough we drag our datagrid to our workspace, name it and set the names for it’s columns, note the dataField property this related directly to the name of the XML Nodes.</p>
<pre>&lt;mx:DataGrid bottom="60" top="10" left="10" id="myDg"&gt;
&lt;mx:columns&gt;
&lt;mx:DataGridColumn headerText="Name" dataField="name"/&gt;
&lt;mx:DataGridColumn headerText="Telphone" dataField="telephone"/&gt;
&lt;mx:DataGridColumn headerText="Email" dataField="email"/&gt;
&lt;/mx:columns&gt;
&lt;/mx:DataGrid&gt;
&lt;mx:Label x="10" text="Search:" bottom="10"/&gt;
&lt;mx:TextInput x="65" id="search_txt" bottom="10"/&gt;</pre>
<p>And finally we just set the click handler for the GO! button to update our search results.</p>
<pre>&lt;mx:Button x="233" label="Go!" id="go_btn" click="{updateList()}" bottom="10"/&gt;
&lt;/mx:WindowedApplication&gt;</pre>
<p>Now in order to publish the application we need to create a certificate (or use an existing one), this can be easily done by using create new certificate option, which will create an unsigned certificate, or by getting one from Twathe or Verisign.</p>
<p style="text-align: center;"><img class="alignnone size-thumbnail wp-image-1350 aligncenter" src="http://flashenabled.files.wordpress.com/2008/05/export-release-build.jpg?w=224&amp;h=204" alt="" width="224" height="204" /></p>
<p style="text-align: center;"><img class="alignnone size-thumbnail wp-image-1347 aligncenter" src="http://flashenabled.files.wordpress.com/2008/05/create-new-certificate.jpg?w=227&amp;h=112" alt="" width="227" height="112" /></p>
<p style="text-align: left;">
<p>After that you just save your certificate, select it and hit finish!<span class="apple-converted-space"> </span></p>
<p>We now have a fully working Air application.</p>
<p>In part 2 we’ll go through Editing and saving the file, how to set up our bindings so that both the Xml, and the results are updated automatically, go through the data types that we use and how to use an auto-updating library for your application.</p>
<p><a href="http://thetechlabs.com/flashenabledblog/tutorials/FEXMLContacts.zip" onclick="javascript:pageTracker._trackPageview('downloads/flashenabledblog/tutorials/FEXMLContacts.zip');" target="_blank">Download the support files</a></p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=How%20to%20build%20a%20contact%20manager%20in%20AIR%20using%20XML&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fxml%2Fhow-to-build-a-contact-manager-in-air-using-xml%2F" onclick="javascript:pageTracker._trackPageview('oclicks/http://www.addtoany.com/share_save?sitename=The%20Tech%20Labs&amp;siteurl=http%3A%2F%2Fwww.thetechlabs.com%2F&amp;linkname=How%20to%20build%20a%20contact%20manager%20in%20AIR%20using%20XML&amp;linkurl=http%3A%2F%2Fwww.thetechlabs.com%2Fxml%2Fhow-to-build-a-contact-manager-in-air-using-xml%2F');"><img src="http://www.thetechlabs.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Save/Bookmark"/></a>

	</p><img src="http://feedproxy.google.com/~r/TheTechLabs_xml/~4/I6XsYC60ipc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.thetechlabs.com/xml/how-to-build-a-contact-manager-in-air-using-xml/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.thetechlabs.com/xml/how-to-build-a-contact-manager-in-air-using-xml/</feedburner:origLink></item>
	</channel>
</rss>
