<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>RiaCodes &#187; Flex</title>
	<atom:link href="http://www.riacodes.com/category/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.riacodes.com</link>
	<description>Resources, tutorials , tips &#38; tricks for RIA : Flex, Flash, Air, AS3</description>
	<lastBuildDate>Thu, 15 Jul 2010 16:11:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Create a Show/Hide Sliding Panel using Flex</title>
		<link>http://www.riacodes.com/flex/create-a-show-hide-sliding-panel-using-flex/</link>
		<comments>http://www.riacodes.com/flex/create-a-show-hide-sliding-panel-using-flex/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 15:16:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1083</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flex_sliding-panel/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>This tutorial will show you how to add a nice hide/show sliding panel at the top of your flex application that when clicked will reveal itself.<br />
<span id="more-1083"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flex_sliding-panel/demo" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flex_sliding-panel/demo/srcview/SlidingPanel.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flex project named SlidingPanel, set the name of the main MXML application file to Main.mxml and set its layout to absolute. </p>
<p><em>2.</em> First let&#8217;s create the top panel. To do so add a Canvas component and give it an id of &#8220;panel&#8221;. To make it open or close, add a Button at the bottom of the canvas and set its properties as shown in the code below. Its click event will be handled by the toggleBtn function that we are going to create later.<br />
When the application will be launched we want only the button &#8220;Open&#8221; to be visible so in order to do that set the canvas y property to -180.</p>
<pre class="brush: xml;">
&lt;mx:Canvas id=&quot;panel&quot; width=&quot;100%&quot; height=&quot;200&quot; y=&quot;-180&quot; backgroundColor=&quot;#000000&quot;&gt;
		&lt;mx:LinkButton id=&quot;btn&quot; width=&quot;100%&quot;  height=&quot;21&quot;
			bottom=&quot;0&quot; horizontalCenter=&quot;0&quot;
			label=&quot;Open&quot;
		  	click=&quot;toggleBtn(event)&quot;/&gt;
&lt;/mx:Canvas&gt;
</pre>
<p>We let you put your own content inside this panel.</p>
<p><em>3.</em> To make the panel appear and disappear we need to create 2 Move effects, one to slide out and the other to slide in.<br />
The first one will be used to open the panel. To do so set its yTo property to 0 so that the panel is fully visible and when its effectEnd event will occur we set the label property of the button to &#8220;Close&#8221;.<br />
Follow the same process for the second Move effect that we&#8217;ll use to close the panel.<br />
To make these effects more eye-catching, we add a bounce easing.</p>
<pre class="brush: xml;">
&lt;mx:Move id=&quot;panelOut&quot; target=&quot;{panel}&quot; yTo=&quot;0&quot; effectEnd=&quot;btn.label='Close'&quot;
		duration=&quot;1500&quot; easingFunction=&quot;Bounce.easeOut&quot;/&gt;
&lt;mx:Move id=&quot;panelIn&quot; target=&quot;{panel}&quot; yTo=&quot;-180&quot; effectEnd=&quot;btn.label='Open'&quot;
		duration=&quot;1000&quot; easingFunction=&quot;Bounce.easeIn&quot;/&gt;
</pre>
<p><em>4.</em> Next add a Script section to create the toggleBtn function. In this function we check whether the panel is opened or not and we play the corresponding Move effect.</p>
<pre class="brush: jscript;">
&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.effects.easing.*;

			private function toggleBtn(e:MouseEvent):void{
				if(e.currentTarget.label== 'Open')
					 panelOut.play();
				else
					panelIn.play();
			}
		]]&gt;
&lt;/mx:Script&gt;
</pre>
<p><em>5.</em> Finally we add some CSS to custom the app.</p>
<pre class="brush: xml;">
&lt;mx:Style&gt;
		Application{
		   backgroundGradientColors: #E2DEDE, #3C2580;
		}
		LinkButton {
		   rollOverColor: #000000;
		   selectionColor: #000000;
		   color: #ffffff;
		   textRollOverColor: #ffffff;
		   textAlign: center;
		}
&lt;/mx:Style&gt;
</pre>
<p><em></em> Here&#8217;s the final code, run your application to see it in action.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;absolute&quot;&gt;

	&lt;mx:Style&gt;
		Application{
		   backgroundGradientColors: #E2DEDE, #3C2580;
		}
		LinkButton {
		   rollOverColor: #000000;
		   selectionColor: #000000;
		   color: #ffffff;
		   textRollOverColor: #ffffff;
		   textAlign: center;
		}
	&lt;/mx:Style&gt;

	&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.effects.easing.*;

			private function toggleBtn(e:MouseEvent):void{
				if(e.currentTarget.label== 'Open')
					 panelOut.play();
				else
					panelIn.play();
			}
		]]&gt;
	&lt;/mx:Script&gt;

	&lt;mx:Move id=&quot;panelOut&quot; target=&quot;{panel}&quot; yTo=&quot;0&quot; effectEnd=&quot;btn.label='Close'&quot;
		duration=&quot;1500&quot; easingFunction=&quot;Bounce.easeOut&quot;/&gt;
	&lt;mx:Move id=&quot;panelIn&quot; target=&quot;{panel}&quot; yTo=&quot;-180&quot; effectEnd=&quot;btn.label='Open'&quot;
		duration=&quot;1000&quot; easingFunction=&quot;Bounce.easeIn&quot;/&gt;        

	&lt;mx:Canvas id=&quot;panel&quot; width=&quot;100%&quot; height=&quot;200&quot; y=&quot;-180&quot; backgroundColor=&quot;#000000&quot;&gt;
       &lt;!--Add the content of your sliding panel here  --&gt;
		&lt;mx:LinkButton id=&quot;btn&quot; width=&quot;100%&quot;  height=&quot;21&quot;
			bottom=&quot;0&quot; horizontalCenter=&quot;0&quot;
			label=&quot;Open&quot;
		  	click=&quot;toggleBtn(event)&quot;/&gt;
	&lt;/mx:Canvas&gt;

	&lt;!--Add the content of your page here--&gt;

&lt;/mx:Application&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flex/create-a-show-hide-sliding-panel-using-flex/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Build an Automatic Slideshow with Flex</title>
		<link>http://www.riacodes.com/flex/build-an-automatic-slideshow-with-flex/</link>
		<comments>http://www.riacodes.com/flex/build-an-automatic-slideshow-with-flex/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 11:47:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1061</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flex_automatic-slideshow/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>This Flex tutorial will show you how to build a slideshow that will change the images automatically with a special appearance effect.</p>
<p><span id="more-1061"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flex_automatic-slideshow/demo" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flex_automatic-slideshow/demo/srcview/Slideshow.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flex project named Slideshow, set the name of the main MXML application file to Main.mxml and set its layout to vertical. </p>
<p><em>2.</em> First add an Image component and give it an id of &#8220;img&#8221;. Everything else will happen in the Script section. </p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;&gt;

	&lt;mx:Image id=&quot;img&quot;/&gt;

&lt;/mx:Application&gt;
</pre>
<p><em>3.</em> Add a Script section.<br />
Create 2 variables, one as an array that contains the pictures and the other that keeps track of the image that will be displayed.<br />
Put your image files inside an assets folder.</p>
<pre class="brush: jscript;">
&lt;mx:Script&gt;
	&lt;![CDATA[

private var pictures : Array = [&quot;ali1.jpg&quot;,&quot;ali2.jpg&quot;,&quot;ali3.jpg&quot;,&quot;ali4.jpg&quot;];
private var index:int = 0;

]]&gt;
&lt;/mx:Script&gt;
</pre>
<p><em>4.</em> Create an init() function that will be called for the creationComplete event of the Application.</p>
<pre class="brush: xml; highlight: [3];">
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;
	verticalAlign=&quot;middle&quot;
	creationComplete=&quot;init()&quot;&gt;
