<?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>FlaDev</title>
	<atom:link href="http://www.fladev.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fladev.com</link>
	<description>Flash programming blog</description>
	<lastBuildDate>Mon, 21 Mar 2011 18:51:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>How to Export Video from Flash</title>
		<link>http://www.fladev.com/tutorials/how-to-export-video-from-flash/</link>
		<comments>http://www.fladev.com/tutorials/how-to-export-video-from-flash/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 14:05:36 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[export video]]></category>
		<category><![CDATA[Flash video]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://www.fladev.com/?p=1213</guid>
		<description><![CDATA[Today I&#8217;ll show you my own technique, after many and many videos exported from Flash, in this tutorial called How to Export Video from Flash. The technique is not a fabulous one, and doesn&#8217;t require an advanced level, but it wont fail when you need to export your animation in a video format on a [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;ll show you my own technique, after many and many videos exported from Flash, in this tutorial called <strong>How to Export Video from Flash</strong>. The technique is not a fabulous one, and doesn&#8217;t require an advanced level, but it wont fail when you need to export your animation in a video format on a high quality.</p>
<hr />
<h3>Preview</h3>
<p><a href="http://preview.fladev.com/how-to-export-video-from-flash/"><img class="alignnone size-full wp-image-1230" title="How to Export Video From Flash" src="http://www.fladev.com/wp-content/uploads/2011/03/PreviewExportVideoFromFlash.jpg" alt="" width="534" height="108" /></a></p>
<h3>Setting all files</h3>
<p>Let&#8217;s say you will create an app, or a simple animation using OOP, and you want to export this as video. Create a new ActionScript 3.0 Flash file with dimensions 590x300px,  and let&#8217;s create a simple animation. Create a MovieClip on Stage, with instance name <em>mc</em>. If you don&#8217;t know already how to work with Caurina, make sure to check <a title="How to properly install Caurina Tweener classes" href="http://www.fladev.com/featured/how-to-properly-install-caurina-tweener-classes/">How to properly install Caurina Tweener classes</a>, because we will use this. Create a new ActionScript 3.0 Class file, called <em>Main</em> and set this in Flash to be Document Class.</p>
<hr />
<h3>Animating</h3>
<p>Let&#8217;s focus on Main.as class &#8211; we will animate the MovieClip <em>mc</em> five times, once per second. Declare all variables:</p>
<pre class="brush: as3; title: ;">
public var mc:MovieClip;
private var timer:Timer;
</pre>
<p>Create a timer to animate the MovieClip <em>mc</em>:</p>
<pre class="brush: as3; title: ;">
timer = new Timer(1000, 5);
timer.addEventListener(TimerEvent.TIMER, onCounting);
timer.start();
</pre>
<p>Basically I create a simple timer to animate 5 times the MovieClip to different positions. Let&#8217;s see how looks <em>onCounting </em>function:</p>
<pre class="brush: as3; title: ;">
private function onCounting(e:TimerEvent):void
{
	Tweener.addTween(mc, { transition:&quot;easeOutSine&quot;, x:Math.random() * stage.stageWidth, y:Math.random() * stage.stageHeight, time:0.5} );
}
</pre>
<p>It&#8217;s a simple animation, I wont cover this deeply than now, just make an idea how your OOP animation will be when you&#8217;ll export to video.</p>
<hr />
<h3>Ready to export video</h3>
<p>Ok, we know how long is the animation, right? 5 seconds. Go to File &gt; Export &gt; Export Movie. Choose to export Quick Time (.mov), and let&#8217;s take a look to the settings panel:</p>
<p><a href="http://www.fladev.com/wp-content/uploads/2011/03/QuickTimeExportSettings.jpg"><img class="size-medium wp-image-1216 alignnone" title="Quick Time Export Settings" src="http://www.fladev.com/wp-content/uploads/2011/03/QuickTimeExportSettings-300x218.jpg" alt="" width="300" height="218" /></a></p>
<p>Let&#8217;s discuss a little bit these options.<br />
<strong>Stop Exporting</strong> &#8211; since we don&#8217;t have animation on Timeline, we need to choose the second option &#8211; After time elapsed &#8211; here type 5 (seconds).<br />
<strong>Store temp data</strong> &#8211; obviously what does<br />
<strong>Ignore stage color</strong> &#8211; If you don&#8217;t want your video to have background and to to keep just animations, you need to choose this option &#8211; note that you must don&#8217;t have anything on your stage as background, even if it&#8217;s a shape, a MovieClip or pictures.</p>
<p>Next, press <em>QuickTime Settings</em> for movie settings.<br />
<a href="http://www.fladev.com/wp-content/uploads/2011/03/MovieSettings.jpg"><img class="alignnone size-medium wp-image-1217" title="Movie Settings" src="http://www.fladev.com/wp-content/uploads/2011/03/MovieSettings-238x300.jpg" alt="" width="238" height="300" /></a></p>
<p>If you want your movie to have sound, you must check the sound option. Then if you want to make changes on your video, from <em>Video </em>tab press <em>Settings</em>.<br />
<a href="http://www.fladev.com/wp-content/uploads/2011/03/VideoCompression.jpg"><img class="alignnone size-medium wp-image-1218" title="Video Compression" src="http://www.fladev.com/wp-content/uploads/2011/03/VideoCompression-300x211.jpg" alt="" width="300" height="211" /></a></p>
<p>If you want have a lower quality movie, from compression type you can choose <em>Animation</em>. If not <em>None</em>, that means your movie will not have compression  &#8211; also this option will increase your file size. On <em>Frame Rate</em> you can choose 30 frames per second or <em>Current</em>, your current frame used in movie. You can let the key frames on <em>Automatic</em>; now, pay your attention. If you want to export this, with a transparent background for example, from <em>Compressor </em> box, choose depth to <em>Millions of Colors +</em>, if not you can let just <em>Millions of Colors</em>.</p>
<p>Press ok and let&#8217;s move to <em>Video Size</em> panel. <strong>Always</strong> be sure when you export different formats from Flash, to check this option from <em>Dimmensions</em> and to select <em>Current</em>.</p>
<hr />
<h3>Final result</h3>
<p>Open the new .mov file created with Quick Time, and see the result. What do you think? A good quality, a video smoothed and cool resolution. Much more, you can export this to TGA sequences, convert to .AVI uncompressed or even a .WMW and .MPEG file, with this .mov file at a great resolution all these options are possible. Let me know what do you think, let me know what technique do you use when you export video files from Flash. Thank you for your time</p>
<hr />
<div class="download"><a href="http://www.fladev.com/wp-content/files/export_video.zip">Download sources</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fladev.com/tutorials/how-to-export-video-from-flash/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to make your own Draggable Progress Bar in Flash</title>
		<link>http://www.fladev.com/tutorials/how-to-make-your-own-draggable-progress-bar-in-flash/</link>
		<comments>http://www.fladev.com/tutorials/how-to-make-your-own-draggable-progress-bar-in-flash/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 13:43:06 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[draggable percent bar]]></category>
		<category><![CDATA[flash percent bar]]></category>
		<category><![CDATA[percent bar]]></category>

		<guid isPermaLink="false">http://www.fladev.com/?p=1174</guid>
		<description><![CDATA[If you don&#8217;t know how to create your own Draggable Progress Bar in Flash, then this is the right place. First of all, the usability of this progress bar can be multiple, even if we speak about loading, scrollbars, seeking, volume or chart bars. Another advantage when you use your own progress bar, instead of [...]]]></description>
			<content:encoded><![CDATA[<p>If you don&#8217;t know <a title="How to make your own Draggable Progress Bar in Flash " href="http://www.fladev.com/tutorials/learn-to-make-your-own-draggable-progress-bar-in-flash">how to create your own Draggable Progress Bar in Flash</a>, then this is the right place. First of all, the usability of this progress bar can be multiple, even if we speak about loading, scrollbars, seeking, volume or chart bars.  Another advantage when you use your own progress bar, instead of the component already developed in Flash, is that your file size will be very small.</p>
<hr />
<h3>Preview the final result</h3>
<p><a href="http://preview.fladev.com/how-to-make-your-own-draggable-progress-bar-in-flash/"><img class="alignnone size-full wp-image-1175" title="Draggable Progress Bar" src="http://www.fladev.com/wp-content/uploads/2011/03/DragableProgressBar.jpg" alt="" width="589" height="131" /></a></p>
<hr />
<h3>Setting the files</h3>
<p>In Flash, create a new ActionScript 3.0 file, with 590x300px dimmensions and save the file as <em>progressBar</em>. Our Progress Bar will contain 2 MovieClips &#8211; <em>bar skin</em> (the one that you see behind) and <em>track skin</em> (the one that is draggable); Create them as in the attached image,  then make them as a new MovieClip, called <em>percentBar</em>.<br />
<a href="http://www.fladev.com/wp-content/uploads/2011/03/DragableProgressScheme.jpg"><img class="alignleft size-medium wp-image-1181" title="Draggable Progress Scheme" src="http://www.fladev.com/wp-content/uploads/2011/03/DragableProgressScheme-300x66.jpg" alt="" width="300" height="66" /></a><br />
While dragging, you want to display somewhere the progress and then to use that value to scroll or doing something. To do this we need to create an info box, where the percent will be. Basically what you need to do,  is to create on Stage a new MovieClip with instance name <em>boxInfo</em>, and inside of this to add a dynamic TextField, called <em>txt</em>.</p>
<hr />
<h3>DraggableProgressBar.as</h3>
<p>Create a new ActionScript 3.0 class file, called <em>DraggableProgressBar.as</em>, and declare all MovieClips from progress bar as public variables:</p>
<pre class="brush: as3; title: ;">
public var trackSkin:MovieClip;
public var barSkin:MovieClip;
public var percent:int = 0;
</pre>
<p>As you observe there is a percent variable also, that will store a value when the MovieClip trackSkin is dragged.  In the <em>init</em> function we:</p>
<ul>
<li> set the progress bar as buttonMode;</li>
<li> make the trackSkin&#8217;s width to be 0;</li>
<li> add listeners when Mouse is DOWN or UP;</li>
</ul>
<pre class="brush: as3; title: ;">
private function init(e:Event = null):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			trackSkin.width = 0;
			buttonMode = true;
			mouseChildren = false;

			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
			addEventListener(MouseEvent.MOUSE_OUT, onMouseUp);
		}
</pre>
<p>When Mouse is DOWN we add an EnterFrame listener, so we&#8217;ll know what size will have the MovieClip <em>trackSkin</em> after dragging, according to Mouse position on X; and when Mouse is UP we remove the EventListener.</p>
<pre class="brush: as3; title: ;">
private function onMouseDown(e:MouseEvent):void
{
	addEventListener(Event.ENTER_FRAME, stateBar);
}

private function onMouseUp(e:MouseEvent):void
{
	removeEventListener(Event.ENTER_FRAME, stateBar);
}
</pre>
<p>Let&#8217;s see how the <em>stateBar</em> function looks:</p>
<pre class="brush: as3; title: ;">
	trackSkin.width = Math.min(mouseX, barSkin.width);
	percent = (trackSkin.width / barSkin.width) * 100;
	dispatchEvent(new Event(Event.COMPLETE));
</pre>
<p>First line increase or decrease the trackSkin&#8217;s width according to <em>mouseX</em>, but no higher then his max width; second line is the difference between the new scale after dragging and the max scale multiplied with 100, in order to get a value from 0 to 100; third line is a dispatcher to the Main class, to know that the percent is changed.</p>
<hr />
<h3>Main Class</h3>
<p>Create a new ActionScript 3.0 class file, called <em>Main.as</em>, and declare all MovieClips as public variables:</p>
<pre class="brush: as3; title: ;">
public var boxInfo:MovieClip;
public var progressBar:DraggableProgressBar;
</pre>
<p>Then we align the <em>boxInfo</em> with the <em>progressBar</em> on X position, and add a listener to read the new percent when <em>progressBar</em> is dragged:</p>
<pre class="brush: as3; title: ;">
boxInfo.x = progressBar.x;
boxInfo.txt.text = progressBar.percent;
progressBar.addEventListener(Event.COMPLETE, getValue);
</pre>
<p>Finally the <em>getValue </em>function will be:</p>
<pre class="brush: as3; title: ;">

	boxInfo.txt.text = progressBar.percent;
	boxInfo.x = Math.max(mouseX, Math.min(progressBar.x, progressBar.width));
</pre>
<p>Save this, recompile and see if everything is ok. If the progressBar is ready, it&#8217;s easy to create scrollbar, a seeking bar, a volume or a chart bar also. Let me know what do you think</p>
<hr />
<div class="download"><a href="http://www.fladev.com/wp-content/files/draggable_percent_bar.zip">Download sources</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fladev.com/tutorials/how-to-make-your-own-draggable-progress-bar-in-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Create a Pattern Background in Flash</title>
		<link>http://www.fladev.com/tutorials/how-to-create-a-pattern-background-in-flash/</link>
		<comments>http://www.fladev.com/tutorials/how-to-create-a-pattern-background-in-flash/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 15:24:28 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[fullscreen background]]></category>
		<category><![CDATA[pattern background]]></category>

		<guid isPermaLink="false">http://www.fladev.com/?p=1117</guid>
		<description><![CDATA[Hi, I decide to extend my tutorial Building a Fullscreen Background Image with AS3 into How to Create a Pattern Background in Flash. In this tutorial you will learn to build a fullscreen background with your own pattern, that will be multiplied according with your screen dimensions. Preview the final result Setting files Create a [...]]]></description>
			<content:encoded><![CDATA[<p>Hi, I decide to extend my tutorial <a title="Building a fullscreen background image with AS3" href="http://www.fladev.com/featured/building-a-fullscreen-background-image-with-as3/" target="_blank">Building a Fullscreen Background Image with AS3</a> into <a title="How to Create a Pattern Background in Flash" href="http://www.fladev.com/tutorials/how-to-create-a-pattern-background-in-flash" target="_self">How to Create a Pattern Background in Flash</a>. In this tutorial you will learn to build a fullscreen background with your own pattern, that will be multiplied according with your screen dimensions.</p>
<hr />
<h3>Preview the final result</h3>
<p><a href="http://preview.fladev.com/how-to-create-a-pattern-background-in-flash/"><img class="alignnone size-full wp-image-1122" title="PatternBackgroundFullScreen" src="http://www.fladev.com/wp-content/uploads/2011/02/PatternBackgroundFullScreen.jpg" alt="" width="590" height="300" /></a></p>
<hr />
<h3>Setting files</h3>
<p>Create a new ActionScript File called &#8220;Main.as&#8221; in a empty folder <em>src</em> (src.MainClass) that extend the Sprite class, since our Timeline will not contain any ActionScript code. Also create a new AS3 Flash file(550×400px) and open it, so that we have both files opened, and download <a title="FlaDev Pattern" href="http://preview.fladev.com/how-to-create-a-pattern-background-in-flash/pattern.jpg" target="_blank">my pattern</a> used in this tutorial (you can use yours later).</p>
<hr />
<h3>Main.as</h3>
<p>In ActionScript file <em>Main.as</em> first thing to do is to create a loader that will preload the pattern multiplied on whole screen. Let&#8217;s add variables for loader and pattern:</p>
<pre class="brush: as3; title: ;">
private var loader:Loader;
private static const IMAGE_PATH:String = &quot;pattern.jpg&quot;;
</pre>
<p>Then in the <em>constructor</em> function declare properties for Stage:</p>
<pre class="brush: as3; title: ;">
public function Main():void
{
	stage.align = StageAlign.TOP_LEFT;
	stage.scaleMode = StageScaleMode.NO_SCALE;
	if (stage) init();
	else addEventListener(Event.ADDED_TO_STAGE, init);
}
</pre>
<p>Load the pattern in the <em>init</em> function:</p>
<pre class="brush: as3; title: ;">
private function init(e:Event = null):void
	{
		removeEventListener(Event.ADDED_TO_STAGE, init);

		loader = new Loader();
		loader.load(new URLRequest(IMAGE_PATH));
		loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
	}
</pre>
<p>Now, when the pattern was fully loaded, Stage will be filled on resize with this image as BitmapData:</p>
<pre class="brush: as3; title: ;">
private function onComplete(e:Event):void
	{
		bitmapData = e.target.loader.contentLoaderInfo.content.bitmapData as BitmapData;
		onStageResized();
	}
</pre>
<p>Before to see how <em>onStageResized</em> looks, we need to add a listener on Stage in order to trigger this function. To do this, in the <em>init</em> function add this line:</p>
<pre class="brush: as3; title: ;">
stage.addEventListener(Event.RESIZE, onStageResized);
</pre>
<hr />
<h3>onStageResized</h3>
<p>Since this function is twice used, one for listener and one when the pattern was loaded, set the Even to be <em>null</em>. Then, we will fill a rectangle representing the whole stage with the pattern, setting smoothing and repeat to true.</p>
<pre class="brush: as3; title: ;">
private function onStageResized(e:Event=null):void
		{
			graphics.clear();
			graphics.beginBitmapFill(bitmapData, null, true, true);
			graphics.moveTo(0, 0);
			graphics.lineTo(stage.stageWidth, 0);
			graphics.lineTo(stage.stageWidth, stage.stageHeight);
			graphics.lineTo(0, stage.stageHeight);
			graphics.lineTo(0, 0);
			graphics.endFill();
		}
</pre>
<p>If you test this, you&#8217;ll see the hole area filled with this nice pattern. But we want to be fully filled when Stage resized or maybe on FullScreen also, not in a small area. So how to do this? The answer is simple, when the pattern was fully loaded, add a listener on resize calling again <em>onStageResized</em></p>
<pre class="brush: as3; title: ;">
stage.addEventListener(Event.RESIZE, onStageResized);
</pre>
<hr />
<h3>onFullscreen function</h3>
<p><a href="http://www.fladev.com/wp-content/uploads/2011/02/Full-Screen-Button.jpg"><img class="size-full wp-image-1128 alignleft" title="Full Screen Button" src="http://www.fladev.com/wp-content/uploads/2011/02/Full-Screen-Button.jpg" alt="" width="292" height="62" /></a>If you compile now, you will see the hole screen filled with this loaded pattern, even when Stage resizes. What about creating a button, that on pressed will make the screen fully filled with pattern?<br />
On Stage draw a simple <em>Rectangle</em>, convert this to <em>Button</em> and give him an instance name <em>btn</em>. In <em>Main.as</em> don&#8217;t forget to declare public variable with this new button created. In the init function add these 2 lines that will trigger the fullscreen function:</p>
<pre class="brush: as3; title: ;">
stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullscreen);
btn.addEventListener(MouseEvent.CLICK, goFullscreen);
</pre>
<pre class="brush: as3; title: ;">
private function goFullscreen(e:MouseEvent):void
{
	 if( stage.displayState == StageDisplayState.NORMAL ){
             stage.displayState = StageDisplayState.FULL_SCREEN;
          } else {
                stage.displayState = StageDisplayState.NORMAL;
          }
}
</pre>
<p>In order to be this possible, in your HTML code where you embed the .SWF file, be sure you have next parameters:</p>
<pre class="brush: xml; title: ;">
&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot; /&gt;
&lt;param name=&quot;wmode&quot; value=&quot;window&quot; /&gt;
</pre>
<p>If you want on full screen to hide the button, in <em>onFullscreen</em> function add:</p>
<pre class="brush: as3; title: ;">
btn.visible = e.fullScreen?false:true;
</pre>
<p>That&#8217;s it, check if everything is ok then replace your pattern with yours. Until next time, have a nice day.</p>
<hr/>
<div class="download"><a href="http://www.fladev.com/wp-content/files/pattern_background.zip">Download sources</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fladev.com/tutorials/how-to-create-a-pattern-background-in-flash/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Create an advanced XML Video Gallery part 1</title>
		<link>http://www.fladev.com/tutorials/create-an-advanced-xml-video-gallery-part-1/</link>
		<comments>http://www.fladev.com/tutorials/create-an-advanced-xml-video-gallery-part-1/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 15:59:25 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[advanced video gallery]]></category>
		<category><![CDATA[Flash videoplayer]]></category>
		<category><![CDATA[Flash XML video gallery]]></category>
		<category><![CDATA[Videoplayer AS3]]></category>
		<category><![CDATA[XML video gallery]]></category>

		<guid isPermaLink="false">http://www.fladev.com/?p=999</guid>
		<description><![CDATA[This is the first tutorial of the series how to create an advanced XML Video Gallery, consisting of three parts. Currently we need to cover some basics of how to create a Video Player that is connected with XML and plays .flv files. To handle this, we use Flash, Flash Develop and AS3 and also [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first tutorial of the series how to <strong>create an advanced XML Video Gallery</strong>, consisting of three parts. Currently we need to cover some basics of how to create a Video Player that is connected with XML and plays .flv files.</p>
<p>To handle this, we use Flash, Flash Develop and AS3 and also we need to have some knowledge’s about <a title="ClassPaths and Packages in Adobe Flash Cs5" href="http://www.fladev.com/tutorials/classpaths-and-packages-in-adobe-flash-cs5/" target="_blank">Class Paths and Packages</a>, <a title="How to properly install Caurina Tweener classes" href="http://www.fladev.com/featured/how-to-properly-install-caurina-tweener-classes/" target="_blank">Caurina</a> and SWC files. Note: I’m not willing to use a FLVPlayback component.</p>
<hr />
<h2>Preview the final result</h2>
<p><a href="http://preview.fladev.com/create-an-advanced-xml-video-gallery-part-1/"><img class="alignnone size-full wp-image-1044" title="Create and advanced XML Video Gallery" src="http://www.fladev.com/wp-content/uploads/2011/01/FlaDevCover.jpg" alt="" width="590" height="300" /></a></p>
<hr />
<h2>What is Flash Video</h2>
<p><strong>Flash Video</strong> is a <a title="Container format (digital)" href="http://en.wikipedia.org/wiki/Container_format_%28digital%29" target="_blank">container file format</a> used to deliver <a title="Video" href="http://en.wikipedia.org/wiki/Video" target="_blank">video</a> over the <a title="Internet" href="http://en.wikipedia.org/wiki/Internet" target="_blank">Internet</a> using <a title="Adobe  Flash Player" href="http://en.wikipedia.org/wiki/Adobe_Flash_Player" target="_blank">Adobe Flash Player</a> versions 6–10. Flash Video content may also be embedded within <a title="SWF" href="http://en.wikipedia.org/wiki/SWF" target="_blank">SWF</a> files. There are two different video file formats known as Flash Video: <strong>FLV</strong> and <strong>F4V</strong>. The audio and video data within FLV files are encoded in the same way as they are within SWF files. The latter F4V file format is based on the <a title="ISO base media file format" href="http://en.wikipedia.org/wiki/ISO_base_media_file_format" target="_blank">ISO base media file format</a> and is supported starting with Flash Player 9 update 3. You can found more info about this <a title="Flash Video" href="http://en.wikipedia.org/wiki/Flash_Video." target="_blank">here</a>.</p>
<hr />
<h2>Loading a Video</h2>
<p>To load and playback a Video we need to use a <em>NetStream </em>object, which require to pass it a <em>NetConnection </em>object.</p>
<pre class="brush: as3; title: ;">
var videoConnection:NetConnection= new NetConnection();
videoConnection.connect(null)//for progressive download video use a null connection string
</pre>
<p>Now that you’ve constructed a <em>NetConnection</em> object and called the connect() method with a null value, we need to pass the <em>NetStream</em> consctructor a reference to the him:</p>
<pre class="brush: as3; title: ;">var videoStream:NetStream = new NetStream(videoConnection);
</pre>
<p>Next Step is to add a <em>Video</em> object, and to associate this with the <em>NetStream</em>:</p>
<pre class="brush: as3; title: ;">
var video = new Video();
addChild(video);
</pre>
<p>Optional you can associate a <em>NetStream</em> object with a Video object using the Video object’s <em>attachNetStream()</em>:</p>
<pre class="brush: as3; title: ;">
video.attachNetStream(videoStream);
</pre>
<p>Finally we need to tell to the Flash Player to load the video and to start the playback, both accomplished with one simple method called play:</p>
<pre class="brush: as3; title: ;">
videoStream.play(&quot;flv path);//the parameter can be absolute or relative
</pre>
<p>Flash video playback starts automatically as soon as enough has buffered. You can control buffering and monitor loading, using a preloader for example. Last point, if the FLV contains metadata or/and cue points and you don’t handle the events, Flash Player throws errors.</p>
<pre class="brush: as3; title: ;">
var client = new Object();
client.onMetaData = onMetaData;
videoStream.client =client;
</pre>
<hr />
<h2>Creating the Flash file</h2>
<p><a href="http://www.fladev.com/wp-content/uploads/2011/01/CheckingSWC.jpg"><img class="alignleft size-medium wp-image-1017" title="CheckingSWC" src="http://www.fladev.com/wp-content/uploads/2011/01/CheckingSWC-197x300.jpg" alt="" width="197" height="300" /></a>Now that you have an idea about how this works, let&#8217;s create a Video Player.  After you read this post called <a title="ClassPaths and Packages in Adobe Flash Cs5" href="http://www.fladev.com/tutorials/classpaths-and-packages-in-adobe-flash-cs5/" target="_blank">ClassPaths and Packages in Adobe Flash Cs5</a>, create a new Flash file with dimensions 590x300px. Then use the <em>Rectangle Tool(R)</em> to draw a rectangle, let&#8217;s say 320x240px, convert this to be MovieClip linked with a class &#8220;Videoplayer&#8221;  that will be created later. We&#8217;ll use this MovieClip as container for Video Player.</p>
<hr />
<h2>Building Classes</h2>
<p>In FlashDevelop create a new ActionScript file <em>Videoplayer</em> that was linked in Flash, when you create the Video Players container and let&#8217;s apply what we&#8217;ve learned. Save this file in a new folder called <em>src</em>. Then declare variables:</p>
<pre class="brush: as3; title: ;">
private var videoConnection:NetConnection;
private var videoStream:NetStream;
private var video:Video;
private var client:Object;
</pre>
<p>New features was added in latest version of FlashDevelop, which I&#8217;m proud, as you observe in the constructor function.</p>
<pre class="brush: as3; title: ;">
public function VideoPlayer():void {
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
</pre>
<p>Instantiate all classes imported:</p>
<pre class="brush: as3; title: ;">
removeEventListener(Event.ADDED_TO_STAGE, init);
		videoConnection = new NetConnection();
			videoConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
			videoConnection.connect(null);
		videoStream = new NetStream(videoConnection);
			videoStream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
			videoStream.client = this;
			video = new Video();
			addChild(video);
			video.attachNetStream(videoStream);
			videoStream.play(&quot;../videos/video1.flv&quot;);
			video.smoothing = true;
			client = new Object();
			client.onMetaData = onMetaData;
			videoStream.client = client;
</pre>
<p>The <em>netStatus </em>function for NetConection and NetStream listeners:</p>
<pre class="brush: as3; title: ;">
private function netStatus(e:NetStatusEvent):void
		{
			switch (e.info.code) {
				case &quot;NetStream.Play.StreamNotFound&quot;
					//&quot;Stream not found&quot;;
				break;
			case &quot;NetStream.Play.Stop&quot;
					//&quot;Stream stopped&quot;;
				break;
			}
		}
</pre>
<p>And finally the MetaData function:</p>
<pre class="brush: as3; title: ;">
public function onMetaData(info:Object):void {
	//video info
}
</pre>
<p>Save all files, compile and let&#8217;s see the final result.</p>
<p>Let me know, keep sending me emails and comments, I would love to hear them. Next time we&#8217;ll load videos from XML and add buttons to control this Video Player.</p>
<hr/>
<div class="download"><a href="http://www.fladev.com/wp-content/files/videogallery_part1.zip">Download sources</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fladev.com/tutorials/create-an-advanced-xml-video-gallery-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The success of Flash Games: Zynga</title>
		<link>http://www.fladev.com/articles/the-success-of-flash-games-zynga/</link>
		<comments>http://www.fladev.com/articles/the-success-of-flash-games-zynga/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 14:54:14 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CityVille]]></category>
		<category><![CDATA[FarmVille]]></category>
		<category><![CDATA[flash games]]></category>
		<category><![CDATA[FrontierVille]]></category>
		<category><![CDATA[Zynga]]></category>

		<guid isPermaLink="false">http://www.fladev.com/?p=1086</guid>
		<description><![CDATA[Zynga has become something of a commonly used reference when talking about casual online gaming. In just four very short years, this company has monetized its IPs to such an extent that the company is valued now at somewhere around the 5.5 billion dollar mark, a bit over Electronic Arts which conversely is the second [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Zynga " href="http://zynga.com" target="_blank">Zynga</a> has become something of a commonly used reference when talking about casual online gaming.</p>
<p>In just four very short years, this company has monetized its IPs to such an extent that the company is valued now at somewhere around the 5.5 billion dollar mark, a bit over Electronic Arts which conversely is the second largest game publisher and also a company founded in 1982.</p>
<p><img class="alignleft size-full wp-image-1087" title="CityVille" src="http://www.fladev.com/wp-content/uploads/2011/02/CityVille.jpg" alt="" width="200" height="200" />How did this happen, how can an extremely young company get to be worth more than one that has been around almost as long as home video games have?</p>
<p>The short answer: <a title="Facebook" href="http://www.facebook.com/" target="_blank">Facebook;</a> the longer answer: social networking entertainment.</p>
<p>Indeed, it couldn’t have happened without the phenomenon that is social networking and Facebook in particular.</p>
<p>Working out a deal to disseminate their addictive games via Facebook and programming them in such a way so as to promote the continual use and growth of the website worked as a win-win for both the parties involved.</p>
<p>How they did that was very easy given the framework of the social networking site, basically the more friends you had that played the game with you the better you would do at the game. This meant that if someone wanted to get better and bigger items, and didn’t want to spend real world money to get them, they would have to get some of their friends involved with the game and so on and so forth.</p>
<p>Their best known games have been Farmville and relatively recently Frontierville, but Farmville’s become the go to reference in popular media, mostly related to people spending too much time on Facebook, but as there is no such thing as bad publicity, they can’t lose either way.</p>
<p>On the 2nd of December 2010, they launched their latest variation of the “Ville” series, namely <a title="CityVille" href="http://www.facebook.com/apps/application.php?id=291549705119" target="_blank">Cityville</a>, and in the short span of time that has passed since it has already become the most played of the “Ville” games proving that the market for these types of games is nowhere near saturation.</p>
<p>I say this because the game maintains many of the mechanics, features and characteristics of their older games but as opposed to the others, this time they combined what they’ve been successful on their own with something that has been a success since 1989 – SimCity.</p>
<p><img class="alignleft size-full wp-image-1089" title="FrontierVille" src="http://www.fladev.com/wp-content/uploads/2011/02/FrontierVille.jpg" alt="" width="200" height="200" />So in less than two months, they’ve managed to reach the top spot when it comes to social network games, a spot they already held with <a title="FarmVille" href="http://www.farmville.com/" target="_blank">Farmville</a>. Obviously most of the players of the new game are also players of <a title="FarmVille" href="http://www.farmville.com/" target="_blank">Farmville</a>, but equally obvious is the fact that there are many more new players that have either just come aboard with the new title or older players who got sick of either <a title="FarmVille" href="http://www.farmville.com/" target="_blank">Farmville</a> or <a title="FrontierVille" href="http://www.facebook.com/frontierville?v=app_4949752878" target="_blank">Frontierville</a> and decided to give the new game a try, and they’re sticking around at least for the moment.</p>
<p>Time will tell whether this latest title will indeed become the new Farmville, or the latter will reclaim its spot as top dog, but it is interesting to watch further how long can this trend continue; because sooner or later they’ll have to go to space with it and where do you go from there?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fladev.com/articles/the-success-of-flash-games-zynga/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Manipulating a loaded image with BitmapData in AS3</title>
		<link>http://www.fladev.com/tutorials/manipulating-a-loaded-image-with-bitmapdata-in-as3/</link>
		<comments>http://www.fladev.com/tutorials/manipulating-a-loaded-image-with-bitmapdata-in-as3/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 16:54:32 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[Image Loaded]]></category>

		<guid isPermaLink="false">http://www.fladev.com/?p=1031</guid>
		<description><![CDATA[It&#8217;s very useful to work with external files and load them in Flash, using a preloader for example or adding some nice effects. Let&#8217;s see how to manipulate a loaded image with BitmapData in AS3 using few lines of code. Preview the final result Loading an image Probably you know already how to load an [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s very useful to work with external files and load them in Flash, using a preloader for example or adding some nice effects. Let&#8217;s see <strong>how to manipulate a loaded image with BitmapData in AS3</strong> using few lines of code.</p>
<hr/>
<h3>Preview the final result</h3>
<p><a title="Manipulating a loaded image with BitmapData in AS3" href="http://preview.fladev.com/manipulating-a-loaded-image-with-bitmapdata-in-as3/" target="_blank"><img class="alignnone size-full wp-image-1044" title="Manipulating a loaded image with BitmapData in AS3" src="http://www.fladev.com/wp-content/uploads/2011/01/FlaDevCover.jpg" alt="" width="590" height="300" /></a></p>
<h3>Loading an image</h3>
<p>Probably you know already how to load an image in Flash, using AS3. Create a new ActionScript file <em>Main.as</em> and first declare variables for loader:</p>
<pre class="brush: as3; title: ;">
private var loader:Loader;
private var imgPath:String = &quot;img.gif&quot;;
</pre>
<p>Then the constructor and <em>init </em>functions will be:</p>
<pre class="brush: as3; title: ;">
public function Main() {
			if (stage) init()
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}

		private function init(e:Event = null):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);

			loader = new Loader();
			loader.load(new URLRequest(imgPath));
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
		}
</pre>
<p>Once the image is loaded, the &#8220;onComplete&#8221; function will be triggered:</p>
<pre class="brush: as3; title: ;">
private function onComplete(e:Event):void
		{
			splitBitmap(e.target.loader.content.bitmapData, 3, 5);
		}
</pre>
<p>I&#8217;m trying to create an effect like an image divided in many thumbs that regroups random. Create a function <em>splitBitmap</em> that receives 3 parameters: first is the loader&#8217;s content as bitmap, second and third one represents the columns and rows.</p>
<pre class="brush: as3; title: ;">
private function splitBitmap(bitmapSource:BitmapData, columns:int, rows:int):void
{ }
</pre>
<p>It&#8217;s time to declare new variables for <em>Bitmap</em> and <em>BitmapData</em>:</p>
<pre class="brush: as3; title: ;">
private var bitmapData:BitmapData;
private var bitmap:Bitmap;
private var space:int = 0;
</pre>
<p>Focus now on <em>splitBitmap </em>function. We need variables for Bitmap info, like width or height:</p>
<pre class="brush: as3; title: ;">
var bitmapWidth:int = bitmapSource.width;
var bitmapHeight:int = bitmapSource.height;

var thumbWidth:Number = Math.round(bitmapWidth / columns);
var thumbHeight:Number = Math.round(bitmapHeight / rows);
</pre>
<p>After we know what size does Bitmap have, create a BitmapData object as model for each thumbs:</p>
<pre class="brush: as3; title: ;">
bitmapData = new BitmapData(bitmapWidth, bitmapHeight);
bitmapData.draw(bitmapSource);
</pre>
<p>From now on it&#8217;s simple, create a <em>for </em> statement for X and Y position and add thumbs according to them:</p>
<pre class="brush: as3; title: ;">
for (var i = 0; i &lt; columns; i++) {
	for (var j:int = 0; j &lt; rows; j++)
	{

	}
}
</pre>
<hr/>
<h3>Putting all together</h3>
<p>Inside of this statement create a new <em>BitmapData</em> for each thumb, use<em> copyPixels</em> to copy the pixels from an defined area and finally add thumbs according with number of columns and rows:</p>
<pre class="brush: as3; title: ;">
var thumbBitmap:BitmapData = new BitmapData(bitmapWidth, bitmapHeight);
thumbBitmap.copyPixels(bitmapData, new Rectangle(i * thumbWidth, j * thumbHeight, thumbWidth, thumbHeight), new Point(0, 0));
bitmap = new Bitmap(thumbBitmap);

addChild(bitmap);
bitmap.x = i * (thumbWidth + space);
bitmap.y = j * (thumbHeight + space);
bitmap.smoothing = true;
bitmap.alpha = 0;
</pre>
<p>Now, let&#8217;s say you want to animate each individual thumb. Calling a new function in a random interval, that receive as parameters the Bitmap object and his coordonates, will make the thumb to move to a defined position and after back to his coordonates. This get a random interval, declare a variable <em>c</em> as Number before the <em>for </em>statement. Add a <em>setTimeout </em>method inside of same statement to call the <em>animate </em>function:</p>
<pre class="brush: as3; title: ;">
setTimeout(animate, 1000+ (100*(Math.round(Math.random()*c))), bitmap, bitmap.x, bitmap.y);
</pre>
<p>and the function that use <a href="http://www.fladev.com/featured/how-to-properly-install-caurina-tweener-classes/">Caurina</a> to animate the thumbs:</p>
<pre class="brush: as3; title: ;">
private function animate(bitmapSource:Bitmap, bitmapX:Number, bitmapY:Number):void
{
	bitmapSource.y = -100;
        Tweener.addTween(bitmapSource, { time:0.5, transition:&quot;easeOutSine&quot;, x:bitmapX, y:bitmapY, alpha:1} );
}
</pre>
<p>Now that you know how to manipulate them, you can add multiple effects and play around with them.<br />
Let me know what do you think by sending me emails or comments. Cheers</p>
<hr/>
<div class="download"><a href="http://www.fladev.com/wp-content/files/manipulated_image.zip">Download sources</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fladev.com/tutorials/manipulating-a-loaded-image-with-bitmapdata-in-as3/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>HTML5 and Flash</title>
		<link>http://www.fladev.com/articles/html5-and-flash/</link>
		<comments>http://www.fladev.com/articles/html5-and-flash/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 08:41:06 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Flash Player 10.1]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Steve Jobs]]></category>

		<guid isPermaLink="false">http://www.fladev.com/?p=942</guid>
		<description><![CDATA[The better part of 2010 was mired in a rather heated debate about the future of Flash. This was happening despite the fact that Flash Player 10.1 was launched that same year, coming after a major rewrite which saw it become a much more effective piece of software. The whole discussion raged around the new [...]]]></description>
			<content:encoded><![CDATA[<p>The better part of 2010 was mired in a rather heated debate about the future of Flash. This was happening despite the fact that <a title="Adobe Flash Player 10.1" href="http://labs.adobe.com/technologies/flashplayer10/" target="_blank">Flash Player 10.1</a> was launched that same year, coming after a major rewrite which saw it become a much more effective piece of software.</p>
<p><img class="alignleft size-full wp-image-946" title="AdobeFlashCS5" src="http://www.fladev.com/wp-content/uploads/2011/01/AdobeFlashCS5.jpg" alt="" width="250" height="250" />The whole discussion raged around the new <a title="HTML5" href="http://en.wikipedia.org/wiki/HTML5" target="_blank">HTML5</a> web standard being able to do a lot of things that Flash was able to do as well. Very rarely have there been so many message boards filled with geekery, bile and fanboyism related to a simple thing as new technology.</p>
<p>Of course whenever something new appears there are always some individuals that declare it to be the “something killer”, or “the dawn of a new age”, but usually those flame war discussions don’t spill over into the more mainstream tech media, not unless you have a high level troll doing what they do best.</p>
<p>The entire discussion was sparked and fueled by a certain open missive from one <a title="Steve Jobs" href="http://en.wikipedia.org/wiki/Steve_Jobs" target="_blank">Steve Jobs</a> to the entirety of the app developing world in which he basically declared that Flash can’t work on multi-touch and mobile platforms for a slew of reasons and that <a title="HTML5" href="http://en.wikipedia.org/wiki/HTML5" target="_blank">HTML5</a> is <a title="Apple Inc." href="http://en.wikipedia.org/wiki/Apple_Inc." target="_blank">Apple</a>’s focus.</p>
<p>This letter was the culmination of a rather long lasting fight between Apple and Adobe on various reasons, mostly having to do with each other company’s control over their properties and how said properties would be disseminated through the developer world.</p>
<p>Now all of this was taking place at the rather high echelons of the two companies, but at some point mister Jobs chose to step it up a notch and basically burn all the bridges between Apple and Adobe with his open letter.</p>
<p>Now why exactly he did this is anyone’s guess, maybe to hit Adobe stock prices, maybe because he felt the need to clarify his company’s stance on Flash, that much we don’t know, what we do know and what he knows as well, is that Apple benefits from a very strong base of fans that have stood with the company through thick and thin and he has been getting exponentially more acolytes thanks to the successes of the iPhone and the iPad. And what he basically did with the letter was to seed the Apple fanboys (or girls) with a hate for Flash products.</p>
<p>Being the <img class="alignleft size-full wp-image-947" title="HTML5Snippets" src="http://www.fladev.com/wp-content/uploads/2011/01/HTML5Snippets.jpg" alt="" width="250" height="172" />major player in any market offers you some definite clout, even more so if you are a major player in a market thanks to a self-enclosed environment that keeps on growing, because as far as you’re concerned your customers won’t leave this protective bubble any time soon.</p>
<p>Let’s face it, he’s a troll, a very well placed troll with a lot of listeners, but nonetheless still a troll. And he was successful in igniting this discussion and keeping it aflame for a few months but just like any other troll’s statements it died down rather soon and cooler heads prevailed, but more on that in a future article.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fladev.com/articles/html5-and-flash/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>2011 will still be red</title>
		<link>http://www.fladev.com/articles/2011-will-still-be-red/</link>
		<comments>http://www.fladev.com/articles/2011-will-still-be-red/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 15:41:43 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.fladev.com/?p=930</guid>
		<description><![CDATA[Hello and Happy New Year! 2010 has finished and now we are in the beginning of 2011, a start of year with many events already. I hope you learned many things on this blog last year and now you can start to develop your own applications in Flash at a new level. I know that [...]]]></description>
			<content:encoded><![CDATA[<p>Hello and<strong> Happy New Year</strong>!<br />
2010 has finished and now we are in the beginning of 2011, a start of year with many events already. I hope you learned many things on this blog last year and now you can start to develop your own applications in Flash at a new level. I know that time is very expensive for all of us, but I will try to write as much as I can and to publish fresh and awesome tutorials. Take this as a promise!<br />
<a href="http://craciun2010.make-flash.ro/"><img class="alignleft size-full wp-image-934" title="ItsCarolTime" src="http://www.fladev.com/wp-content/uploads/2011/01/ItsCarolTime.jpg" alt="" width="210" height="156" /></a>Thanks to all my visitors, friends, colleagues and collaborators and hopefully that 2011 will be much productive year, with new tools from Adobe and new skills in Flash. Also, after many stories about HTML5 and how Flash will be erased from the ground or how sheep&#8217;s eat the wolf, with all these 2011 will still be a red year. Closing this shortly speech, let me show you a funny game from make-flash, called <a title="It's carols time!" href="http://craciun2010.make-flash.ro/" target="_blank"><strong>It&#8217;s carols time!</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fladev.com/articles/2011-will-still-be-red/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yahoo Weather App in Flash</title>
		<link>http://www.fladev.com/featured/yahoo-weather-app-in-flash/</link>
		<comments>http://www.fladev.com/featured/yahoo-weather-app-in-flash/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 12:21:38 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Freebies]]></category>
		<category><![CDATA[Latest]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Weather Application]]></category>
		<category><![CDATA[Yahoo API]]></category>
		<category><![CDATA[Yahoo! ASTRA]]></category>
		<category><![CDATA[Yahoo! Weather Forecast]]></category>

		<guid isPermaLink="false">http://www.fladev.com/?p=785</guid>
		<description><![CDATA[In this tutorial I&#8217;m gonna show you how to create your own Yahoo Weather App in Flash, using AS 3.0 and Adobe Flash. There are many ways to build such an app, most of them use an API called Yahoo! ASTRA. The Yahoo! ASTRA Web APIs library is a set of wrapper tools that facilitate [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial I&#8217;m gonna show you how to create your own <strong>Yahoo Weather App in Flash</strong>, using AS 3.0 and Adobe Flash. There are many ways to build such an app, most of them use an API called Yahoo! ASTRA. The Yahoo! ASTRA Web APIs library is a set of wrapper tools that facilitate access to Yahoo! public APIs from Flex and Flash applications. You can find more info about ASTRA Web APIs <a title="Yahoo! ASTRA Web APIs library" href="http://developer.yahoo.com/flash/astra-webapis/" target="_blank">here</a>. In this tutorial we will not use this API becouse it shows only 2 days of Forecast and we want 5.</p>
<h4>Setting the Flash file</h4>
<p>Create a new <em>Flash File</em> (ActionScript 3.0) with size 630x360px and set a document-level classpath for this to be <em>src. </em>If you are not sure how to work with ClassPaths and Packages in Flash then I strongly recommend you to check <a title="Classpaths and packages in Adobe Flash Cs5" href="http://www.fladev.com/tutorials/classpaths-and-packages-in-adobe-flash-cs5/" target="_blank">Classpaths and packages in Adobe Flash Cs5</a>. Then create a blank folder called <em>src </em>where will be all classes used in this widget.</p>
<p><a href="http://www.fladev.com/wp-content/uploads/2010/12/yahoo_weather_app_in_flash.jpg"><img class="alignleft size-medium wp-image-831" title="yahoo_weather_app_in_flash" src="http://www.fladev.com/wp-content/uploads/2010/12/yahoo_weather_app_in_flash-300x171.jpg" alt="" width="300" height="171" /></a>Before proceeding, you must understand how this widget works. Go to <a title="Yahoo! Weather Forecast" href="http://weather.yahoo.com/" target="_blank">weather.yahoo.com</a>, browse or search for your city and you will see the weather forecast for 5 days. In the forecast table  press <em>Extended  Forecast</em> that will redirect you to a new page. The small code from the URL of the page represents the location number (WOEID) for the forecast page &#8211; in my case Bucharest, Romania will be:</p>
<p>http://www.weather.com/outlook/travel/businesstraveler/extended/<strong>ROXX0003</strong></p>
<p>With this code, just make a simple request to<em> &#8220;http://xml.weather.yahoo.com/forecastrss/&#8221; + <strong>WOEID_CODE + </strong></em><em>&#8220;.xml&#8221;</em> to receive the weather info from that city.  As you observe the URL address is mostly like a RSS feed; (trace this address to see the result). More info about the WOEID codes can be found <a title="Yahoo WOEID Weather Codes" href="http://developer.yahoo.com/geo/geoplanet/guide/concepts.html" target="_blank">here</a>.</p>
<h4>The XML file</h4>
<p>Create a new XML file <em>locations.xml</em> and add 5  different WOEID codes from random locations:</p>
<pre class="brush: as3; title: ;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;data&gt;
	&lt;location title=&quot;United States, California&quot; code=&quot;USCA0011&quot; /&gt;
	&lt;location title=&quot;India, Chennai&quot; code=&quot;INXX0075&quot; /&gt;
........................................
&lt;/data&gt;
</pre>
<h4>Weather Icons</h4>
<p>After the request was done to that RSS feed, you will find some weather codes for each day.  For example if outside it&#8217;s a sunny day then the weather code will be 32. These codes are from 1 to 47 but there is also an error code called 3200. Download some custom icons and rename them according with these weather codes and save them in a folder called <em>images</em>. Yahoo provide also some icons already in case you don&#8217;t want to use custom icons.</p>
<h4>Weather Day Container</h4>
<p><img class="size-full wp-image-816 alignleft" title="weather_day_container" src="http://www.fladev.com/wp-content/uploads/2010/12/weather_day_container.jpg" alt="" width="110" height="308" />Before to start building the classes, we need a drop-down menu for location names and codes. From <em>Window</em> choose <em>Components</em> and drag to stage from <em>User Interface</em> a ComboBox component with instance name <em>locationsCombo</em>.</p>
<p>Also we need to create a new MovieClip &#8211; a container &#8211; for each Weather Day Forecast, where all weather info from that day will be displayed. This container will hold 4 new TextFields for:</p>
<ul>
<li><em>dayTxt </em> &#8211; will be the name of the day</li>
<li><em>num1</em> &#8211; for high degrees</li>
<li><em>num2</em> &#8211; for small degrees</li>
<li><em>weatherTxt</em> &#8211; for weather description</li>
</ul>
<p>..and one container for weather icons called <em>pic</em>, which is another new MovieClip. Finally the Weather Day Forecast container will be like this:<br />
Duplicate this for 5 times and give them instance names from <em>day1 </em>to <em>day5</em>.</p>
<h4 class="clear">All together</h4>
<p>Create 2 new ActionScript 3.0 classes and save them in <em>src </em>folder- one for pics <em>PicLoader.as</em> and one for the hole container <em>DayTab.as</em>.<br />
PicLoader.as will load the weather icons and will display them with Caurina:</p>
<pre class="brush: as3; title: ;">
	public class PicLoader extends Sprite
	{
		private var loader:Loader;
		public var mc:MovieClip;

		public function PicLoader()
		{
			mc.visible = false;
			loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, objectLoaded);
		}

		private function objectLoaded(e:Event):void
		{
			e.target.content.alpha = 0;
			e.target.content.smoothing = true;
			Tweener.addTween(e.target.content, { alpha:1, transition:&quot;easeOutSine&quot;, time:0.3 } );
		}

		public function getPath(c:int) {//here are the paths for icons
			if (loader != null) {
				loader.unload();
			}
			loader.load(new URLRequest(&quot;images/&quot; + c + &quot;.png&quot;));
			addChild(loader);
		}
	}
</pre>
<p>In <em>DayTab.as</em> declare all instance names as public variables:</p>
<pre class="brush: as3; title: ;">
public var dayTxt:TextField;
public var num1:TextField;
public var num2:TextField;
public var weatherTxt:TextField;
public var pic:PicLoader;
public var bg:MovieClip;
</pre>
<p>&#8230;and create a function that will receive an object with all info about weather:</p>
<pre class="brush: as3; title: ;">
public function getInfo(c:Object) {
	pic.getPath(c.@code);
	num2.text = c.@low;
	num1.text = c.@high;
	dayTxt.text = c.@day;
	weatherTxt.text = c.@text;
}
</pre>
<p>That&#8217;s it with all these 2 classes, now go back to you flash file and locate in library the symbols created &#8211; <em><em>pic </em></em> and <em>DayTab</em>. Link these 2 symbols with their classes and let&#8217;s move to the final part of this tutorial.</p>
<h4>Final part</h4>
<p>Create a new ActionScript 3.0 class into <em>src </em>folder as <em>Widget.as</em> file. Declare all instance names as public variables:</p>
<pre class="brush: as3; title: ;">
public var pic:PicLoader;
public var locationsCombo:ComboBox;
public var day1:DayTab;
public var day2:DayTab;
public var day3:DayTab;
public var day4:DayTab;
public var day5:DayTab;
</pre>
<p>For XML path we need a variable, for XML object after the file is loaded, a variable to load the file and one for a proxy file (I will describe later about this) and one variable as Array to store the info from XML. If you remember what we&#8217;ve discussed before, we need to make an request to <em> &#8220;http://xml.weather.yahoo.com/forecastrss/&#8221; + <strong>WOEID_CODE + </strong></em><em>&#8220;.xml&#8221;</em> in order to receive the weather info from that city. If you just do this, you&#8217;ll observe that will work only on your local computer &#8211; that&#8217;s because of the Yahoo Security sandbox violation; to resolve this problem we need to create a php file as proxy.</p>
<pre class="brush: as3; title: ;">
private var xmlPath:String = &quot;locations.xml&quot;;
private var xml:XML;
private var urlLoader:URLLoader;
private var rssLoader:URLLoader;
private var links:Array;
</pre>
<p>The constructor function will look like this:</p>
<pre class="brush: as3; title: ;">
links = new Array();

urlLoader = new URLLoader();
urlLoader.load(new URLRequest(xmlPath));
urlLoader.addEventListener(Event.COMPLETE, onDataLoaded);

rssLoader = new URLLoader();
rssLoader.addEventListener(Event.COMPLETE, rssLoaded);
locationsCombo.addEventListener(Event.CHANGE, changeLocation);
</pre>
<p>&#8230;after the XML is loaded we receive the results:</p>
<pre class="brush: as3; title: ;">
private function onDataLoaded(e:Event):void
{
	xml = new XML(URLLoader(e.target).data);
	var c:Number = -1;
	for each(var locations:XML in xml.location) {
		c++;
		links.push([locations.@title, locations.@code]);
		locationsCombo.addItem( { label:locations.@title, data:c } );
	}

		getInfo(0);
}
</pre>
<p>&#8230;make the request with the WOIED code:</p>
<pre class="brush: as3; title: ;">
private function getInfo(c:int) {
	rssLoader.load(new URLRequest(&quot;proxy.php?cod=&quot; + links[c][1]));
}
</pre>
<p>The function that allow us to change trough drop-down menu different locations:</p>
<pre class="brush: as3; title: ;">
private function changeLocation(e:Event):void
{
	getInfo(e.target.selectedItem.data);//data is the WOIED code from xml
}
</pre>
<p>&#8230;after the request was completed and we get the results:</p>
<pre class="brush: as3; title: ;">
private function rssLoaded(e:Event):void
		{

			xml = new XML(URLLoader(e.target).data);
			//see every node called forcast
//RSS feeds like Yahoo! weather have data that can't be retrieved by using the regular XML class. So we need to use the Namespace class that will give you access to data inside an RSS feed.
			var yweather:Namespace = new Namespace(&quot;http://xml.weather.yahoo.com/ns/rss/1.0&quot;);
			day1.getInfo(xml..item.yweather::forecast[0]);
			day2.getInfo(xml..item.yweather::forecast[1]);
			day3.getInfo(xml..item.yweather::forecast[2]);
			day4.getInfo(xml..item.yweather::forecast[3]);
			day5.getInfo(xml..item.yweather::forecast[4]);
		}
</pre>
<p>&#8230;and each <em>DayTab </em>container will receive the weather info. Also proxy.php will read the URL address (as RSS feed) and will return the content of XML &#8211; in this way we avoid the security problems.</p>
<pre class="brush: as3; title: ;">
&lt;?php
$url = &quot;http://xml.weather.yahoo.com/forecastrss/&quot; . $_GET['cod'] . &quot;_c.xml&quot;;
echo file_get_contents($url);
?&gt;
</pre>
<p>That&#8217;s it ladies and gentlemen, hope you will have a good winter and that you learn something from today. Until my next tutorial, Merry Christmas Everybody!</p>
<p id="preview"><a title="Preview Yahoo Weather App in Flash" href="http://preview.fladev.com/yahoo-weather-app-in-flash" target="_blank">Preview</a></p>
<hr/>
<div class="download"><a href="http://www.fladev.com/wp-content/files/weather.zip">Download sources</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fladev.com/featured/yahoo-weather-app-in-flash/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>ClassPaths and Packages in Adobe Flash Cs5</title>
		<link>http://www.fladev.com/tutorials/classpaths-and-packages-in-adobe-flash-cs5/</link>
		<comments>http://www.fladev.com/tutorials/classpaths-and-packages-in-adobe-flash-cs5/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 19:53:20 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Adobe Flash]]></category>
		<category><![CDATA[classpath]]></category>
		<category><![CDATA[flash cs5]]></category>
		<category><![CDATA[Latest]]></category>
		<category><![CDATA[package]]></category>

		<guid isPermaLink="false">http://www.fladev.com/?p=749</guid>
		<description><![CDATA[In these days, when Adobe&#8217;s Flash version is up to CS5, and when the code are not anymore accepted/used on objects, the concept of Actionscript Classes are more familiar to us as each day passes. Even if we build a banner, a simple or complex application or an animated template, we create a class, type [...]]]></description>
			<content:encoded><![CDATA[<p>In these days, when Adobe&#8217;s Flash version is up to CS5, and when the code are not anymore accepted/used on objects, the concept of Actionscript Classes are more familiar to us as each day passes. Even if we build a banner, a simple or complex application or an animated template, we create a class, type some code inside and voila &#8211; the job is done. Generally speaking, there are more than few steps to build an application, that&#8217;s way we will take a look closely on how these classes are builded.</p>
<h3>Classpaths</h3>
<p>Working with classes it&#8217;s not really rocket science, but you must set set them properly in order that your project to be well organized &#8211; so you need to show Flash where to look for them. Basically a classpath will tell to Flash where the whole organized structure of directories/sub directories are situated, which contain different classes &#8211; packages. There are two ways to do this: a global class path for all your projects you will work on &#8211; or a document-level class path separate for every new Flash file.</p>
<h3>Setting the Global Classpath</h3>
<p>As we&#8217;ve discussed, a global classpath can be used by any new Flash file &#8211; in present I have 2 folders -as2 (with as2 classes) and as3 (with as3 classes). What do I have for example in my folder as3? Well I used to keep there classes from Caurina, Adobe or even custom classes, for example a class for rollOver and rollOut for any button created. So I don&#8217;t have to copy these classes on any new project, each time. To set a global classpath in actionscript 3.0 you must go to Edit &gt; Preferences (or simple <em>CTRL+U</em>) &gt; ActionScript &gt; ActionScript 3.0 Settings.</p>
<p><a href="http://www.fladev.com/wp-content/uploads/2010/10/cs5_preferences_panel.jpg"><img class="size-full wp-image-751 alignnone" title="cs5_preferences_panel" src="http://www.fladev.com/wp-content/uploads/2010/10/cs5_preferences_panel.jpg" alt="" width="562" height="672" /></a><br />
<a href="http://www.fladev.com/wp-content/uploads/2010/10/global_class_path.jpg"><img class="size-full wp-image-753 alignnone" title="global_class_path" src="http://www.fladev.com/wp-content/uploads/2010/10/global_class_path.jpg" alt="" width="562" height="672" /></a></p>
<p>As you can see my global class path is &#8220;D:\Classes\as3&#8243; &#8211; you can create on any disk drive a folder with your classes, it will help you very well on your next project. Also, Flash will import these automatically, so you don&#8217;t have to import them anymore.</p>
<h3>Setting the Document-Level Classpath</h3>
<p>To setting a document-level classpath you have to follow these steps in every new flash file created: in Properties panel go to Profile &gt; Edit (or simple<em> CTRL+SHIFT+F12</em>) or File &gt; Publish Settings, near the Actionscript 3.0 dropdown choose Settings.<a href="http://www.fladev.com/wp-content/uploads/2010/10/publish_settings.jpg"><img class="size-full wp-image-756 alignnone" title="publish_settings" src="http://www.fladev.com/wp-content/uploads/2010/10/publish_settings.jpg" alt="" width="435" height="200" /></a></p>
<p>Here ai strongly recommend to <em>uncheck </em>the checkbox &#8220;Automatically declare stage instances&#8221; &#8211; by checking this you must declare all MovieClips and objects by being public variables in every class, but also this will make visible any properties/functions of that movieclip in any class, once that is declared. In source path tab, add a new path of your folder where all classes will be stored.</p>
<p>Don&#8217;t use an absolute path, like <em>C:\src\mysubfolder\myclass</em> becouse Flash will not understand where are all that classes you declared before, if you move this flash file on other computer, for example. <a href="http://www.fladev.com/wp-content/uploads/2010/10/as3_settings.jpg"><img class="size-full wp-image-758 alignnone" title="as3_settings" src="http://www.fladev.com/wp-content/uploads/2010/10/as3_settings.jpg" alt="" width="449" height="661" /></a></p>
<p>This is also a useful way, becouse you don&#8217;t have to type the hole path in your document class for example. Now you just type <em>mysubfolder.myclass</em> and that&#8217;s it.</p>
<p>By convention a right classpath will contain a path such as <strong>yourrojectname.yourapplicationame.yourclassfolder </strong>or other people use <strong>theirdomainextension.theirdomainname.theirprojectname</strong> &#8211; it&#8217;s ok both ways.</p>
<p>Another thing that I want to remind you, is that by convention your class name should never start with a lowercase character! Use more often folders &#8211; for your classes and for your movieclips inside of your Flash file, try to create a structure with not just a single or 2 classes. It will make your project more and more complicated.</p>
<p>Many thanks to my master, <a href="http://www.goflash.org">Virusescu</a>. Cheers until next time!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fladev.com/tutorials/classpaths-and-packages-in-adobe-flash-cs5/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