</pre>
<p>In the init() function, load the first picture and increment the index variable. Next declare a Timer variable and add its event listener that will be handled by the changeImage function.</p>
<pre class="brush: jscript;">
private function init():void{

	img.load(&quot;assets/&quot;+pictures[0]);
	index ++;

	var timer:Timer = new Timer(5000);
	timer.addEventListener(TimerEvent.TIMER,changeImage);
	timer.start();
}
</pre>
<p><em>5.</em> In the changeImage function we simply load the next image and increment the index variable if the array&#8217;s limit hasn&#8217;t been reached.</p>
<pre class="brush: jscript;">
private function changeImage(e:TimerEvent):void{
	img.load(&quot;assets/&quot;+pictures[index]);
	if(index&lt;pictures.length -1)
		index++;
	else
		index=0;
}
</pre>
<p><em>6.</em> So far if you test your app, all should work fine but to make it more special we will add an Iris effect to the image&#8217;s  appearance.</p>
<pre class="brush: jscript; highlight: [3];">
private function init():void{

	img.setStyle(&quot;completeEffect&quot;,Iris);

	img.load(&quot;assets/&quot;+pictures[0]);
	index ++;

	var timer:Timer = new Timer(5000);
	timer.addEventListener(TimerEvent.TIMER,changeImage);
	timer.start();
}
</pre>
<p><em>7.</em> Here&#8217;s the final code, run your application to test it.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;
	verticalAlign=&quot;middle&quot;
	backgroundGradientAlphas=&quot;[1.0, 1.0]&quot;
	backgroundGradientColors=&quot;[#17043B, #000000]&quot;
	creationComplete=&quot;init()&quot;&gt;

&lt;mx:Script&gt;
	&lt;![CDATA[
		import mx.effects.Iris;

		private var pictures : Array = [&quot;ali1.jpg&quot;,&quot;ali2.jpg&quot;,&quot;ali3.jpg&quot;,&quot;ali4.jpg&quot;];
		private var index:int = 0;

		private function init():void{

			img.setStyle(&quot;completeEffect&quot;,Iris);

			img.load(&quot;assets/&quot;+pictures[0]);
			index ++;

			var timer:Timer = new Timer(5000);
			timer.addEventListener(TimerEvent.TIMER,changeImage);
			timer.start();
		}

		private function changeImage(e:TimerEvent):void{
			img.load(&quot;assets/&quot;+pictures[index]);
			if(index&lt;pictures.length -1)
				index++;
			else
				index=0;
		}
	]]&gt;
&lt;/mx:Script&gt;

	&lt;mx:Image id=&quot;img&quot;/&gt;

&lt;/mx:Application&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flex/build-an-automatic-slideshow-with-flex/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Build a XML Driven Accordion Image Gallery</title>
		<link>http://www.riacodes.com/flex/build-a-xml-driven-accordion-image-gallery/</link>
		<comments>http://www.riacodes.com/flex/build-a-xml-driven-accordion-image-gallery/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 11:15:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1024</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flex_accordion-image-gallery/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>The following Flex tutorial will show you how to build an accordion image gallery populated using XML datas. </p>
<p><span id="more-1024"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flex_accordion-image-gallery/demo" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flex_accordion-image-gallery/demo/srcview/AccordionGallery.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p>The photos showcased in our gallery are part of <a href="http://www.smashingmagazine.com/2009/03/15/35-really-stunning-photos-and-pictures/" target="_blank">&#8220;35 (Really) Stunning Photos and Pictures&#8221; Smashing magazine</a> list.</p>
<p><em>1.</em> Create a new flex project named AccordionGallery, set the name of the main MXML application file to Main.mxml and set its layout to vertical. </p>
<p><em>2.</em> All of the informations about the images showcased in the accordion gallery are stored in an XML file. Create an xml file that match the following structure and save it as datas.xml in the src directory :</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;gallery&gt;
	&lt;photo&gt;
		&lt;title&gt;Photo by Simon Shareef&lt;/title&gt;
		&lt;file&gt;1.jpg&lt;/file&gt;
	&lt;/photo&gt;
	&lt;photo&gt;
		&lt;title&gt;Photo by In Cherl Kim&lt;/title&gt;
		&lt;file&gt;2.jpg&lt;/file&gt;
	&lt;/photo&gt;
	&lt;photo&gt;
		&lt;title&gt;Photo by Perico Terrades&lt;/title&gt;
		&lt;file&gt;3.jpg&lt;/file&gt;
	&lt;/photo&gt;
	&lt;photo&gt;
		&lt;title&gt;Photo by Frank Daske&lt;/title&gt;
		&lt;file&gt;4.jpg&lt;/file&gt;
	&lt;/photo&gt;
&lt;/gallery&gt;
</pre>
<p><em>3. </em> Next, create an assets folder and put your image files inside.</p>
<p><em>4.</em> In the main.mxml file, use the HTTPService component to load the Xml datas:</p>
<pre class="brush: xml;">
&lt;mx:HTTPService id=&quot;service&quot; url=&quot;datas.xml&quot; result=&quot;serviceHandler(event)&quot;/&gt;
</pre>
<p><em>5.</em> Next create a Script section. Declare a variable named pictures as an arraycollection and defined as bindable. This variable will hold the datas retrieved from the xml in the serviceHandler function : </p>
<pre class="brush: jscript;">
&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.rpc.events.ResultEvent;
			import mx.collections.ArrayCollection;

			[Bindable] private var pictures : ArrayCollection;

			private function serviceHandler(event:ResultEvent):void{
				pictures = event.result.gallery.photo;
			}
		]]&gt;
&lt;/mx:Script&gt;
</pre>
<p><em>6.</em> In order to finish the xml datas&#8217; loading , don&#8217;t forget to call the HTTPService&#8217;s send method : </p>
<pre class="brush: xml;">
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;
	creationComplete=&quot;service.send()&quot; &gt;
</pre>
<p><em>7.</em> Now we just have to create the accordion. To do so, first add an Accordion navigator and set its width and height.<br />
Next use a Repeater and bind its dataProvider with the pictures variable.<br />
Inside the Repeater, add a VBox component and bind its label property to the picture&#8217;s title. Inside the VBox add an Image component and bind its source to the file property of the picture.</p>
<pre class="brush: xml;">
&lt;mx:Accordion width=&quot;400&quot; height=&quot;400&quot;&gt;
		&lt;mx:Repeater id=&quot;rep&quot; dataProvider=&quot;{pictures}&quot;&gt;
			&lt;mx:VBox width=&quot;100%&quot; height=&quot;100%&quot;
				verticalAlign=&quot;middle&quot; horizontalAlign=&quot;center&quot;
				label=&quot;{rep.currentItem.title}&quot;  &gt;
				&lt;mx:Image source=&quot;assets/{rep.currentItem.file}&quot;/&gt;
			&lt;/mx:VBox&gt;
		&lt;/mx:Repeater&gt;
&lt;/mx:Accordion&gt;
</pre>
<p><em>8.</em> To custom the accordion change its openDuration property and set its creationCompleteEffect to an Iris effect so that the accordion&#8217;s appearance will be more attractive.</p>
<pre class="brush: xml; highlight: [2];">
&lt;mx:Accordion x=&quot;190&quot; y=&quot;19&quot; width=&quot;400&quot; height=&quot;400&quot;
creationCompleteEffect=&quot;Iris&quot; openDuration=&quot;500&quot;&gt;
</pre>
<p><em>9.</em> Finally we add some css to custom the app.</p>
<pre class="brush: xml;">
&lt;mx:Style&gt;
		Application {
			verticalAlign : middle;
			backgroundGradientColors:#5F73EF,#02072B;
		}

		Accordion {
   			headerStyleName: &quot;myaccordionHeader&quot;;
		}

		.myaccordionHeader {
		   color: #02072B;
		   fontFamily: Georgia;
		   fontSize: 14;
		   fontStyle: italic;

		}
&lt;/mx:Style&gt;
</pre>
<p><em>10.</em> That&#8217;s it, here&#8217;s the final code, run your application to test it.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;
	creationComplete=&quot;service.send()&quot; &gt;

	&lt;mx:Style&gt;
		Application {
			verticalAlign : middle;
			backgroundGradientColors:#5F73EF,#02072B;
		}

		Accordion {
   			headerStyleName: &quot;myaccordionHeader&quot;;
		}

		.myaccordionHeader {
		   color: #02072B;
		   fontFamily: Georgia;
		   fontSize: 14;
		   fontStyle: italic;

		}
	&lt;/mx:Style&gt;

	&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.rpc.events.ResultEvent;
			import mx.collections.ArrayCollection;

			[Bindable] private var pictures : ArrayCollection;

			private function serviceHandler(event:ResultEvent):void{
				pictures = event.result.gallery.photo;
			}
		]]&gt;
	&lt;/mx:Script&gt;

	&lt;mx:HTTPService id=&quot;service&quot; url=&quot;datas.xml&quot; result=&quot;serviceHandler(event)&quot;/&gt;

	&lt;mx:Accordion width=&quot;400&quot; height=&quot;400&quot;
		creationCompleteEffect=&quot;Iris&quot; openDuration=&quot;500&quot;&gt;
		&lt;mx:Repeater id=&quot;rep&quot; dataProvider=&quot;{pictures}&quot;&gt;
			&lt;mx:VBox width=&quot;100%&quot; height=&quot;100%&quot;
				verticalAlign=&quot;middle&quot; horizontalAlign=&quot;center&quot;
				label=&quot;{rep.currentItem.title}&quot;  &gt;
				&lt;mx:Image source=&quot;assets/{rep.currentItem.file}&quot;/&gt;
			&lt;/mx:VBox&gt;
		&lt;/mx:Repeater&gt;
	&lt;/mx:Accordion&gt;

&lt;/mx:Application&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flex/build-a-xml-driven-accordion-image-gallery/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Create a Custom Animated Cursor for your Flex app</title>
		<link>http://www.riacodes.com/flex/create-a-custom-animated-cursor-for-your-flex-app/</link>
		<comments>http://www.riacodes.com/flex/create-a-custom-animated-cursor-for-your-flex-app/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 11:03:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1004</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flex_custom-animated-cursor/preview.gif"/>]]></description>
			<content:encoded><![CDATA[<p>In this Flex tutorial, let&#8217;s see how to replace the default arrow cursor with an animated cursor created in Flash using the CursorManager class.</p>
<p><span id="more-1004"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flex_custom-animated-cursor/demo/" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flex_custom-animated-cursor/demo/srcview/AnimatedCursor.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flex project named AnimatedCursor, set the name of the main MXML application file to Main.mxml.</p>
<p><em>2.</em> Our custom cursor is a swf file, so open Flash and create your own custom cursor. Set the framerate to 24 to match with the Flex framerate. Here we simply draw an arrow by hand and create a tween to change its color which is quite boring but we leave it to you to make a more creative one.<br />
Publish your swf file.</p>
<p><em>3.</em> Back into Flex, add a Checkbox component that for its change event call the toggleCursor function that we&#8217;are going to create.</p>
<pre class="brush: xml;">
&lt;mx:CheckBox label=&quot;Custom Cursor&quot; change=&quot;toggleCursor(event)&quot;/&gt;
</pre>
<p><em>4.</em> Add a Script section. First, embed your swf file that will be used as the custom cursor.  </p>
<pre class="brush: jscript;">
[Embed(source=&quot;cursor.swf&quot;)]
private var AnimatedCursor:Class;
</pre>
<p><em>5.</em> In the toggleCursor() function, we check whether the checkbox is selected.<br />
If true, call the setCursor() method of the CursorManager class and pass it a reference to the class of your embedded swf cursor.<br />
The setCursor() method returns an ID for the cursor being set that you need to store as we&#8217;ll need to pass the ID to the removeCursor() method.</p>
<pre class="brush: jscript;">
 import mx.managers.CursorManager;

 private var cursorID:int;

 private function toggleCursor(e:Event):void{
          if (e.currentTarget.selected)
            	cursorID = CursorManager.setCursor(AnimatedCursor);
          else CursorManager.removeCursor(cursorID);
 }
</pre>
<p><em>6.</em> Here&#8217;s the final code, run the application to test it.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;
	verticalAlign=&quot;middle&quot; backgroundColor=&quot;#FFFFFF&quot;&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.managers.CursorManager;

            [Embed(source=&quot;cursor.swf&quot;)]
            private var AnimatedCursor:Class;

            private var cursorID:int;

            private function toggleCursor(e:Event):void{
            	if (e.currentTarget.selected)
            		 cursorID = CursorManager.setCursor(AnimatedCursor);
            	else CursorManager.removeCursor(cursorID);
            }
        ]]&gt;
    &lt;/mx:Script&gt;

	&lt;mx:CheckBox id=&quot;checkBox&quot; label=&quot;Custom Cursor&quot; change=&quot;toggleCursor(event)&quot;/&gt;

&lt;/mx:Application&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flex/create-a-custom-animated-cursor-for-your-flex-app/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Build a Drag-and-Drop XML Image Viewer</title>
		<link>http://www.riacodes.com/flex/build-a-drag-and-drop-xml-image-viewer/</link>
		<comments>http://www.riacodes.com/flex/build-a-drag-and-drop-xml-image-viewer/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 17:34:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=923</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flex_drag-drop-image-viewer/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>In this Flex tutorial, we are going to create a drag &#038; drop xml driven image viewer that when the user drags  a thumbnail and drops it inside a box it will display the image&#8217;s bigger version.</p>
<p><span id="more-923"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flex_drag-drop-image-viewer/demo" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flex_drag-drop-image-viewer/demo/srcview/GalleryDragDrop.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flex project named GalleryDragDrop, set the name of the main MXML application file to Main.mxml and set its layout to vertical. Set its horizontalAlign property to &#8220;center&#8221;.</p>
<p><em>2.</em> All of the informations about the images showcased in the gallery are stored in an XML file. Create an xml file that follows this structure and save it as datas.xml in the src directory :</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;gallery&gt;
	&lt;image&gt;marilyn1.jpg&lt;/image&gt;
	&lt;image&gt;marilyn2.jpg&lt;/image&gt;
	&lt;image&gt;marilyn3.jpg&lt;/image&gt;
	&lt;image&gt;marilyn4.jpg&lt;/image&gt;
	&lt;image&gt;marilyn5.jpg&lt;/image&gt;
&lt;/gallery&gt;
</pre>
<p><em>3. </em> Next, create an assets folder, and inside it create a &#8220;thumbs&#8221; folder where you store your thumbnail image files with names matching the xml file, and create a &#8220;big&#8221; folder to put the big images.</p>
<p><em>4.</em> To load the datas from the xml use the HTTPService component :</p>
<pre class="brush: xml;">
&lt;mx:HTTPService id=&quot;service&quot; url=&quot;datas.xml&quot; result=&quot;serviceHandler(event)&quot;/&gt;
</pre>
<p><em>5.</em> Next create a Script section. Declare a variable named images as an arraycollection and defined as bindable. This variable will hold the datas retrieved from the xml in the serviceHandler function : </p>
<pre class="brush: jscript;">
&lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;

            [Bindable]
            private var images:ArrayCollection;

            private function serviceHandler(event:ResultEvent):void{
                images = event.result.gallery.image;
            }

        ]]&gt;
&lt;/mx:Script&gt;
</pre>
<p><em>6.</em> In order to finish this process of loading the xml datas, call the send method of the HTTPService : </p>
<pre class="brush: xml; highlight: [3];">
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;
     horizontalAlign=&quot;center&quot; creationComplete=&quot;service.send()&quot; &gt;
</pre>
<p><em>7.</em> To display the thumbnails use a Repeater and bind its dataProvider with the images variable.<br />
Inside, add an Image component to display the thumbnail.</p>
<pre class="brush: xml;">
&lt;mx:HBox&gt;
		&lt;mx:Repeater dataProvider=&quot;{images}&quot; id=&quot;rep&quot;&gt;
			&lt;mx:Image source=&quot;assets/thumbs/{rep.currentItem}&quot; /&gt;
		&lt;/mx:Repeater&gt;
	&lt;/mx:HBox&gt;
</pre>
<p><em>8.</em> Beneath, add a VBox container with a black background that will be the drop zone for the thumbnails. Add an Image component with an id of &#8220;bigImage&#8221; to diplay the big image.</p>
<pre class="brush: xml;">
&lt;mx:VBox width=&quot;340&quot; height=&quot;350&quot; backgroundColor=&quot;#000000&quot;
	      horizontalAlign=&quot;center&quot; verticalAlign=&quot;middle&quot;&gt;
			&lt;mx:Image id=&quot;bigImage&quot; showBusyCursor=&quot;true&quot;/&gt;
&lt;/mx:VBox&gt;
</pre>
<p><em>9.</em> Now let&#8217;s add the drag and drop interactions between the thumbnails and the black box.<br />
In order to be able to drag the thumbnails, add a mouseMove event listener.</p>
<pre class="brush: xml; highlight: [4];">
&lt;mx:HBox&gt;
		&lt;mx:Repeater dataProvider=&quot;{images}&quot; id=&quot;rep&quot;&gt;
			&lt;mx:Image source=&quot;assets/thumbs/{rep.currentItem}&quot;
				mouseMove=&quot;initiateDrag(event,event.currentTarget.getRepeaterItem())&quot; /&gt;
		&lt;/mx:Repeater&gt;
&lt;/mx:HBox&gt;
</pre>
<p><em>10.</em> The initiateDrag function handles the mouseMove event. Inside this function, we  instantiate a dragInitiator, a dragSource that holds the data being dragged and we also specify a dragProxy which is displayed while the object being dragged.</p>
<pre class="brush: jscript;">
private function initiateDrag(event:MouseEvent,value:String):void{

       var dragInitiator:Image= event.currentTarget as Image;   

       var dragSource:DragSource = new DragSource();
       dragSource.addData(value, 'value');

       var dragProxy:Image = new Image();
       dragProxy.source = event.currentTarget.source;
       dragProxy.width = 100 ;
       dragProxy.height = 100 ;

       DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
}
</pre>
<p><em>11.</em> Next, in order to have a functional drop black box to display the big image, add the dragEnter and dragDrop event listeners.</p>
<pre class="brush: xml; highlight: [3,4];">
&lt;mx:VBox width=&quot;340&quot; height=&quot;350&quot; backgroundColor=&quot;#000000&quot;
	      horizontalAlign=&quot;center&quot; verticalAlign=&quot;middle&quot;
	      dragEnter=&quot;dragEnterHandler(event)&quot;
	      dragDrop=&quot;dragDropHandler(event)&quot;&gt;
			&lt;mx:Image id=&quot;bigImage&quot; showBusyCursor=&quot;true&quot;/&gt;
&lt;/mx:VBox&gt;
</pre>
<p><em>12.</em> The dragEnterHandler function determines whether the data being dragged is in a format that the target accepts. If so, to accept the drop, we call the DragManager.acceptDragDrop() method.</p>
<pre class="brush: jscript;">
private function dragEnterHandler(event:DragEvent):void {
     var dropTarget:VBox =event.currentTarget as VBox;
      if (event.dragSource.hasFormat('value')) {
            DragManager.acceptDragDrop(dropTarget);
      }
}
</pre>
<p><em>13.</em> Finally the dragDropHandler function, which is called when a thumbnail is dropped inside the black box, set the source of the big image to the appropriate value.</p>
<pre class="brush: jscript;">
private function dragDropHandler(event:DragEvent):void {
       var value:String = event.dragSource.dataForFormat('value') as String;
       bigImage.source = &quot;assets/big/&quot;+value;
}
</pre>
<p><em>14.</em> Here&#8217;s the final code, run your application to see it in action.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;
	horizontalAlign=&quot;center&quot;
	backgroundGradientAlphas=&quot;[1.0, 1.0]&quot;
	backgroundGradientColors=&quot;[#FFFFFF, #FFFFFF]&quot;
	creationComplete=&quot;service.send()&quot;&gt;

	&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.core.DragSource;
			import mx.collections.ArrayCollection;
			import mx.rpc.events.ResultEvent;
			import mx.events.DragEvent;
            import mx.managers.DragManager;

			[Bindable]
			private var images:ArrayCollection;

			private function serviceHandler(event:ResultEvent):void{
				images = event.result.gallery.image;
			}

			private function initiateDrag(event:MouseEvent,value:String):void{

             	var dragInitiator:Image= event.currentTarget as Image;   

             	var dragSource:DragSource = new DragSource();
              	dragSource.addData(value, 'value');

              	var dragProxy:Image = new Image();
              	dragProxy.source = event.currentTarget.source;
             	dragProxy.width = 100 ;
              	dragProxy.height = 100 ;

              	DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
           	} 

			private function dragEnterHandler(event:DragEvent):void {
              var dropTarget:VBox =event.currentTarget as VBox;
          	  if (event.dragSource.hasFormat('value')) {
                DragManager.acceptDragDrop(dropTarget);
              }
            }

           	private function dragDropHandler(event:DragEvent):void {
              var value:String = event.dragSource.dataForFormat('value') as String;
              bigImage.source = &quot;assets/big/&quot;+value;
            }

		]]&gt;
	&lt;/mx:Script&gt;

	&lt;mx:HTTPService id=&quot;service&quot; url=&quot;datas.xml&quot; result=&quot;serviceHandler(event)&quot;/&gt;

	&lt;mx:Label text=&quot;Drag a thumbnail image inside the black box and drop it to display its bigger version&quot;/&gt;

	&lt;mx:HBox&gt;
		&lt;mx:Repeater dataProvider=&quot;{images}&quot; id=&quot;rep&quot;&gt;
			&lt;mx:Image source=&quot;assets/thumbs/{rep.currentItem}&quot;
				mouseMove=&quot;initiateDrag(event,event.currentTarget.getRepeaterItem())&quot; /&gt;
		&lt;/mx:Repeater&gt;
	&lt;/mx:HBox&gt;

	&lt;mx:VBox width=&quot;340&quot; height=&quot;350&quot; backgroundColor=&quot;#000000&quot;
	      horizontalAlign=&quot;center&quot; verticalAlign=&quot;middle&quot;
	      dragEnter=&quot;dragEnterHandler(event)&quot;
	      dragDrop=&quot;dragDropHandler(event)&quot;&gt;
			&lt;mx:Image id=&quot;bigImage&quot; showBusyCursor=&quot;true&quot;/&gt;
	&lt;/mx:VBox&gt;

&lt;/mx:Application&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flex/build-a-drag-and-drop-xml-image-viewer/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Build a XML PopUp Image Gallery</title>
		<link>http://www.riacodes.com/flex/build-a-xml-popup-image-gallery/</link>
		<comments>http://www.riacodes.com/flex/build-a-xml-popup-image-gallery/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 00:18:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=874</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flex_xml-popup-image-gallery/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>In the following Flex tutorial, we are going to create an xml driven popup image gallery that when we click on a thumbnail it will open a bigger version of the image in a popup window.</p>
<p><span id="more-874"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flex_xml-popup-image-gallery/demo" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flex_xml-popup-image-gallery/demo/srcview/GalleryPopUp.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flex project named GalleryPopUp, set the name of the main MXML application file to Main.mxml and set its layout to vertical. Set its horizontalAlign property to &#8220;center&#8221; and its verticalAlign property to &#8220;middle&#8221;.</p>
<pre class="brush: xml;">
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;
     horizontalAlign=&quot;center&quot;  verticalAlign=&quot;middle&quot; &gt;
</pre>
<p><em>2.</em> All of the informations about the images showcased in the gallery are stored in an XML file. Create an xml file that follows this structure and save it as data.xml in the src directory :</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;gallery&gt;
    &lt;movie&gt;
    	&lt;pic&gt;titanic.jpg&lt;/pic&gt;
    	&lt;title&gt;Titanic&lt;/title&gt;
    	&lt;date&gt;1997&lt;/date&gt;
    &lt;/movie&gt;
    &lt;movie&gt;
    	&lt;pic&gt;shakespeareinlove.jpg&lt;/pic&gt;
    	&lt;title&gt;Shakespeare in Love&lt;/title&gt;
    	&lt;date&gt;1998&lt;/date&gt;
    &lt;/movie&gt;

    ...

    &lt;movie&gt;
    	&lt;pic&gt;slumdogmillionaire.jpg&lt;/pic&gt;
    	&lt;title&gt;Slumdog Millionaire&lt;/title&gt;
    	&lt;date&gt;2008&lt;/date&gt;
    &lt;/movie&gt;
&lt;/gallery&gt;
</pre>
<p><em>3. </em> Next, create an assets folder, and inside it create a &#8220;thumbs&#8221; folder where you store your thumbnail image files with names matching the xml file, and create a &#8220;posters&#8221; folder to put the big images.</p>
<p><em>4.</em> To load the datas from the xml use the HTTPService component :</p>
<pre class="brush: xml;">
&lt;mx:HTTPService id=&quot;service&quot; url=&quot;data.xml&quot; result=&quot;serviceHandler(event)&quot;/&gt;
</pre>
<p><em>5.</em> Next create a Script section. Declare a variable named movies as an arraycollection and defined as bindable. This variable will hold the datas retrieved from the xml in the serviceHandler function : </p>
<pre class="brush: jscript;">
&lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;

            [Bindable]
            private var movies:ArrayCollection;

            private function serviceHandler(event:ResultEvent):void{
                movies = event.result.gallery.movie;
            }

        ]]&gt;
&lt;/mx:Script&gt;
</pre>
<p><em>6.</em> In order to finish this process of loading the xml datas, call the send method of the HTTPService : </p>
<pre class="brush: xml; highlight: [3];">
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;
     horizontalAlign=&quot;center&quot;  verticalAlign=&quot;middle&quot;
     creationComplete=&quot;service.send()&quot; &gt;
</pre>
<p><em>7.</em> To display the thumbnails use the TileList component and bind its dataProvider with the movies variable.<br />
Inside, add an inline itemRenderer to display the movie&#8217;s thumbnail picture and the movie&#8217;s date.</p>
<pre class="brush: xml;">
&lt;mx:TileList id=&quot;moviesList&quot; dataProvider=&quot;{movies}&quot;
        direction=&quot;horizontal&quot;
        width=&quot;800&quot; height=&quot;450&quot; rowHeight=&quot;150&quot; columnWidth=&quot;200&quot;&gt;
        &lt;mx:itemRenderer&gt;
            &lt;mx:Component&gt;
                &lt;mx:VBox horizontalAlign=&quot;center&quot; verticalAlign=&quot;middle&quot;&gt;
                    &lt;mx:Image source=&quot;assets/thumbs/{data.pic}&quot;/&gt;
                    &lt;mx:Label text=&quot;{data.date}&quot; /&gt;
                &lt;/mx:VBox&gt;
            &lt;/mx:Component&gt;
        &lt;/mx:itemRenderer&gt;
    &lt;/mx:TileList&gt;
</pre>
<p><em>8.</em> Create a new MXML Component named Window, based on the TitleWindow component. This component will display the movies&#8217;s big poster image and its title.<br />
Add an image component and bind its source with a sourceImage String variable declared as public. Create a closeWindow function that will handle the close event. </p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:TitleWindow xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
	layout=&quot;vertical&quot; width=&quot;400&quot; height=&quot;520&quot;
	horizontalAlign=&quot;center&quot;
	showCloseButton=&quot;true&quot;
	close=&quot;closeWindow(event);&quot; &gt;

	&lt;mx:Script&gt;
		&lt;![CDATA[

			import mx.events.CloseEvent;
			import mx.managers.PopUpManager;

			[Bindable]
			public var sourceImage:String;

			private function closeWindow(e:CloseEvent):void {
				PopUpManager.removePopUp(this);
			}

		]]&gt;
	&lt;/mx:Script&gt;

	&lt;mx:Image source=&quot;{sourceImage}&quot;/&gt;

&lt;/mx:TitleWindow&gt;
</pre>
<p><em>9.</em> Also to make the popup window more handy, we want to be able to close it just by clicking on it. To do so, we need to dispatch a CloseEvent for the click event listener.</p>
<pre class="brush: xml; highlight: [6];">
&lt;mx:TitleWindow xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
	layout=&quot;vertical&quot; width=&quot;400&quot; height=&quot;520&quot;
	horizontalAlign=&quot;center&quot;
	showCloseButton=&quot;true&quot;
	close=&quot;closeWindow(event);&quot;
	click=&quot;dispatchEvent(new CloseEvent(CloseEvent.CLOSE));&quot;&gt;
</pre>
<p><em>10.</em> We have finished with this component, return to the Main.mxml file<br />
Add a click event listener to the TileList component that will be handled by the launchPopUp function. </p>
<pre class="brush: xml; highlight: [4];">
&lt;mx:TileList id=&quot;moviesList&quot; dataProvider=&quot;{movies}&quot;
        direction=&quot;horizontal&quot;
        width=&quot;800&quot; height=&quot;450&quot; rowHeight=&quot;150&quot; columnWidth=&quot;200&quot;
        click=&quot;launchPopUp(event)&quot;&gt;
</pre>
<p>In the launchPopUp function, create a new Window component and set its title and sourceImage properties to the values of the movie that has been clicked. Use the PopUpManager class to display the window.</p>
<pre class="brush: jscript;">
private function launchPopUp(e:MouseEvent):void {
        if(moviesList.selectedItem){
              var win : Window = new Window();
              win.sourceImage = &quot;assets/posters/&quot;+moviesList.selectedItem.pic;
              win.title =  moviesList.selectedItem.title;
              PopUpManager.addPopUp(win,this,true);
              PopUpManager.centerPopUp(win);
        }
}
</pre>
<p><em>11.</em> Finally as usual, we add a Style section to custom the appearance of the whole application :</p>
<pre class="brush: xml;">
&lt;mx:Style&gt;
    	global{
	 		modalTransparency : .8;
			modalTransparencyColor : #000000;
	 	}
	 	Application{
	 	 	backgroundGradientColors: #ffffff, #ffffff;
   			backgroundGradientAlphas: 1, 1;
	 	}
        TileList{
            selectionColor:  #717070;
            rollOverColor: #CCCCCC;
            borderStyle : none;
        }
        TitleWindow{
	 		borderColor : #C1C1C1;
	 		borderAlpha : .8;
	 		fontSize : 14;
	 		fontFamily :Georgia;
	 		fontWeight : bold ;
	 		color : #FFFFFF;
	 	}
	 	Label{
	 		color : #000000;
	 		fontStyle : italic;
	 	}
    &lt;/mx:Style&gt;
</pre>
<p><em>12.</em> Here&#8217;s the final code, run the application to see it in action.</p>
<p><em>Main.mxml</em></p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;
     horizontalAlign=&quot;center&quot;  verticalAlign=&quot;middle&quot;
     creationComplete=&quot;service.send()&quot; &gt;

    &lt;mx:Style&gt;
    	global{
	 		modalTransparency : .8;
			modalTransparencyColor : #000000;
	 	}
	 	Application{
	 	 	backgroundGradientColors: #ffffff, #ffffff;
   			backgroundGradientAlphas: 1, 1;
	 	}
        TileList{
            selectionColor:  #717070;
            rollOverColor: #CCCCCC;
            borderStyle : none;
        }
        TitleWindow{
	 		borderColor : #C1C1C1;
	 		borderAlpha : .8;
	 		fontSize : 14;
	 		fontFamily :Georgia;
	 		fontWeight : bold ;
	 		color : #FFFFFF;
	 	}
	 	Label{
	 		color : #000000;
	 		fontStyle : italic;
	 	}
    &lt;/mx:Style&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;
            import mx.managers.PopUpManager;

            [Bindable]
            private var movies:ArrayCollection;

            private function serviceHandler(event:ResultEvent):void{
                movies = event.result.gallery.movie;
            }

            private function launchPopUp(e:MouseEvent):void {
				if(moviesList.selectedItem){
					var win : Window = new Window();
					win.sourceImage = &quot;assets/posters/&quot;+moviesList.selectedItem.pic;
					win.title =  moviesList.selectedItem.title;
					PopUpManager.addPopUp(win,this,true);
					PopUpManager.centerPopUp(win);
				}
			}

        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:HTTPService id=&quot;service&quot; url=&quot;data.xml&quot; result=&quot;serviceHandler(event)&quot;/&gt;
    &lt;mx:TileList id=&quot;moviesList&quot; dataProvider=&quot;{movies}&quot;
        direction=&quot;horizontal&quot;
        width=&quot;800&quot; height=&quot;450&quot; rowHeight=&quot;150&quot; columnWidth=&quot;200&quot;
        click=&quot;launchPopUp(event)&quot;&gt;
        &lt;mx:itemRenderer&gt;
            &lt;mx:Component&gt;
                &lt;mx:VBox horizontalAlign=&quot;center&quot; verticalAlign=&quot;middle&quot;&gt;
                    &lt;mx:Image source=&quot;assets/thumbs/{data.pic}&quot;/&gt;
                    &lt;mx:Label text=&quot;{data.date}&quot; /&gt;
                &lt;/mx:VBox&gt;
            &lt;/mx:Component&gt;
        &lt;/mx:itemRenderer&gt;
    &lt;/mx:TileList&gt;

&lt;/mx:Application&gt;
</pre>
<p><em>Window.mxml</em></p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:TitleWindow xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
	layout=&quot;vertical&quot; width=&quot;400&quot; height=&quot;520&quot;
	horizontalAlign=&quot;center&quot;
	showCloseButton=&quot;true&quot;
	close=&quot;closeWindow(event);&quot;
	click=&quot;dispatchEvent(new CloseEvent(CloseEvent.CLOSE));&quot;&gt;

	&lt;mx:Script&gt;
		&lt;![CDATA[

			import mx.events.CloseEvent;
			import mx.managers.PopUpManager;

			[Bindable]
			public var sourceImage:String;

			private function closeWindow(e:CloseEvent):void {
				PopUpManager.removePopUp(this);
			}

		]]&gt;
	&lt;/mx:Script&gt;

	&lt;mx:Image source=&quot;{sourceImage}&quot;/&gt;

&lt;/mx:TitleWindow&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flex/build-a-xml-popup-image-gallery/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Watch Adobe Max 2009 Sessions</title>
		<link>http://www.riacodes.com/flex/watch-adobe-max-2009-sessions/</link>
		<comments>http://www.riacodes.com/flex/watch-adobe-max-2009-sessions/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 08:42:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Air]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=853</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_adobe-max2009/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>Watch and learn from videos of Adobe MAX 2009 sessions that are available for free at the Adobe TV.<br />
<span id="more-853"></span><br />
These sessions covers topics like </p>
<p>MAX 2009 DEVELOP<br />
<a href="http://tv.adobe.com/show/max-2009-develop/" target="_blank">http://tv.adobe.com/show/max-2009-develop/</a></p>
<ul>
<li>Practical Actionscript 3.0 For Flash CS3 and CS4</li>
<li>What&#8217;s new in Flash Player</li>
<li>Things every flash developer should know</li>
<li>Actionscript 3.0 Tastes Good (And is Good for You Too !)</li>
<li>The Advantages of Flex</li>
<li>Killer Text in Flash with The Text Layout Framework</li>
<li>What&#8217;s Coming in Adobe AIR 2</li>
</ul>
<p>MAX 2009 DESIGN<br />
<a href="http://tv.adobe.com/show/max-2009-design/" target="_blank">http://tv.adobe.com/show/max-2009-design/</a></p>
<ul>
<li>Secret Session : Flash Professional</li>
<li>Multi-Touch and the Flash Platform</li>
<li>Flash Professional, Flash Catalyst, and Flash Builder : Fact, Features and (Work)Flows</li>
</ul>
<p>and so much more &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flex/watch-adobe-max-2009-sessions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Build a PopUp Window with Flex</title>
		<link>http://www.riacodes.com/flex/build-a-popup-window-with-flex/</link>
		<comments>http://www.riacodes.com/flex/build-a-popup-window-with-flex/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 15:25:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=834</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flex_popup-window/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>In this Flex tutorial, let&#8217;s see how to create a Popup window.<br />
<span id="more-834"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flex_popup-window/demo" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flex_popup-window/demo/srcview/PopUpWindow.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flex project named PopUpWindow, set the name of the main MXML application file to main.mxml and set its layout to vertical.</p>
<p><em>2.</em> In the main.mxml file, add a button that when the user clicks on it will launch the window by calling the launchPopUp function.</p>
<pre class="brush: xml;">
&lt;mx:Button id=&quot;button&quot; label=&quot;Launch PopUp Window&quot;
			   click=&quot;launchPopUp(event);&quot;/&gt;
</pre>
<p><em>3.</em> Before writing  the launchPopUp function, create a new MXML Component named Window, based on the TitleWindow component and set its size as you want. You have now a Window.mxml file inside your src directory.<br />
Open this file and add some content inside the TitleWindow component, in our case we&#8217;ve added an image.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:TitleWindow xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
	layout=&quot;vertical&quot; width=&quot;650&quot; height=&quot;250&quot;
	title=&quot;PopUp Window&quot; horizontalAlign=&quot;center&quot;&gt;

	&lt;mx:Image source=&quot;assets/img.gif&quot; /&gt;

&lt;/mx:TitleWindow&gt;
</pre>
<p><em>4.</em> So far we&#8217;ve created the window, now let&#8217;s it pop up when the button is clicked.<br />
Back with the main.mxml file, add a Script section to the application to create the launchPopUp function.<br />
This function creates a Window object, the component we&#8217;ve created before and uses the PopUpManager class to display it.</p>
<pre class="brush: xml;">
 &lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.managers.PopUpManager;

			private function launchPopUp(e:MouseEvent):void {
				var win : Window = new Window();
				PopUpManager.addPopUp(win,this,true);
				PopUpManager.centerPopUp(win);
			}
		]]&gt;
&lt;/mx:Script&gt;
</pre>
<p><em>5.</em> At this point, if you test the application, clicking on the button should launch the popup window.<br />
But how to close the window you might ask?<br />
To resolve this issue, let&#8217;s edit our Window component (window.mxml file).<br />
The WindowTitle component has a showCloseButton property that you need to set to true to view a close button. Next add a close event listener to handle this event.</p>
<pre class="brush: xml; highlight: [4,5];">
&lt;mx:TitleWindow xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
	layout=&quot;vertical&quot; width=&quot;650&quot; height=&quot;250&quot;
	title=&quot;PopUp Window&quot; horizontalAlign=&quot;center&quot;
	showCloseButton=&quot;true&quot;
	close=&quot;closeWindow(event);&quot; &gt;
</pre>
<p><em>6.</em> Add a Script section to write the closeWindow function. We use the PopUpManager.removePopUp method to remove the window.</p>
<pre class="brush: xml;">
&lt;mx:Script&gt;
		&lt;![CDATA[

			import mx.core.IFlexDisplayObject;
			import mx.events.CloseEvent;
			import mx.managers.PopUpManager;

			private function closeWindow(e:CloseEvent):void {
				PopUpManager.removePopUp(e.target as IFlexDisplayObject);
			}

		]]&gt;
&lt;/mx:Script&gt;
</pre>
<p><em>7.</em> Alright, now all is good to go. Finally we add to the main application some css to make the application more to our taste.</p>
<p><em>8.</em> Here&#8217;s the final code, test the application to see it in action.</p>
<p><em>main.mxml</em> : </p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;&gt;

 &lt;mx:Style&gt;
	 	Application{
	 	 	backgroundColor: #000000;
	 	}
	 	global{
	 		modalTransparency : .3;
			modalTransparencyColor : #ffffff;
	 	}

&lt;/mx:Style&gt;

&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.managers.PopUpManager;

			private function launchPopUp(e:MouseEvent):void {
				var win : Window = new Window();
				PopUpManager.addPopUp(win,this,true);
				PopUpManager.centerPopUp(win);
			}
		]]&gt;
&lt;/mx:Script&gt;

	&lt;mx:Button id=&quot;button&quot; label=&quot;Launch PopUp Window&quot;
			   click=&quot;launchPopUp(event);&quot;/&gt;

&lt;/mx:Application&gt;
</pre>
<p><em>Window.mxml</em>:</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:TitleWindow xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
	layout=&quot;vertical&quot; width=&quot;650&quot; height=&quot;250&quot;
	title=&quot;PopUp Window&quot; horizontalAlign=&quot;center&quot;
	showCloseButton=&quot;true&quot;
	close=&quot;closeWindow(event);&quot; &gt;

	&lt;mx:Script&gt;
		&lt;![CDATA[

			import mx.core.IFlexDisplayObject;
			import mx.events.CloseEvent;
			import mx.managers.PopUpManager;

			private function closeWindow(e:CloseEvent):void {
				PopUpManager.removePopUp(e.target as IFlexDisplayObject);
			}

		]]&gt;
	&lt;/mx:Script&gt;

	&lt;mx:Image source=&quot;assets/img.gif&quot;/&gt;

&lt;/mx:TitleWindow&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flex/build-a-popup-window-with-flex/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Build a XML Image Viewer with Flex</title>
		<link>http://www.riacodes.com/flex/build-a-xml-image-viewer-in-flex/</link>
		<comments>http://www.riacodes.com/flex/build-a-xml-image-viewer-in-flex/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 10:31:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=702</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flex_image-viewer/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>The following tutorial shows how to build a driven xml image viewer in Flex which allows the user to navigate through the images using a previous and next buttons.<br />
<span id="more-702"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flex_image-viewer/demo" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flex_image-viewer/demo/srcview/Image-viewer.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flex project named Image-viewer, set the name of the main MXML application file to main.mxml and set its layout to vertical.</p>
<p><em>2.</em> All the datas about the images are stored in a XML file. Create an xml file that follows this structure and save it as data.xml :</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;gallery&gt;
    &lt;img&gt;
    	&lt;file&gt;1.jpg&lt;/file&gt;
    	&lt;title&gt;Warhol &amp; Basquiat&lt;/title&gt;
    &lt;/img&gt;
    &lt;img&gt;
    	&lt;file&gt;2.jpg&lt;/file&gt;
    	&lt;title&gt;Beethoven Yellow Book&lt;/title&gt;
    &lt;/img&gt;
    &lt;img&gt;
    	&lt;file&gt;3.jpg&lt;/file&gt;
    	&lt;title&gt;Marilyn Monroe&lt;/title&gt;
    &lt;/img&gt;
    &lt;img&gt;
    	&lt;file&gt;4.jpg&lt;/file&gt;
    	&lt;title&gt;Zebra&lt;/title&gt;
    &lt;/img&gt;
    &lt;img&gt;
    	&lt;file&gt;5.jpg&lt;/file&gt;
    	&lt;title&gt;Campbell's Soup I&lt;/title&gt;
    &lt;/img&gt;
&lt;/gallery&gt;
</pre>
<p><em>3.</em> Create a folder named assets. Inside it, create a subfolder named &#8220;images&#8221; and put in the images which filenames are given in the xml file .</p>
<p><em>4.</em> Open the main application to start adding the code.<br />
To load the datas from the xml, use the HTTPService component :</p>
<pre class="brush: xml;">
&lt;mx:HTTPService id=&quot;service&quot; url=&quot;data.xml&quot; result=&quot;serviceHandler(event)&quot;/&gt;
</pre>
<p>Next open a Script section and declare a variable named images as an arraycollection and defined as bindable. This variable will hold the datas retrieved from the xml.<br />
Then write the serviceHandler function :</p>
<pre class="brush: xml;">
	&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.collections.ArrayCollection;
			import mx.rpc.events.ResultEvent;

			[Bindable]
			private var images:ArrayCollection;

			private function serviceHandler(event:ResultEvent):void{
				images = event.result.gallery.img;
			}

		]]&gt;
	&lt;/mx:Script&gt;
</pre>
<p>In order to finish this process of loading the xml, call the send method of the HTTPService: </p>
<pre class="brush: xml;">
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;
	creationComplete=&quot;service.send()&quot;&gt;
</pre>
<p><em>5.</em> Declare a currentIndex variable that will keep track of the index of the image currently on display and set its value to zero.</p>
<pre class="brush: jscript;">
[Bindable]
private var currentIndex : Number = 0
</pre>
<p><em>6.</em> Now let&#8217;s add the elements, a Text component to display the title, an Image component and two buttons.<br />
We bind the text property of the Text component with the title of the current image by using our currentIndex variable. And we do the same with the source property of the Image.</p>
<pre class="brush: xml;">
 &lt;mx:VBox horizontalAlign=&quot;center&quot; width=&quot;300&quot; height=&quot;400&quot;&gt;
			&lt;mx:Text text=&quot;{images.getItemAt(currentIndex).title}&quot;/&gt;
			&lt;mx:Image source=&quot;assets/images/{images.getItemAt(currentIndex).file}&quot;
				showBusyCursor=&quot;true&quot;/&gt;
	&lt;/mx:VBox&gt;

	&lt;mx:HBox&gt;
			&lt;mx:Button click=&quot;previousImage(event)&quot; buttonMode=&quot;true&quot;/&gt;
			&lt;mx:Button click=&quot;nextImage(event)&quot; buttonMode=&quot;true&quot;/&gt;
	&lt;/mx:HBox&gt;
</pre>
<p><em>7.</em> Now let&#8217;s write the previousImage and nextImage functions that will change the index of the image to be displayed.</p>
<pre class="brush: jscript;">
private function nextImage(e:MouseEvent):void{
	if (currentIndex &lt; images.length - 1){
        currentIndex++;
    }
    else {
        currentIndex = 0;
    }
}

private function previousImage(e:MouseEvent):void{
	if (currentIndex != 0){
		currentIndex--;
    }
    else {
        currentIndex = images.length - 1;
    }
}
</pre>
<p><em>8. </em> Finally create a css file and save it as style.css in the src directory. For the next and previous buttons, we place their 3 different states images inside a folder &#8220;style&#8221; inside the &#8220;assets&#8217; folder.</p>
<pre class="brush: xml;">
Application {
   backgroundColor: #000000;
}

.previousBtn{
    upSkin:Embed(&quot;/assets/style/left_up.png&quot;);
    overSkin:Embed(&quot;/assets/style/left_over.png&quot;);
    downSkin:Embed(&quot;/assets/style/left_down.png&quot;);
}

.nextBtn{
    upSkin:Embed(&quot;/assets/style/right_up.png&quot;);
    overSkin:Embed(&quot;/assets/style/right_over.png&quot;);
    downSkin:Embed(&quot;/assets/style/right_down.png&quot;);
}

.title{
   color: #ffffff;
   fontFamily: Times New Roman;
   fontSize: 16;
   fontWeight: bold;
   fontStyle: italic;
}
</pre>
<p>Apply the style to the components : </p>
<pre class="brush: xml;">
&lt;mx:Text text=&quot;{images.getItemAt(currentIndex).title}&quot; styleName=&quot;title&quot;/&gt;
    ...
&lt;mx:Button click=&quot;previousImage(event)&quot; buttonMode=&quot;true&quot; styleName=&quot;previousBtn&quot; /&gt;
&lt;mx:Button click=&quot;nextImage(event)&quot; buttonMode=&quot;true&quot; styleName=&quot;nextBtn&quot; /&gt;
</pre>
<p><em>9.</em> Here&#8217;s the final code. Run the application to test it.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;
	creationComplete=&quot;service.send()&quot;&gt;

	&lt;mx:Style source=&quot;style.css&quot;/&gt;

	&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.collections.ArrayCollection;
			import mx.rpc.events.ResultEvent;

			[Bindable]
			private var images:ArrayCollection;

			[Bindable]
			private var currentIndex : Number = 0;

			private function serviceHandler(event:ResultEvent):void{
				images = event.result.gallery.img;
			}

			private function nextImage(e:MouseEvent):void{
				if (currentIndex &lt; images.length - 1){
                    currentIndex++;
                }
                else {
                    currentIndex = 0;
                }

			}

			private function previousImage(e:MouseEvent):void{
				if (currentIndex != 0){
					currentIndex--;
                }
                else {
                    currentIndex = images.length - 1;
                }
           	}

		]]&gt;
	&lt;/mx:Script&gt;

	&lt;mx:HTTPService id=&quot;service&quot; url=&quot;data.xml&quot; result=&quot;serviceHandler(event)&quot;/&gt;

	&lt;mx:VBox horizontalAlign=&quot;center&quot; width=&quot;300&quot; height=&quot;400&quot;&gt;
			&lt;mx:Text text=&quot;{images.getItemAt(currentIndex).title}&quot; styleName=&quot;title&quot;/&gt;
			&lt;mx:Image source=&quot;assets/images/{images.getItemAt(currentIndex).file}&quot;
				showBusyCursor=&quot;true&quot;/&gt;
	&lt;/mx:VBox&gt;

	&lt;mx:HBox&gt;
			&lt;mx:Button click=&quot;previousImage(event)&quot; buttonMode=&quot;true&quot; styleName=&quot;previousBtn&quot;/&gt;
			&lt;mx:Button click=&quot;nextImage(event)&quot; buttonMode=&quot;true&quot; styleName=&quot;nextBtn&quot;/&gt;
	&lt;/mx:HBox&gt;

&lt;/mx:Application&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flex/build-a-xml-image-viewer-in-flex/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Get your free Flash &amp; Flex Developer&#8217;s magazine</title>
		<link>http://www.riacodes.com/flex/get-your-free-flash-flex-develop/</link>
		<comments>http://www.riacodes.com/flex/get-your-free-flash-flex-develop/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 11:00:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=689</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_ffdmag-free/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>Get tutorials, expert articles, reviews of products, as well as greatest Flash &#038; Flex advice, news and opinions with Flash &#038; Flex Developer&#8217;s magazine for FREE.<br />
<span id="more-689"></span><br />
Here is their message : &#8220;Since September 2009 FFD Magazine becomes online magazine. What is important &#8211; it will be also FREE of ANY charges . The only thing you need to do is to sign up to our Newsletter :<br />
<a href="http://www.ffdmag.com/prt/view/subscribe-to-newslet.html" target="_blank">http://www.ffdmag.com/prt/view/subscribe-to-newslet.html</a>.<br />
If you&#8217;re not sure if you like the idea &#8211; try out the magazine &#8211; 4 back issues to download :<br />
<a href="http://www.ffdmag.com/prt/view/back-issues.html" target="_blank">http://www.ffdmag.com/prt/view/back-issues.html</a>.<br />
Check this out! Let&#8217;s build the biggest Flash and Flex Developer&#8217;s Community!&#8221;<br />
<a href="http://www.ffdmag.com" target="_blank">www.ffdmag.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flex/get-your-free-flash-flex-develop/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
