<?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/"
	>

<channel>
	<title>Flash Explained</title>
	<atom:link href="http://flashexplained.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://flashexplained.com</link>
	<description>Learn Flash easily.</description>
	<pubDate>Sun, 05 Apr 2009 21:35:53 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>New host, new tutorials, new features</title>
		<link>http://flashexplained.com/news/new-host-new-tutorials-new-features/</link>
		<comments>http://flashexplained.com/news/new-host-new-tutorials-new-features/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 21:35:53 +0000</pubDate>
		<dc:creator>Luka</dc:creator>
		
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://flashexplained.com/?p=944</guid>
		<description><![CDATA[Hi friends,
It&#8217;s been long since I posted anything new. Well, rejoice, for new tutorials are in the works! Also, I&#8217;ll be changing the host for flashexplained.com because I need something more powerful to handle my 100K+ monthly visits. So don&#8217;t sweat it if the site goes down for 1-2 days. It will be back - [...]]]></description>
			<content:encoded><![CDATA[<p>Hi friends,</p>
<p>It&#8217;s been long since I posted anything new. Well, rejoice, for new tutorials are in the works! Also, I&#8217;ll be changing the host for flashexplained.com because I need something more powerful to handle my 100K+ monthly visits. So don&#8217;t sweat it if the site goes down for 1-2 days. It will be back - faster, better and with new features, too. I am planning to add a download section. It will come in handy, you&#8217;ll see why.</p>
<p>So, keep on working in Flash and expect new, fresh tutorials coming your way! Thanks for all the e-mails and cool comments. Sorry if I don&#8217;t reply to your comments, but I have way too much work to do to be able to handle these.</p>
<p>See you soon in new tuts,</p>
<p>Luka Maras</p>
]]></content:encoded>
			<wfw:commentRss>http://flashexplained.com/news/new-host-new-tutorials-new-features/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flash CS3 animation basics: Motion guide</title>
		<link>http://flashexplained.com/animation/flash-cs3-animation-basics-motion-guide/</link>
		<comments>http://flashexplained.com/animation/flash-cs3-animation-basics-motion-guide/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 13:28:14 +0000</pubDate>
		<dc:creator>Luka</dc:creator>
		
		<category><![CDATA[Animation]]></category>

		<guid isPermaLink="false">http://flashexplained.com/?p=896</guid>
		<description><![CDATA[With this simple and straightforward tutorial, you will learn one very handy animation technique: how to use a motion guide to make an object follow a certain path. I&#8217;ll show you:

How to create a motion guide (inside a guide layer),
How to make a movieclip follow the motion guide you made,
How to make the guided animation [...]]]></description>
			<content:encoded><![CDATA[<p>With this simple and straightforward tutorial, you will learn one very handy animation technique: how to use a <strong>motion guide</strong> to make an object follow a certain path. I&#8217;ll show you:</p>
<ul class="learningpoints">
<li>How to create a motion guide (inside a guide layer),</li>
<li>How to make a movieclip follow the motion guide you made,</li>
<li>How to make the guided animation more realistic and more.</li>
</ul>
<p>You will be creating a <a href="http://flashexplained.com/animation/flash-cs3-animation-basics-motion-tween/">motion tween animation</a> which will then be linked to a <strong>motion guide</strong>. You can see the kind of animation you are going to make below.</p>

<object	type="application/x-shockwave-flash"
			data="http://www.flashexplained.com/img/animation/media/cs3-animation-motion-guide-example.swf"
			width="550"
			height="400">
	<param name="movie" value="http://www.flashexplained.com/img/animation/media/cs3-animation-motion-guide-example.swf" />
</object><br />
<span id="more-896"></span></p>
<h3>1. Making a simple motion tween animation that will follow the motion guide later</h3>
<p><span class="step">1.1</span> Open a new document by selecting <strong>File &gt; New</strong>. Select <strong>Flash File (ActionScript 3.0)</strong>, click <strong>OK</strong>.</p>
<p><span class="step">1.2</span> <strong>Save</strong> your document right away. Later, you&#8217;ll be able to save it just by pressing <strong>Ctrl+S</strong>. Remember to do this whenever you pass a certain number of steps or make significant changes to your document. It is better to save often then to lose your work because of your computer crashing, power shortages, etc.</p>
<p>OK. You&#8217;ll start by making a movieclip. You need it to make a motion tween animation which will be made to follow a motion guide later. A paper airplane will be fine for this kind of animation.</p>
<p><span class="step">1.3</span> Select the Line tool <strong>(N)</strong>. Select a darker grey hue for the <strong>Stroke color</strong> (I picked #646464), turn on the <strong>Snap to Objects</strong> option and make sure that <strong>Object Drawing</strong> is turned off. The screenshot below shows you these three options clearly.</p>
<p><img src="/img/animation/cs3mg/cs3-mg001-line-tool.gif" alt="Options for the Line tool." width="343" height="105" /></p>
<p><span class="step">1.4</span> Click and start dragging with the Line tool downwards. Make a line that is approximately 60-65 pixels long.</p>
<p><img src="/img/animation/cs3mg/cs3-mg002-line-drawing.gif" alt="Drawing a straight line." width="140" height="66" /></p>
<p>Since you have turned on the Snap to Objects option, drawing a straight line should pose no problem at all.</p>
<p><span class="step">1.5</span> Select the Zoom tool <strong>(Z)</strong> and zoom in on the line that you just drew. Click and drag to zoom in on the desired area.</p>
<p><img src="/img/animation/cs3mg/cs3-mg003-zooming-in.gif" alt="Using the zoom tool to work more easily." width="85" height="119" /></p>
<p>You&#8217;ll be able to work more easily now.</p>
<p><span class="step">1.6</span> Use the Line tool <strong>(N)</strong> again. The <strong>Snap to Objects</strong> option should be turned on from before (that&#8217;s the small magnet icon found at the bottom of the Tools panel). Bring the cursor near the top of the line, <strong>click and start dragging</strong> left and down. You will automatically start drawing from the top end of the existing line, thanks to the Snap to Objects option.</p>
<p><img src="/img/animation/cs3mg/cs3-mg004-drawing-lines.gif" alt="Drawing lines with the Line tool in Flash CS3" width="300" height="216" /></p>
<p><span class="step">1.7</span> Add three more lines to complete one side of your paper airplane, as shown on the image below.</p>
<p><img src="/img/animation/cs3mg/cs3-mg005-flashcs3-drawing.gif" alt="Adding further lines." width="400" height="208" /></p>
<p><span class="step">1.8</span> Select the whole drawing using the Selection tool <strong>(V)</strong>.</p>
<p><img src="/img/animation/cs3mg/cs3-mg006-selecting-vectors.gif" alt="Selecting the drawing with the Selection tool." width="271" height="249" /></p>
<p><span class="step">1.9</span> <strong>Copy</strong> the selected items by pressing <strong>Ctrl+C</strong> or selecting <strong>Edit &gt; Copy</strong>.</p>
<p><span class="step">1.10</span> You will now paste in place a copy of these lines either by pressing <strong>Ctrl+Shift+V</strong> or selecting <strong>Edit &gt; Paste in Place</strong>. Now, there won&#8217;t be any apparent change. But you have just pasted a smae, exact copy of your drawing over the original one. To see it, use the <strong>left</strong> or <strong>right arrow</strong> keys on your keyboard to move the new copy.</p>
<p><img src="/img/animation/cs3mg/cs3-pasting-and-moving.gif" alt="Moving the new copy of your vector drawing." width="195" height="210" /></p>
<div class="note">
<p>If you had clicked anywhere on the stage after pasting the drawing in place, you will lose it. That&#8217;s because the copy will merge with the original automatically. That&#8217;s what happens with vectors (pure drawings, not symbols) in Flash. So, if you want to make use of your new copy, just move it before clicking anything else.</p>
</div>
<p><span class="step">1.11</span> With the freshly pasted copy still selected, select <strong>Modify &gt; Transform &gt; Flip Horizontal</strong>.</p>
<p><img src="/img/animation/cs3mg/cs3-flip-horizontal.gif" alt="Using the Flip Horizontal action to create a mirror image." width="195" height="210" /></p>
<p><span class="step">1.12</span> Move the mirrored half so that it joins the original drawing perfectly. You can do that with the <strong>arrow keys</strong>, but I recommend doing it with the Selection tool <strong>(V)</strong>, because thanks to it, the drawing will perfectly snap into place, as shown in the picture below.</p>
<p><img src="/img/animation/cs3mg/cs3-snapping-objects.gif" alt="Putting two vector objects together with the selection tool." width="195" height="213" /></p>
<p><span class="step">1.13</span> If you wish to make your paper airplane more realistic, you can apply some linear gradient color fills to it. Use the Paint Bucket tool <strong>(K)</strong> to do it.</p>
<p><img src="/img/animation/cs3mg/cs3-linear-color-fills.jpg" alt="Applying some linear gradients to the vevtor drawing." width="409" height="263" /></p>
<p><span class="step">1.14</span> Turn back the zoom to 100% (no zoom at all).</p>
<p><img src="/img/animation/cs3mg/cs3-zoom-stage.gif" alt="Zooming the stage to 100%" width="257" height="198" /></p>
<p><span class="step">1.15</span> <strong>Select</strong> your completed drawing, both the lines and fills, using the Selection tool <strong>(V)</strong>. To create a movieclip out of your selected vector drawing, select <strong>Modify &gt; Convert to Symbol</strong>.</p>
<p>Call your new symbol <em>paper airplane</em>, select <strong>Movie clip</strong> as type and also select the central square for the registration point This last choice isn&#8217;t exactly a must, but it will make creating the guided animation a little bit easier. Click <strong>OK</strong>.</p>
<p><img src="/img/animation/cs3mg/cs3-creating-movieclip.gif" alt="Creating a new movieclip symbol in Flash CS3." width="408" height="137" /></p>
<p>&#8230;as soon as you do that, an azure outline will appear around your newly made symbol and the Properties inspector will also show you that you are dealing with a movieclip symbol now and not a simple drawing anymore.</p>
<p><img src="/img/animation/cs3mg/cs3-new-movieclip.gif" alt="The new movieclip shown." width="267" height="122" /></p>
<p>You will create a simple motion tween animation now.</p>
<p><span class="step">1.16</span> <strong>Right-click</strong> on frame 50 and select <strong>Insert Keyframe</strong>.</p>
<p><img src="/img/animation/cs3mg/cs3-inserting-new-keyframe.gif" alt="A new keyframe is being inserted into the layer." width="388" height="187" /></p>
<p><span class="step">1.17</span> Use the Selection tool <strong>(V)</strong> to move the movieclip. Just click and drag it to a new position. You can place it anywhere, because what&#8217;s important is that you make a motion tween animation, the direction of the movement isn&#8217;t important now.</p>
<p><img src="/img/animation/cs3mg/cs3-moving-a-movieclip.gif" alt="Moving the newly made movieclip." width="220" height="135" /></p>
<p><span class="step">1.18</span> <strong>Right-click</strong> between the two keyframes and select the <strong>Create Motion Tween</strong> animation.</p>
<p><img src="/img/animation/cs3mg/cs3-motion-tweening.gif" alt="Creating a motion tween animation." width="550" height="92" /></p>
<p>If you have done everything properly, an unbroken arrow over a purple background should appear.</p>
<p><img src="/img/animation/cs3mg/cs3-good-motion-tween.gif" alt="A correctly done motion tween animation." width="550" height="64" /></p>
<p>If you didn&#8217;t obtain a good motion tween (your arrow is dashed-broken), please check my <a href="http://flashexplained.com/animation/flash-cs3-animation-basics-motion-tween/">motion tween animation</a> tutorial which explaines in detail how to make such an animation, and where possible errors may lurk.</p>
<p><span class="step">1.19</span> Call the current layer <em>airplane</em> and <strong>lock</strong> it.</p>
<p><img src="/img/animation/cs3mg/cs3-locking-a-layer.gif" alt="The first layer has been renamed and locked." width="350" height="58" /></p>
<p>Fine. Now you have the prerequisite for creating a guided animation &#8212; a simple motion tween. Let me show you how to add a guide to it.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>2. Creating a motion guide</h3>
<p><span class="step">2.1</span> Click the <strong>Add Motion Guide</strong> icon beneath the layers to add a new motion guide.</p>
<p><img src="/img/animation/cs3mg/cs3-motion-guide-layer.gif" alt="Adding a motion guide layer." width="333" height="168" /></p>
<p>As you can immediately see, a new motion guide layer has been added to your document. The layer benath it (<em>airplane</em>) has instantly become linked to this layer, become  the <strong>guided layer</strong>. The <em>airplane</em> layer is now guided by the <em>Guide: airplane</em> layer. This can clearly be seen by the layer&#8217;s icon which has become slightly indented &#8212; it has moved to the right.</p>
<p><img src="/img/animation/cs3mg/cs3-guide-and-guided-layers.gif" alt="The motion guide and the layer guided by it." width="333" height="80" /></p>
<p>Also, the duration of the guide layer is the same as that of the guided layer (50 frames in this particular example).</p>
<p><span class="step">2.2</span> Select the Pencil tool <strong>(Y)</strong>. In the Tools panel, go to the end of it and choose the <strong>Smooth</strong> option for drawing with your pencil.</p>
<p><img src="/img/animation/cs3mg/cs3-pencil-smooth.gif" alt="Smooth option for the pencil tool." width="159" height="124" /></p>
<p>In the Properties inspector, select <strong>hairline</strong> as line type and enter <strong>100</strong> as the value for the <strong>Smoothing</strong> option. Choose any color you like, since <strong>the guide won&#8217;t be visible</strong>. I chose hairline to be able to work more easily and adjust the animation in more detail.</p>
<p><img src="/img/animation/cs3mg/cs3-pencil-tool-properties.gif" alt="The options for the Pencil tool." width="461" height="93" /></p>
<p><span class="step">2.3</span> Click and start dragging with the Pencil tool <strong>(Y)</strong> to draw a guide (in the <em>Guide: airplane</em> layer, of course). Make a curve &#8212; it will come in handy for simulating the flight of your paper airplane. I started and finished drawing the curve <strong>outside</strong> the stage on purpose &#8212; to make it appear as if the airplane flew inside the scene and then disappeared outside of it.</p>
<p><img src="/img/animation/cs3mg/cs3-drawing-a-guide.gif" alt="A curve will serve as the guide for the animation." width="550" height="323" /></p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>3. Creating a guided motion tween animation</h3>
<p><span class="step">3.1</span> Now <strong>lock</strong> the <em>Guide: airplane</em> layer and <strong>unlock</strong> the <em>airplane</em> layer. <strong>Click</strong> on the first keyframe of the <em>airplane</em> layer to select it.</p>
<p><img src="/img/animation/cs3mg/cs3-locking-layers.gif" alt="Locking and unlocking the layers." width="550" height="152" /></p>
<p><span class="step">3.2</span> <strong>Click</strong> on the <em>paper airplane</em> movieclip <strong>once</strong> to select it - do this with the Selection tool <strong>(V)</strong>.</p>
<p><span class="step">3.3</span> You will move the movieclip to the guide&#8217;s starting point. Use the Selection tool <strong>(V)</strong> again. Click on the movieclip&#8217;s <strong>registration point</strong> (that&#8217;s the small circle with a little cross inside) and <strong>drag it</strong> over to the beginning of the guide. Once the movieclip is ready to snap into place, you will see a bold, black circle appear near your cursor, as shown below.</p>
<p><img src="/img/animation/cs3mg/cs3-movieclip-placement.gif" alt="The movieclip has just snapped onto the guide." width="550" height="297" /></p>
<p>If the snapping does not occur, check if it is turned on.</p>
<p><img src="/img/animation/cs3mg/cs3-snap-to-objects.gif" alt="The Snap to Objects option selected in the Tools panel." width="166" height="150" /></p>
<p><span class="step">3.4</span> <strong>Click</strong> on the second keyframe in the airplane layer to select it.</p>
<p><img src="/img/animation/cs3mg/cs3-selecting-keyframe.gif" alt="Selecting a keyframe in the guided layer." width="550" height="130" /></p>
<p><span class="step">3.5</span> Now do the same thing for the movieclip in this keyframe: Place it over the other end of the guide using the Selection tool <strong>(V)</strong>. It should also snap into place, just like before.</p>
<p><img src="/img/animation/cs3mg/cs3-movieclip-guide.gif" alt="Placing the movieclip on the guide." width="550" height="306" /></p>
<p><span class="step">3.6</span> Speed up the animation a little bit (before testing it), by <strong>increasing the frame rate</strong> of your Flash movie. <strong>Double-click</strong> the frame rate (below the layers) to open the Document Properties window.</p>
<p><img src="/img/animation/cs3mg/cs3-frame-rate.gif" alt="Accessing the frame rate option in Flash CS3." width="490" height="165" /></p>
<p>Set the Frame rate to <strong>24 fps</strong> and click OK.</p>
<p><img src="/img/animation/cs3mg/cs3-swf-speed.gif" alt="Modifying the speed of the SWF movie." width="372" height="346" /></p>
<p><span class="step">3.7</span> Select <strong>Control &gt; Test Movie</strong>. You should see an animation similar to the one shown below.</p>

<object	type="application/x-shockwave-flash"
			data="http://www.flashexplained.com/img/animation/media/flashcs3-motion-guide-simple.swf"
			width="550"
			height="400">
	<param name="movie" value="http://www.flashexplained.com/img/animation/media/flashcs3-motion-guide-simple.swf" />
</object>
<p>Wow! The movieclip is moving along the guide! You did it. But, there is one obvious flaw here: the paper airplane isn&#8217;t moving around as in the real world. It should be moving with its nose pointing forward. So let me show you now how you can easily do that (you must, because animation is about simulating the real-world)!</p>
<p><span class="step">3.8</span> <strong>Select</strong> the first keyframe again.</p>
<p><img src="/img/animation/cs3mg/cs3-keyframe-selection.gif" alt="Selecting the keyframe for motion adjustment." width="335" height="123" /></p>
<p><span class="step">3.9</span> Select the Free Transform tool <strong>(Q)</strong>. Also, turn off the Snap to Objects option to be able to adjust your movieclip&#8217;s position freely, without any snapping.</p>
<p><img src="/img/animation/cs3mg/cs3-free-transform.gif" alt="Selecting the Free transform tool." width="167" height="56" /></p>
<p><span class="step">3.10</span> Bring the cursor near one of the movieclip&#8217;s corners (if the movieclip isn&#8217;t selected, select it now). <strong>Click and start rotating</strong> until the paper airplane&#8217;s nose is aligned with the direction of your motion guide (the curve in the layer above it).</p>
<p><img src="/img/animation/cs3mg/cs3-rotating-movieclip.gif" alt="Rotating a movieclip with the Free Transform tool." width="501" height="139" /></p>
<p><span class="step">3.11</span> <strong>Select</strong> the second keyframe of your animation again.</p>
<p><img src="/img/animation/cs3mg/cs3-click-keyframe.gif" alt="Selecting the keyframe on the animation's ending." width="159" height="100" /></p>
<p><span class="step">3.12</span> Adjust the movieclip with the Free Transform tool here too. The important thing is that the movieclip should be oriented as if it was following the guide all along &#8212; aligned with its direction.</p>
<p><img src="/img/animation/cs3mg/cs3-manipulating-movieclip.gif" alt="Rotating the movieclip in relation to the motion guide in the layer above it." width="380" height="168" /></p>
<p><span class="step">3.13</span> There is one last thing to be done to have a proper guided motion tween: <strong>Select the first keyframe</strong> again (like you did in step 3.8) and go to the Properties inspector. Once there, turn on the option called <strong>Orient to path</strong>. Make sure that it is selected, as seen below.</p>
<p><img src="/img/animation/cs3mg/cs3-orient-to-path.gif" alt="Selecting the Orient to path option for the guided animation." width="387" height="127" /></p>
<p><span class="step">3.14</span> Test your SWF again by selecting <strong>Control &gt; Test Movie</strong> and you should see your airplane moving realistically, as shown at the beginning of this lesson.</p>
<p>Now that was easy, wasn&#8217;t it? Guided animations are fun, because they help simulate real-world movements of various objects. In one of the upcoming animation tutorials, I will also explain to you how to create a circular animation and how to display the path. In the meantime, <a href="http://feeds.feedburner.com/FlashExplained">Subscribe to FlashExplained</a> and you&#8217;ll be notified of any new Flash lessons coming your way! Download the source FLA file for this lesson below.</p>
<p><a href="http://www.flashexplained.com/img/animation/materials/cs3-motion-guide.zip">Download the source file</a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashexplained.com/animation/flash-cs3-animation-basics-motion-guide/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Wishing you all the best</title>
		<link>http://flashexplained.com/news/wishing-you-all-the-best/</link>
		<comments>http://flashexplained.com/news/wishing-you-all-the-best/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 17:50:25 +0000</pubDate>
		<dc:creator>Luka</dc:creator>
		
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://flashexplained.com/?p=893</guid>
		<description><![CDATA[Happy New Year! Wishing you lots of love, health and money in 2009!
Luka Maras
]]></description>
			<content:encoded><![CDATA[<p>Happy New Year! Wishing you lots of love, health and money in 2009!</p>
<p>Luka Maras</p>
]]></content:encoded>
			<wfw:commentRss>http://flashexplained.com/news/wishing-you-all-the-best/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flash CS3 animation basics: Animating effects</title>
		<link>http://flashexplained.com/animation/flash-cs3-animation-basics-animating-effects/</link>
		<comments>http://flashexplained.com/animation/flash-cs3-animation-basics-animating-effects/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 23:19:39 +0000</pubDate>
		<dc:creator>Luka</dc:creator>
		
		<category><![CDATA[Animation]]></category>

		<guid isPermaLink="false">http://flashexplained.com/?p=880</guid>
		<description><![CDATA[In this easy lesson, you will see how to animate effects in Flash. You&#8217;ll learn how to animate a filter and create a glowing effect and more along the way.
Take a peek at what you are going to learn to create below:

<object	type="application/x-shockwave-flash"
			data="http://www.flashexplained.com/img/animation/media/cs3-animating-effects-example.swf"
			width="400"
			height="300">
	<param name="movie" value="http://www.flashexplained.com/img/animation/media/cs3-animating-effects-example.swf" />
</object>

1. Creating a simple movieclip
1.1 Open a new document: choose [...]]]></description>
			<content:encoded><![CDATA[<p>In this easy lesson, you will see how to animate effects in Flash. You&#8217;ll learn how to animate a filter and create a glowing effect and more along the way.</p>
<p>Take a peek at what you are going to learn to create below:</p>

<object	type="application/x-shockwave-flash"
			data="http://www.flashexplained.com/img/animation/media/cs3-animating-effects-example.swf"
			width="400"
			height="300">
	<param name="movie" value="http://www.flashexplained.com/img/animation/media/cs3-animating-effects-example.swf" />
</object><br />
<span id="more-880"></span></p>
<h3>1. Creating a simple movieclip</h3>
<p><span class="step">1.1</span> Open a new document: choose <strong>File &gt; New</strong>. Select <strong>Flash File (ActionScript 3.0)</strong>. Click <strong>OK</strong>.</p>
<p><img src="/img/animation/cs3ae/cs3ae_001.gif" alt="Opening a new document in Flash CS3." width="550" height="360" /></p>
<p><span class="step">1.2</span> <strong>Double-click</strong> the <strong>fps</strong> field below the layers (you can see it in the screenshot below) to access the Document Properties.</p>
<p><img src="/img/animation/cs3ae/cs3ae_002.gif" alt="Accessing the document properties." width="550" height="165" /></p>
<p>Change the speed of your movie (to make your animation more smooth) by typing <strong>24</strong> in the <strong>Frame rate</strong> field. Click <strong>OK</strong>. This will speed up your movie to a decent level for a nice animation.</p>
<p><img src="/img/animation/cs3ae/cs3ae_003.gif" alt="The Document Properties window." width="372" height="346" /></p>
<p><span class="step">1.3</span> Select the Oval tool <strong>(O)</strong>.</p>
<p>Set the options for it as follows:</p>
<ul>
<li>Turn off the <strong>stroke</strong> (outline) color.</li>
<li>Choose some shade of <strong>red</strong> for the <strong>fill</strong> color (you will make something similar to a red alarm light).</li>
<li>Check that the Object Drawing option is turned off and let it stay that way (it&#8217;s next to the litle magnet icon).</li>
</ul>
<p><img src="/img/animation/cs3ae/cs3ae_004.gif" alt="Setting up the parameters for the Oval tool." width="212" height="210" /></p>
<p><span class="step">1.4</span> Hold down <strong>Shift</strong> on your keyboard, <strong>click and start dragging</strong> with the Oval tool to make a circle. Make it about 100 by 100 pixels. Remember that holding down Shift enables you to make a circle right away, and not an oval.</p>
<p><img src="/img/animation/cs3ae/cs3ae_005.gif" alt="A 100 pixel circle drawn on the stage." width="263" height="201" /></p>
<p><span class="step">1.5</span> You&#8217;ll now use the Oval tool <strong>(O)</strong> again, but to draw an outline of a circle only. With the tool still selected, go to the Properites Inspector below the stage and <strong>block</strong> the <strong>fill color</strong>. Select <strong>white</strong> for the outline color, with a thickness of <strong>4</strong>.</p>
<p><img src="/img/animation/cs3ae/cs3ae_006.gif" alt="Selecting the properties of the Oval tool in the Properties Inspector." width="550" height="136" /></p>
<p><span class="step">1.6</span> Draw a circle smaller than the previous one. Do it outside the stage, because you are using white - to see what you are doing.</p>
<p><img src="/img/animation/cs3ae/cs3ae_007.gif" alt="An outline circle was just created." width="292" height="172" /></p>
<p><span class="step">1.7</span> Choose the Selection tool <strong>(V)</strong>. You will cut out 3/4 of the outline circle now. Select the lower half of it by clicking outside it with the Selection tool, dragging and releasing once you&#8217;ve encompassed the desired area. Press <strong>Delete</strong> or <strong>Backspace</strong> to erase the selected part.</p>
<p><img src="/img/animation/cs3ae/cs3ae_008.gif" alt="Selecting and erasing a part of your drawing." width="535" height="153" /></p>
<p><span class="step">1.8</span> Repeat the same thing for the right quarter of the circle.</p>
<p><img src="/img/animation/cs3ae/cs3ae_009.gif" alt="Cutting away a quarter of the outline circle." width="523" height="118" /></p>
<p><span class="step">1.9</span> Select the remaining line by <strong>clicking</strong> on it with the Selection tool <strong>(V)</strong>. Move it over the red circle so that it appears as a sort of shine on it. You can move it by pressing and holding down <strong>Shift</strong> on your keyboard and using the arrow keys to move it around. For more precise movement, release Shift and use the arrows only.</p>
<p><img src="/img/animation/cs3ae/cs3ae_010.gif" alt="Shiny red circle." width="260" height="174" /></p>
<p><span class="step">1.10</span> Select the whole drawing now.</p>
<p><img src="/img/animation/cs3ae/cs3ae_011.gif" alt="Selecting all the vectors." width="365" height="193" /></p>
<p><span class="step">1.11</span> Select <strong>Modify &gt; Convert to Symbol</strong>. Name your new movieclip <em>bulb</em>. Select <strong>movieclip</strong> as type, of course. Click <strong>OK</strong>.</p>
<p><img src="/img/animation/cs3ae/cs3ae_012.gif" alt="Making a movieclip out of a vector drawing in Flash CS3." width="408" height="137" /></p>
<p>And now - save your work before proceeding to the second part (<strong>File &gt; Save</strong>)!</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>2. Applying effects to a movieclip and animating them</h3>
<p>To be able to animate effects like blur, glow and others in Flash, you have to use the <a href="http://flashexplained.com/animation/flash-cs3-animation-basics-motion-tween/">motion tween</a> animation technique - one of the basic ways to set things in motion in Flash. So, before actually using the effects, you have to create an animation first, by adding a new keyframe and making some modifications. Let me show you how - it is easy!</p>
<p><span class="step">2.1</span> <strong>Right-click</strong> on frame <strong>20</strong> of the first and only layer and select <strong>Insert Keyframe</strong>.</p>
<p><img src="/img/animation/cs3ae/cs3ae_013.gif" alt="Inserting a keyframe where effects will be applied to a movieclip" width="550" height="226" /></p>
<p>You will see that the new keyframe you have just inserted is displayed in the Properties Inspector.</p>
<p><img src="/img/animation/cs3ae/cs3ae_014.gif" alt="A frame as it is seen in the Properties Inspector." width="323" height="143" /></p>
<p>This is because when you insert a new keyframe in a layer, it becomes selected automatically. But you need to have your movieclip selected. So&#8230;</p>
<p><span class="step">2.2</span> Select your <em>bulb</em> movieclip by clicking on it <strong>once</strong> with the Selection tool <strong>(V)</strong>. The change will be reflected in the Properties Inspector instantly - your movieclip is selected now.</p>
<p><img src="/img/animation/cs3ae/cs3ae_015.gif" alt="A movieclip has been selected in Flash." width="323" height="143" /></p>
<p><span class="step">2.3</span> Click on the <strong>Filters</strong> tab. Then click on the small blue cross to access the effects at your disposal.</p>
<p><img src="/img/animation/cs3ae/cs3ae_016.gif" alt="Accessing the filter effects in Flash CS3." width="372" height="143" /></p>
<p><span class="step">2.4</span> Select the <strong>Glow</strong> effect from the menu. Select the following values for it:</p>
<ul>
<li><strong>Blur X</strong> and <strong>Blur Y</strong>: 31</li>
<li><strong>Strength</strong>: 230</li>
<li><strong>Quality</strong>: Low</li>
<li><strong>Color</strong>: red (#FF0000)</li>
<li>Leave the Konckout and Inner glow options unchecked.</li>
</ul>
<p><img src="/img/animation/cs3ae/cs3ae_017.gif" alt="Glow effect and its parameters." width="550" height="143" /></p>
<p>This is the result you should see &#8211; a nice, red glow appearing around your movieclip.</p>
<p><img src="/img/animation/cs3ae/cs3ae_018.gif" alt="The glow effect applied to a movieclip." width="294" height="211" /></p>
<div class="note">
<p>Effects in Flash can be applied only to <strong>movieclip symbols</strong>, <strong>button symbols</strong> and <strong>text fields</strong>. They cannot be applied to simple vector drawings, images or anything else other than the three aforementioned objects. If you want to apply an effect to a drawing, convert that drawing into a movieclip first and then proceed with the application of effects.</p>
</div>
<p><span class="step">2.5</span> You should create the animation now &#8212; to animate the glowing effect. Just <strong>right-click</strong> on the grey area between the two keyframes and select <strong>Create Motion Tween</strong>.</p>
<p><img src="/img/animation/cs3ae/cs3ae_019.gif" alt="Making a motion tween animation for effects." width="550" height="265" /></p>
<p>A continuous, unbroken arrow should appear on a magenta background. I won&#8217;t delve into details here, because I already explained in exhaustive detail the proper procedures to create a <a href="http://flashexplained.com/animation/flash-cs3-animation-basics-motion-tween/">motion tween animation</a>. Check it out if you have any questions. Also check the <a href="http://flashexplained.com/animation/flash-cs3-animation-basics-shape-tween/">shape tween animation lesson</a>.</p>
<p><img src="/img/animation/cs3ae/cs3ae_020.gif" alt="The motion tween for animating the glow effect is in place." width="550" height="158" /></p>
<p><span class="step">2.6</span> Select <strong>Control &gt; Test Movie</strong>. You should see your glow appear, from nothing, to full bright red that you have applied to your movieclip in the second keyframe, like this:</p>

<object	type="application/x-shockwave-flash"
			data="http://www.flashexplained.com/img/animation/media/cs3-animating-effects-example-2.swf"
			width="400"
			height="300">
	<param name="movie" value="http://www.flashexplained.com/img/animation/media/cs3-animating-effects-example-2.swf" />
</object>
<p><span class="step">2.7</span> Now that&#8217;s fine, but there is that abrupt jump at the end of your animation. There is no smooth transition between the glowing effect at its most visible and the first keyframe where there is no glow visible at all. You are going to change this now, easily.</p>
<p><strong>Right-click</strong> on the <strong>first keyframe</strong> and select the option <strong>Copy Frames</strong> from the menu that shows up.</p>
<p><img src="/img/animation/cs3ae/cs3ae_021.gif" alt="Copying the keyframe where no effects are applied to your movieclip" width="550" height="274" /></p>
<p><span class="step">2.8</span> You will paste this keyframe onto frame <strong>40</strong>. Right-click there and select <strong>Paste Frames</strong>.</p>
<p><img src="/img/animation/cs3ae/cs3ae_022.gif" alt="Pasting a keyframe to complete the animation loop." width="550" height="297" /></p>
<p><span class="step">2.9</span> Do the same thing as you did before - <strong>right-click</strong> between the two keyframes and <strong>create a motion tween animation</strong>.</p>
<p><img src="/img/animation/cs3ae/cs3ae_023.gif" alt="Adding the second motion tween animation - from glow to no effects." width="550" height="162" /></p>
<p><span class="step">2.10</span> Test your Flash movie again by selecting <strong>Control &gt; Test Movie</strong>.</p>
<p>You should see now an animation similar to the one demonstrated at the beginning of this tutorial. The rythmical glowing of your  bulb movieclip. Yes, it is as easy as that. There is no effect applied in the first keyframe, and there is the glow applied in the second one. Make the motion tween and there you have animated effects in Flash!</p>
<p>You can do the same with the <strong>Color</strong> and <strong>Blend</strong> options. With filter effects thrown in too. Play and experiment to see what you can achieve!</p>
<p><img src="/img/animation/cs3ae/cs3ae_024.gif" alt="The blending and color-changing options for movieclips." width="550" height="136" /></p>
<p>I will make a lesson which will explain how to use what you have just learned, together with motion tweens and shape tweens to create professional animations. So stay tuned! <a href="http://feeds.feedburner.com/FlashExplained">Subscribe to FlashExplained</a> to keep track of every new tutorial!</p>
<p><a href="http://www.flashexplained.com/img/animation/materials/cs3-animating-effects.zip">Download the source file for this lesson</a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashexplained.com/animation/flash-cs3-animation-basics-animating-effects/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flash CS3 animation basics: Shape tween</title>
		<link>http://flashexplained.com/animation/flash-cs3-animation-basics-shape-tween/</link>
		<comments>http://flashexplained.com/animation/flash-cs3-animation-basics-shape-tween/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 17:31:14 +0000</pubDate>
		<dc:creator>Luka</dc:creator>
		
		<category><![CDATA[Animation]]></category>

		<category><![CDATA[shape tweening]]></category>

		<guid isPermaLink="false">http://flashexplained.com/?p=865</guid>
		<description><![CDATA[After learning how to make a motion tween in Flash CS3, it&#8217;s time to see how a shape tween is made.You will see and learn:

How to animate a drawn line,
How to animate a shape and morph it into something different,
You will also learn some really simple drawing and shape manipulation techniques along the way.

The first [...]]]></description>
			<content:encoded><![CDATA[<p>After learning how to make a <a href="http://www.flashexplained.com/animation/flash-cs3-animation-basics-motion-tween/">motion tween in Flash CS3</a>, it&#8217;s time to see how a shape tween is made.You will see and learn:</p>
<ul class="learningpoints">
<li>How to animate a drawn line,</li>
<li>How to animate a shape and morph it into something different,</li>
<li>You will also learn some really simple drawing and shape manipulation techniques along the way.</li>
</ul>
<p>The first simple shape tween that you are going to learn to create is shown right below. The second one will follow right after it, in this same lesson.</p>

<object	type="application/x-shockwave-flash"
			data="http://www.flashexplained.com/img/animation/media/cs3-shape-tween-example.swf"
			width="240"
			height="240">
	<param name="movie" value="http://www.flashexplained.com/img/animation/media/cs3-shape-tween-example.swf" />
</object><span id="more-865"></span></p>
<h3>1. Drawing the smiley shape</h3>
<p><span class="step">1.1</span> Open a new document by selecting <strong>File &gt; New</strong>. Select <strong>Flash File (ActionScript 3.0)</strong> and click <strong>OK</strong>.</p>
<p><span class="step">1.2</span> Go to the Property inspector (below the working area) and find the <strong>Frame rate</strong> option. Change it to <strong>24 fps</strong>. This is a nice speed, for a smooth animation in your SWF.</p>
<p><img src="/img/animation/cs3st/cs3st_001.gif" alt="Modifying the speed of your SWF." width="479" height="97" /></p>
<p><span class="step"><a name="step13" id="step13"></a>1.3</span> Select the Oval tool <strong>(O)</strong>&#8230;</p>
<p>&#8230;and go to the lower portion of the Tools panel. Click the colored square near the pencil icon, that&#8217;s the outline color. When the palette opens up, select the <strong>No color</strong> option. You can see it in the palette&#8217;s upper right corner in the image below. Then&#8230;</p>
<p><img src="/img/animation/cs3st/cs3st_002.gif" alt="Selecting the No color option for the outline color." width="327" height="131" /></p>
<p>&#8230;select a nice yellow fill color for your smiley.</p>
<p><img src="/img/animation/cs3st/cs3st_003.gif" alt="A hue of yellow has been selected for the fill." width="172" height="106" /></p>
<p><span class="step">1.4</span> <strong>Deselect</strong> the <strong>Object drawing</strong> option.</p>
<p><img src="/img/animation/cs3st/cs3st_004.gif" alt="Making sure that the Object drawing stays deselected." width="128" height="98" /></p>
<div class="note">
<p>This is a must if you want to draw pure shapes. Shape tween animation can be obtained by using simple vector shapes only. Objects, movieclips, graphic symbols and buttons cannot be used in a shape tween animation - they can&#8217;t change their shape. Morphing is possible with pure vectors only.</p>
</div>
<p><span class="step">1.5</span> Now, draw a circle on the stage. Make it <strong>150</strong> by <strong>150 pixels</strong>.</p>
<p><img src="/img/animation/cs3st/cs3st_005.gif" alt="A borderless circle with 150px by 150 px dimensions made in Flash CS3." width="160" height="160" /></p>
<p><span class="step">1.6</span> Call the current layer <em>head</em>. Double-click on its default name (<em>Layer 1</em>) to change it. Press <strong>Enter</strong> once you have typed in the new name. Now, press the small dot beneath the padlock icon to lock this layer. Since you finished all the work here, it makes sense to lock it. This will prevent you from accidentaly placing any drawings or objects inside it.</p>
<p><img src="/img/animation/cs3st/cs3st_006.gif" alt="Locking the head layer." width="287" height="86" /></p>
<p><span class="step">1.7</span> Create a fresh layer by clicking on the <strong>Insert Layer</strong> icon. Call the new layer <em>eyes</em>.</p>
<p><img src="/img/animation/cs3st/cs3st_007.gif" alt="Inserting a new layer in Flash CS3." width="287" height="141" /></p>
<p><span class="step">1.8</span> Select the Oval tool <strong>(O)</strong> again. Change the fill  color to <strong>black</strong>.</p>
<p><img src="/img/animation/cs3st/cs3st_008.gif" alt="Selecting black for the fill color." width="212" height="101" /></p>
<div class="note">
<p>As you can see, I changed the fill color in the <strong>Color</strong> panel. This is just to show you that you can do the same thing in many different ways in Flash. For example, the fill color can usually be changed in the Tools panel, in the Property Inspector or in the Color panel. The result is the same - the fill color for the Oval tool has been changed. There is no absolute, best way of doing something in Flash. With time and practice, you will find what works best for <em>you</em> and that&#8217;s what matters.</p>
</div>
<p><span class="step">1.9</span> Now, click and drag with the Oval tool to draw an ellipse. It should be elongated (on its vertical axis), so that its dimensions are approximately <strong>20 px</strong> by <strong>40 px</strong>.</p>
<p><img src="/img/animation/cs3st/cs3st_009.gif" alt="Adding an ellipse with the Oval tool in Flash CS3." width="160" height="160" /> </p>
<p>If you want to get these dimensions right, just click on the eye with the Selection tool <strong>(V)</strong> and go to the left side of the Property Inspector. You will find the <strong>W</strong> and <strong>H</strong> options there, which serve to adjust the width and height of your ellipse.</p>
<p><img src="/img/animation/cs3st/cs3st_010.gif" alt="Setting the dimensions for the elongated ellipse in the Property Inspector." width="208" height="143" /></p>
<p><span class="step">1.10</span> <strong>Click</strong> on the eye with the Selection tool <strong>(V)</strong> to select it. Press <strong>Ctrl+C</strong> (PC) or <strong>Cmd+C</strong> (Mac) to copy the eye shape. </p>
<p><span class="step">1.12</span> Select <strong>Edit &gt; Paste in Place</strong>.</p>
<p><img src="/img/animation/cs3st/cs3st_011.gif" alt="Pasting a vector drawing in place in Flash CS3." width="306" height="185" /></p>
<p>Now, do <em>not</em> click anywhere or touch anything! Just read the following step.</p>
<p><span class="step">1.13</span> Hold <strong>Shift</strong> on your keyboard and press the <strong>right arrow</strong> key repeadetly until the second eye has been positioned well. If you want to position it more precisely, release Shift and just use the <strong>arrow keys</strong> to move it by 1 pixel at a time.</p>
<p><img src="/img/animation/cs3st/cs3st_012.gif" alt="Placing the second eye of your drawing." width="160" height="160" /></p>
<div class="note">
<p>While using the <strong>Paste in Place</strong> command to paste a <em>vector drawing</em> in place in the <em>same layer</em>, you must either use the Selection tool or the arrow keys to move it away from the original copy, before clicking anywhere else. Why? Simply because if you click on some other object or an empty spot of the working area, the pasted drawing will merge with the original copy. That&#8217;s how vectors in Flash work. Of course, you can always paste in place your drawing into a new layer. But here, with this simple drawing, there is simply no need for that.</p>
</div>
<p><span class="step">1.14</span> <strong>Lock</strong> the <em>eyes</em> layer.</p>
<p><img src="/img/animation/cs3st/cs3st_013.gif" alt="The eyes layer has just been locked to prevent further editing." width="287" height="150" /></p>
<p><span class="step">1.15</span> Make a new layer and call it <em>mouth</em>.</p>
<p><img src="/img/animation/cs3st/cs3st_014.gif" alt="Adding a third layer." width="287" height="150" /></p>
<p><span class="step">1.16</span> Select the Line tool <strong>(N)</strong>. In the Property Inspector, choose <strong>black</strong> as color, <strong>Solid</strong> as line type and a thickness of <strong>3</strong>.</p>
<p><img src="/img/animation/cs3st/cs3st_015.gif" alt="Selecting the options for the Line tool." width="550" height="80" /></p>
<p><span class="step">1.17</span> Draw a horizontal line using the Line tool. Do this by holding <strong>Shift</strong>, clicking and dragging your mouse horizontally.</p>
<p><img src="/img/animation/cs3st/cs3st_016.gif" alt="Drawing a straight horizontal line." width="492" height="150" /></p>
<p>Well, your smiley is done! You will now see how to make it smile! <img src='http://flashexplained.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Save your work before proceeding (<strong>File &gt; Save</strong>)!</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>2. Making a simple shape tween animation</h3>
<p><span class="step">2.1</span> <strong>Right-click</strong> on frame <strong>15</strong> of the <em>mouth</em> layer and select <strong>Insert Keyframe</strong> from the menu that pops up.</p>
<p><img src="/img/animation/cs3st/cs3st_017.gif" width="550" height="190" /></p>
<p>You have just inserted a new keyframe in the <em>mouth</em> layer. This is necessary for any kind of animation in Flash, because a keyframe makes change possible. Whenever you want to animate something, be it movement, color or shape change, you must use a <strong>keyframe</strong>.</p>
<p><img src="/img/animation/cs3st/cs3st_018.gif" alt="The second keyframe, preparing for the shape tween." width="413" height="167" /></p>
<p>&#8230;but you have certainly noticed that only the line representing the smiley&#8217;s mouth is visible on the stage.</p>
<p><img src="/img/animation/cs3st/cs3st_019.gif" alt="The thick line in the mouth layer on Flash stage." width="300" height="220" /></p>
<p>&#8230;and this is perfectly normal! Once you have inserted a new keyframe in the <em>mouth</em> layer, you have made it last longer inside the timeline. All the while the first two layers have remained the same. The contents of the <em>head</em> and <em>eyes</em> layers are visible in the first frame only. Until you make them last longer, they won&#8217;t be visible in other frames.</p>
<p><img src="/img/animation/cs3st/cs3st_020.gif" alt="In Flash, layers can have a different lifespan inside the timeline." width="413" height="165" /></p>
<p><span class="step"><a name="step22" id="step22"></a>2.2</span> To update the other layers, do the following (you don&#8217;t have to unlock them!): <strong>Right-click</strong> on frame 15 of the <em>eyes</em> layer and select <strong>Insert Frame</strong> (not keyframe!) from the  menu. A frame is used when you just want to prolong the duration of a keyframe in the timeline, <em>without any changes</em>.</p>
<p><img src="/img/animation/cs3st/cs3st_021.gif" alt="A frame was added on the second layer to make it last longer." width="550" height="166" /></p>
<p>And now, the <em>eyes</em> layer has the same lifespan as the <em>mouth</em> layer. As you can see, a simple, plain frame is represented by a small rectangle, unlike a keyframe, which has a solid black dot.</p>
<p><img src="/img/animation/cs3st/cs3st_022.gif" alt="Making the layers have the same lifespan within the timeline." width="550" height="166" /></p>
<p><span class="step">2.3</span> Repeat the above step for the <em>head</em> layer.</p>
<p><img src="/img/animation/cs3st/cs3st_023.gif" alt="All layers have the same duration now." width="550" height="166" /></p>
<p>Everything is visible now, in the same time span.</p>
<p><span class="step">2.4</span> Fine! Let me show you how to make the shape tween now. <strong>Click</strong> the second keyframe in the <em>mouth</em> layer to select it.</p>
<p><img src="/img/animation/cs3st/cs3st_024.gif" alt="Selecting the second keyframe in the mouth layer." width="377" height="168" /></p>
<p>This automatically selects every single object in this keyframe. You will see that the mouth (the line) has become highlighted. To unselect it (to be able to change its shape)&#8230;</p>
<p><span class="step">2.5</span> <strong>Click</strong> anywhere outside it using the Selection tool <strong>(V)</strong>, on an empty part of the stage.</p>
<p><img src="/img/animation/cs3st/cs3st_025.gif" alt="Deselecting a drawing." width="400" height="180" /></p>
<p><span class="step">2.6</span> Here is how you can easily make a nice smile:</p>
<ol>
<li>Use the Selection tool <strong>(V)</strong>. Bring it over the line, so that a small curve appears near your cursor.</li>
<li><strong>Click</strong> and start <strong>dragging</strong> your mouse downwards.</li>
<li>Once you are satisfied with your curve, <strong>release</strong> the mouse button. There! The line became a curve!</li>
</ol>
<p><img src="/img/animation/cs3st/cs3st_026.gif" alt="Making a curve out of a straight line in Flash CS3." width="492" height="154" /></p>
<p><span class="step">2.7</span> Now, to create a shape tween, <strong>right-click</strong> anywhere between the two keyframes (or on the first one) and select the <strong>Create Shape Tween</strong> option from the menu.</p>
<p><img src="/img/animation/cs3st/cs3st_027.gif" alt="Creating a shape tween animation in Flash CS3." width="550" height="165" /></p>
<p>If you have done everything as I explained to you up to this point, you should see an arrow between the two keyframes appear, on a light green background.</p>
<p><img src="/img/animation/cs3st/cs3st_028.gif" alt="A successful shape tween shown in a layer." width="412" height="166" /></p>
<div class="note">
<p>If you ever see a dashed, discontinued arrow, it means that Flash hasn&#8217;t been able to make a good shape tween animation. This happens when there are objects other than simple vector shapes in your layer, such as movieclips, buttons, graphic symbols etc. A successful shape tween can only be made with pure vector shapes. No symbols or grouped objects are allowed in the layer where the shape tween takes place.</p>
</div>
<p><span class="step">2.8</span> To see your first shape tween animation, select <strong>Control &gt; Test Movie</strong>. The testing window will appear, with your smiley!</p>
<p><img src="/img/animation/cs3st/cs3st_029.gif" alt="Testing a SWF file in Flash CS3." width="390" height="238" /></p>
<p>You should see an animation like this:</p>

<object	type="application/x-shockwave-flash"
			data="http://www.flashexplained.com/img/animation/media/shape_tween_simple.swf"
			width="160"
			height="160">
	<param name="movie" value="http://www.flashexplained.com/img/animation/media/shape_tween_simple.swf" />
</object>
<p>There! The shape tween has been successfuly made! But after the smile appears, it returns abruptly to the straight line. Why? Because you made it that way! Flash cannot know what&#8217;s going on - it&#8217;s just executing what you told him to do. So, if you want to make that smile return to its initial position more smoothly, you should add another shape tween animation segment. And that&#8217;s really easy to do, because you can just copy the first keyframe, instead of having to re-create it manually.</p>
<p><span class="step">2.9</span> <strong>Right-click</strong> on the <strong>first keyframe</strong> in the <em>mouth</em> layer and select <strong>Copy Frames</strong>.</p>
<p><img src="/img/animation/cs3st/cs3st_030.gif" alt="Copying frames for the shape tween." width="494" height="271" /></p>
<p><span class="step">2.10</span> <strong>Right-click</strong> on frame 30 of the <em>mouth</em> layer and select <strong>Paste Frames</strong>.</p>
<p><img src="/img/animation/cs3st/cs3st_031.gif" alt="Pasting a keyframe for a second shape tween." width="550" height="282" /></p>
<p>Your timeline should look like this:</p>
<p><img src="/img/animation/cs3st/cs3st_032.gif" alt="Adding the second segment of the shape tween animation." width="550" height="167" /></p>
<p><span class="step">2.11</span> Let me show you now a different way of making a shape tween. <strong>Click</strong> anywhere between the second and third keyframes in the current, <em>mouth</em>, layer.</p>
<p><img src="/img/animation/cs3st/cs3st_033.gif" alt="Selecting a frame on the Flash timeline." width="527" height="164" /></p>
<p><span class="step">2.12</span> Jump over to the Property Inspector and find the <strong>Tween</strong> drop-down menu. Select the <strong>Shape</strong> option.</p>
<p><img src="/img/animation/cs3st/cs3st_034.gif" alt="Shape tweening done via the Property Inspector." width="550" height="119" /></p>
<p>The second shape tween should appear in the <em>mouth</em> layer, just as before, represented by a continuous arrow on green background.</p>
<p><img src="/img/animation/cs3st/cs3st_035.gif" alt="Another shape tween has been successfully added to the timeline." width="550" height="165" /></p>
<p><span class="step">2.13</span> What is apparent immediately, is that you should add a frame in both the <em>eyes</em> and <em>head</em> layer, to make them last as long as the <em>mouth</em> layer. You already know how to do it - for a reminder take a look at <a href="#step22">step 2.2</a> again. This is the result you should obtain:</p>
<p><img src="/img/animation/cs3st/cs3st_036.gif" alt="The end result: a nice, looping shape tween animation." width="550" height="165" /></p>
<p><span class="step">2.14</span> Select <strong>Control &gt; Test Movie</strong> to see your smiley change its expression, this time without any abrupt changes in animation.</p>
<p>Save your document and close it. I will show you now how to create a shape morph with the shape tween animation technique and also how to change the color of your drawing.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>3. How to create a morphing effect with shape tweens</h3>
<p><span class="step">3.1</span> Open a new document by selecting <strong>File &gt; New &gt; Flash File (ActionScript 3.0)</strong> and clicking <strong>OK</strong>.</p>
<p><span class="step">3.2</span> Select the Oval tool <strong>(O)</strong>. It should have similar settings as before: <strong>block the outline color</strong> by selecting the No color option for it. Choose blue for the fill color. Also, exactly like in the previous exercice, the Object Drawing option should be turned <strong>off</strong>. Just like you did in <a href="#step13">step 1.3</a> and 1.4.</p>
<p><span class="step">3.3</span> Draw a circle on the stage. I made it a little bit bigger than 100 by 100 pixels.</p>
<p><img src="/img/animation/cs3st/cs3st_037.gif" alt="A vector circle ready to be morphed with shape tweens." width="130" height="130" /></p>
<p><span class="step">3.4</span> Insert a <strong>keyframe</strong> in frame <strong>40</strong> on the first layer.</p>
<p><img src="/img/animation/cs3st/cs3st_038.gif" alt="Placing a new keyframe on the first layer." width="550" height="166" /></p>
<p>Do not make any changes to your circle here. Because, as you have seen in the previous exercice, this last frame will serve to make a nice loop. So that your animation will run smoothly, without any sudden jumps.</p>
<p><img src="/img/animation/cs3st/cs3st_039.gif" alt="The second keyframe has been put in place." width="550" height="166" /></p>
<p><span class="step">3.5</span> <strong>Right-click</strong> between the two keyframes and select the <strong>Create Shape Tween</strong> option.</p>
<p><img src="/img/animation/cs3st/cs3st_040.gif" alt="A shape tween." width="550" height="166" /></p>
<p><span class="step">3.6</span> Next, <strong>insert a keyframe</strong> at frame <strong>20</strong>.</p>
<p><img src="/img/animation/cs3st/cs3st_041.gif" alt="A keyframe inserted in the middle of a shape tween." width="550" height="166" /></p>
<p><span class="step">3.7</span> Fine. Now, use the Selection tool <strong>(V)</strong> to <strong>deselect</strong> the circle by clicking anywhere outside it.</p>
<p><img src="/img/animation/cs3st/cs3st_042.gif" alt="Deselecting a vector circle." width="162" height="128" /></p>
<p><span class="step">3.8</span> Bring the Selection tool <strong>(V)</strong> next to the top of your circle, until a curve appears. Now, press and hold <strong>Ctrl</strong> on your keyboard (I don&#8217;t know if it&#8217;s Ctrl or Cmd on a Mac, sorry, my old one is too slow for Flash CS3 and I haven&#8217;t bought a new one yet <img src='http://flashexplained.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ). Still holding the <strong>Ctrl</strong> key, <strong>click and drag</strong> your mouse downwards.</p>
<p>You should see a pointed deformation start to appear, like a wedge has been driven into the circle.</p>
<p><img src="/img/animation/cs3st/cs3st_043.gif" alt="Making a pointed incision in a vector circle in Flash CS3." width="428" height="128" /></p>
<p><span class="step">3.9</span> Repeat this operation at the remaining three sides of your circle, until you get a flower-like shape.</p>
<p><img src="/img/animation/cs3st/cs3st_044.gif" alt="Modifying the shape of a vector circle in Flash." width="422" height="114" /></p>
<p><span class="step">3.10</span> Test your SWF movie by selecting <strong>Control &gt; Test Movie</strong> or pressing <strong>Ctrl+Enter</strong> (<strong>Cmd+Return</strong> on a Mac). Your animation should resemble this one:</p>

<object	type="application/x-shockwave-flash"
			data="http://www.flashexplained.com/img/animation/media/cs3-shape-morph.swf"
			width="148"
			height="148">
	<param name="movie" value="http://www.flashexplained.com/img/animation/media/cs3-shape-morph.swf" />
</object>
<p>Now, if you want to change the color, just select the shape in the middle keyframe (where it is resembling a flower) and change its fill color in the Tools panel.</p>
<h3>Conclusion</h3>
<p>You have just learned how to make shape tweens. For anything more complicated, for example - a character that moves and speaks, you can&#8217;t rely on Flash to do that for you. Any complex animation requires drawing the changes that happen, frame by frame. Flash cannot replace the human hand, while it is excellent for smooth transitions used in many websites that you see around. If you want to create complex animations, arm yourself with patience. Check out the excellent <a href="http://www.gomediazine.com/tutorials/an-angel-grows-wings-animated-mask-in-flash/">animated wings</a> tutorial to see how it is done.</p>
<p><a href="http://www.flashexplained.com/img/animation/materials/cs3-shape-tween-examples.zip">Download the source file for this lesson</a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashexplained.com/animation/flash-cs3-animation-basics-shape-tween/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Making the ultimate dynamic image gallery in Flash 8</title>
		<link>http://flashexplained.com/actionscript/making-the-ultimate-dynamic-image-gallery-in-flash-8/</link>
		<comments>http://flashexplained.com/actionscript/making-the-ultimate-dynamic-image-gallery-in-flash-8/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 19:30:49 +0000</pubDate>
		<dc:creator>Luka</dc:creator>
		
		<category><![CDATA[ActionScript]]></category>

		<category><![CDATA[gallery]]></category>

		<category><![CDATA[images]]></category>

		<category><![CDATA[jpeg]]></category>

		<category><![CDATA[pictures]]></category>

		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://flashexplained.com/?p=757</guid>
		<description><![CDATA[In this Flash 8 lesson explained in extreme detail, I will teach you how to make a powerful image gallery. Before proceeding, please note that this lesson is made for intermediate and advanced Flash users — the ActionScript code behind this image gallery is nearly 250 lines long. This image gallery will have the following [...]]]></description>
			<content:encoded><![CDATA[<p>In this <strong>Flash 8</strong> lesson explained in extreme detail, I will teach you how to make a powerful image gallery. Before proceeding, please note that <strong>this lesson is made for intermediate and advanced Flash users</strong> — the ActionScript code behind this image gallery is nearly 250 lines long. This image gallery will have the following characteristics:<br />
<span id="more-757"></span></p>
<ul class="learningpoints">
<li>It will be <strong>dynamic</strong>, meaning that the image-related data (the <strong>location of images</strong> — the file paths, and the <strong>descriptions</strong>) will be loaded from an external <strong>XML</strong> file.</li>
<li>The dynamic nature of the gallery will allow you to <strong>update it just by changing the external XML file</strong> and re-upload it to the server along with the new images, without having to modify the SWF movie at all. Once the SWF is finished and ready, you don&#8217;t have to touch it any more.</li>
<li>The gallery can feature an <strong>unlimited number of images</strong>.</li>
<li>The image gallery will feature a <strong>menu</strong> which will enable the users to select a particular section and have the related <strong>thumbnails</strong> displayed.</li>
<li><strong>The menu will be created dynamically</strong> (on the fly) via ActionScript, making it <strong>expandable</strong>. It can store as many sections as you like.</li>
<li>The menu will be <strong>scrollable</strong>, with a nice <strong>easing effect</strong> added to it.</li>
<li>Every thumbnail section and every individual image will have its own <strong>textual description</strong>.</li>
<li>Every thumbnail will have its own <strong>preloader</strong>, as well as every image.</li>
<li>Once a user clicks on a thumbnail, the <strong>external JPEG image</strong> will be loaded (a percentage preloader will be used to show the downloading progress), and once it is fully loaded, it will show up with an <strong>alpha fade-in effect</strong>.</li>
<li>By clicking on the loaded image, the user will go back to the thumbnail section.</li>
<li>The image gallery is <strong>extremely small in filesize</strong> (the SWF itself weighs less than 30 KB), because all the JPEG images will be stored externally.</li>
<li>Last but not least, <strong>the gallery works in all major browsers</strong>.</li>
</ul>
<p><a href="http://www.flashexplained.com/img/dynamic-image-gallery-example.html">View the image gallery in action</a>. You can also click on the screenshot below to see it.</p>
<p><a href="http://www.flashexplained.com/img/dynamic-image-gallery-example.html"><img src="http://www.flashexplained.com/img/actionscript/ig/image-gallery-screenshot.jpg" alt="An example of the image gallery. Click it to see it in action!" width="400" height="236" /></a></p>
<h3>Overview</h3>
<p>Before starting to buid your image gallery, there is a little planning to be done, because this is in fact a small application. Let&#8217;s see the elements that make up this gallery:</p>
<h4 style="font-weight:bold;">I. The elements of the SWF movie</h4>
<ol id="galleryelements">
<li><strong>The gallery menu.</strong> This is the interface which will enable the user to browse through the galleries. It will be made of buttons dynamically pulled out from the Library and then nested inside an empty movie clip. The menu will have <strong>two buttons</strong>, which will make possible for the user to <strong>scroll through the menu</strong>, up and down. A <strong>mask</strong> will be made inside this menu, to limit its visible area. You must do this because if you are going to have many galleries (let&#8217;s say 40, 50 or even more), their respective buttons cannot be all over your movie — that would look bad.</li>
<li><strong>The thumbnail MovieClip.</strong> This is a movieclip symbol stored inside the Library, into which a single thumbnail (small image) will be loaded. It contains:
<ul>
<li>a white background, just to make it nicer, and to be able to add a drop shadow effect to it later,</li>
<li>an empty MovieClip inside which the external <strong>JPEG thumbnail</strong> will be loaded and</li>
<li>a dynamic text field which will serve to show the preloader (a simple percentage preloader).</li>
</ul>
</li>
<li><strong>The big image holder MovieClip.</strong> This MovieClip symbol will also be stored in the Library and will be pulled out of it dynamically, via ActionScript. It is nearly the same as the thumbnail MovieClip, except bigger in size. It contains the same three elements as the one above:
<ul>
<li>a white background,</li>
<li>an empty MovieClip inside which the <strong>big external JPEG image</strong> will be loaded and</li>
<li>a dynamic text field for the preloader.</li>
</ul>
</li>
<li><strong>A placeholder for thumbnails and big images.</strong> This is an empty MovieClip, placed directly on the stage, which will have two empty MovieClips created inside it at runtime (meaning while your SWF is running), like this:
<ul>
<li>When the user clicks on a gallery in the menu, an empty MovieClip will be created inside the placeholder. This MovieClip is going to receive several copies of the <strong>thumbnail MovieClip</strong> attached to it, depending on the number of images in the gallery that the user has selected.</li>
<li>When  the user clicks on a thumbnail, a new empty MovieClip will be created inside the placeholder, which will have the <strong>big image holder MovieClip</strong> attached to it. The preloading of the big JPEG image will start, and when it reaches 100%, the image will fade in nicely and hide the thumbnails. When the user click on the image, it will disappear and the thumbnails will appear again.</li>
</ul>
</li>
<li><strong>A dynamic text field.</strong> This is where the <strong>descriptions</strong> for all the galleries and images will appear.</li>
<li><strong>Your website logo.</strong> This is just a graphic element, which will appear above the gallery.</li>
</ol>
<h4 style="font-weight:bold;">II. The XML file</h4>
<p>The XML file will store all the data related to the images:</p>
<ul>
<li><strong>The name of each gallery.</strong> This name will appear as <strong>the label on each gallery button</strong> in the menu. Also, this same name is <strong>the name of the folder</strong> (directory, file folder, as it is also called) inside which that particular gallery will be stored on your web server.</li>
<li><strong>The description of each gallery.</strong> This is the text that will appear in the dynamic text field when the user clicks on a gallery button and the thumbnails for it are shown.</li>
<li><strong>The description of each image.</strong> This is the text that will show up in the same dynamic field mentioned above when a big image has been loaded.</li>
</ul>
<h4 style="font-weight:bold;">III. The images and the thumbnails</h4>
<p>All the images will have to be stored according to an <strong>exact hierarchy </strong>and <strong>precise naming rules</strong>. Each gallery will be placed in a folder which will have <strong>the same name as the title of the gallery as it appears in the XML file</strong>. Inside each folder, the images will have to be named as <strong><em>1.jpg</em></strong>, <strong><em>2.jpg</em></strong>, <strong><em>3.jpg</em></strong> and so on. Furthermore, each gallery folder will have a subfolder inside it, called <strong><em>thumbs</em></strong>, where the thumbnails for the gallery will be stored. The thumbnails will have the same file names as their bigger counterparts (<em>1.jpg</em>, <em>2.jpg</em>, etc). All the galleries will be placed in a single folder, named <strong><em>gallery</em></strong>.</p>
<p>You have to abide by this naming/folder hierarchy system if you want your dynamic image gallery to function properly. Once you want to insert new images inside the gallery, the only thing you will have to do is to update the XML file, create new folders according to the gallery names inside this XML file, and place the images and their respective thumbs inside them. You will then upload the new images and the XML file to your web server and they will automatically appear inside the menu.</p>
<p>Sounds great — a fully automated image gallery system. I will start by showing you how to create the SWF movie, after that you will download the XML file and modify it according to your needs, make all the necessary folders and place the images and thumbnails inside them, and last but not least (in fact, the most important) you will create the ActionScript code that runs the whole thing. Let&#8217;s get started!</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>1. Setting up your document</h3>
<p><span class="step">1.1</span> Open a new Flash document <strong>(File &gt; New &gt; Flash Document)</strong>.</p>
<p><span class="step">1.2</span> Select <strong> Modify &gt; Document</strong>.  Set the dimensions of your Flash movie to <strong>760 by 540 pixels</strong> and set the speed (frame rate) to <strong>30 fps</strong>. Click <strong>OK</strong>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_001.gif" alt="Modifying the document's dimensions and speed." width="210" height="195" /></p>
<p><span class="step">1.3</span> <strong>Save your document</strong> in a separate folder — <strong>make a new folder just for this lesson</strong>. A lot of files are going to be needed for the creation of the image gallery, so it is a wise thing to keep them all in one place, instead of putting them together with any other Flash files that you may be working on.</p>
<div class="note">
<p>Just a little bit about the dimensions of your document here: The document&#8217;s size (width and height) is just a suggestion, like all of the dimensions and element positioning (menu, main images, thumbnails, etc) involved in this lesson. I recommend that you use my dimensions until the end of the tutorial, so that you can more easily follow my instructions. Later, once that you grasp the way the gallery works, you can change the dimensions and the general layout of the gallery to suit your needs.</p>
</div>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>2. Creating the gallery menu</h3>
<p><span class="step">2.1</span> Call the first layer in your document <em>gallery menu</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_002.gif" alt="Changing the label of the first layer." width="215" height="46" /></p>
<p><span class="step">2.2</span> Select <strong>Insert &gt; New Symbol</strong>. In the window that appears, do the following:</p>
<ul>
<li>Select <strong>Movie clip</strong> as type,</li>
<li>enter <em>empty movie clip</em> as the <strong>name</strong> of the new symbol</li>
<li>click <strong>OK</strong>.</li>
</ul>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_003.gif" alt="Creating a new movie clip symbol." width="300" height="101" /></p>
<p><span class="step">2.3</span> You will now find yourself working <em><strong>inside</strong></em> the new MovieClip symbol. Since you need an empty MovieClip, don&#8217;t draw anything here, just <strong>click</strong> the <strong>Scene 1</strong> link above the timeline.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_004.gif" alt="Returning to the main scene." width="180" height="47" /></p>
<p>Your newly made empty movie clip symbol is now stored inside the Library. You can access the Library by selecting <strong>Window &gt; Library</strong>. Keep the Library window open, because you are going to need it frequently, especially to place instances of the <em>empty movie clip</em> symbol  on the stage at various points during this lesson.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_005.gif" alt="The Library with the first movie clip symbol that was made, stored inside it." width="208" height="245" /></p>
<p>Now you are going to create the main MovieClip for the image gallery menu. The first thing that you&#8217;re going to make is a mask for the menu buttons.</p>
<p><span class="step">2.4</span> Select the Rectangle tool <strong>(R)</strong>. In the <strong>Colors</strong> section of the <strong>Tools</strong> panel, <strong>block the stroke color</strong>, because you won&#8217;t need it. Do this by selecting the stroke color first — click on the <strong>little pencil icon</strong> to do it (see 1 in the image below). Next, click on the <strong>No color</strong> button (see 2 in the image below). You can choose any fill color that you like.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/cs/cs_003.gif" alt="Blocking the Outline color." width="70" height="111" /></p>
<p>Also, turn off the <strong>Object Drawing</strong> and <strong>Snap to Objects</strong> options (both icons are shown below — you can find them at the bottom of the Tools panel while the Rectangle tool is still selected).</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_006.gif" alt="Turning off the additional options for the Rectangle tool." width="64" height="47" /></p>
<p><span class="step">2.5</span> <strong>Click and start dragging</strong> your mouse to draw a rectangle. Make it any size you want.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_007.gif" alt="A simple rectangle." width="132" height="59" /></p>
<p><span class="step">2.6</span> <strong>Select the rectangle</strong> by clicking on it with the Selection tool <strong>(V)</strong>. Go to the left side of the Property inspector and find the width and height options (W and H, respectively) for the shape. Enter <strong>200 pixels</strong> for the width and <strong>390 pixels</strong> for height.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_008.gif" alt="Resizing the rectangle numerically." width="93" height="49" /></p>
<p><span class="step">2.7</span> While the rectangle is still selected, select <strong>Modify &gt; Convert to Symbol</strong>. Make the following choices:</p>
<ul>
<li>Select <strong>Movie clip</strong> as type of symbol.</li>
<li><strong>Name</strong> the symbol <em>menu holder</em>.</li>
<li>Select the <strong>upper left</strong> registration point for the new symbol (see image below).</li>
<li>Click <strong>OK</strong>.</li>
</ul>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_009.gif" alt="The convert to symbol window." width="408" height="137" /></p>
<p>This last point is very important. You will do the same thing for every single symbol that you are going to create in this lesson. This is done in order to facilitate the positioning and resizing of elements on the stage via ActionScript (dynamically) later.</p>
<p>If you had made some other choice for the registration point, you would have had to know and use the width and height for each symbol to be able to position them properly. By selecting the upper left corner for the registration point, the positioning is pretty straightforward and there is no fuss at all.</p>
<p><span class="step">2.8</span> <strong>Double-click</strong> on the newly made <em>menu holder</em> MovieClip on the stage (using the Selection tool) to enter inside it. If you take a look above the stage, you&#8217;ll see that Flash nicely informs you that you are working inside the <em>menu holder</em> MovieClip now.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_010.gif" alt="Inside the new movie clip." width="191" height="28" /></p>
<p><span class="step">2.9</span> The rectangle vector shape inside the movie clip should be selected by default. If this isn&#8217;t the case, click on it with the Selection tool <strong>(V)</strong> to select it.</p>
<p><span class="step">2.10</span> Select <strong>Modify &gt; Convert to Symbol</strong>. Once again, select <strong>Movie clip</strong> as type, choose the <strong>upper left corner</strong> for the registration point, call it <em>menu mask</em> and click <strong>OK</strong>.</p>
<p><span class="step">2.11</span> The new MovieClip will be selected by default immediately after you have clicked the OK button in the previous step. Now go to the Property inspector and give an <strong>Instance name</strong> to this MovieClip: call it <em>galleryMask_mc</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_011.gif" alt="An instance name was assigned to the rectangular mask movie clip." width="164" height="51" /></p>
<p><span class="step">2.12</span> <strong>Lock</strong> the current layer and call it <em>mask</em>. Create a <strong>new layer</strong> and call it <em>placeholder</em>. Remember that all of this is done inside the <em>menu holder</em> movie clip — you are still inside it.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_012.gif" alt="Making a new layer inside the menu holder movie clip." width="254" height="94" /></p>
<p><span class="step">2.13</span> Go to the Library (<strong>Window &gt; Library</strong>), <strong>click and drag</strong> an instance of the <em>empty movie clip</em> symbol onto the stage, inside the <em>placeholder</em> layer that you created a moment ago.</p>
<p>This movie clip has no graphical content, and so it is represented by its registration point only. This is the small circle with the cross inside it that showed up once you dragged the movie clip from the Library onto the stage. If ever in doubt which movie clip you are tinkering with, just look at the Property inspector while it is selected. You can see this in the screenshot below.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_013.gif" alt="The empty movie clip on the stage." width="168" height="60" /></p>
<p><span class="step">2.14</span> With the instance of the <em>empty movie clip</em> on the stage <strong>still selected</strong>, open the Align panel by selecting <strong>Window &gt; Align</strong>. Do this:</p>
<ul>
<li>Turn <strong>on</strong> the <strong>Align/Distribute to Stage</strong> button (see 1 below).</li>
<li>Click the <strong>Align left edge</strong> button (see 2 below).</li>
<li>Click the <strong>Align upper edge</strong> button (see 3 below).</li>
</ul>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_014.gif" alt="Using the Align panel for exact positioning of the placeholder movie clip." width="206" height="130" /></p>
<p>The empty movie clip will now be perfectly aligned with the <em>menu holder</em> movie clip&#8217;s registration point, as you can see.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_015.gif" alt="The empty movie clip is aligned with the host movie clip's registration point." width="204" height="135" /></p>
<p>This is just what you need, since this empty movie clip which you have just positioned will be the placeholder for all the menu buttons. That being said, you must prepare it properly to be able to load the buttons inside it later. Follow the next step to see how :-).</p>
<p><span class="step">2.15</span> The empty movie clip must still be selected. Go to the Property inspector and enter the <strong>Instance name</strong> for this movie clip: call it <em>buttonsHolder_mc</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_016.gif" alt="The Instance name of the gallery buttons placeholder movie clip." width="164" height="51" /></p>
<p><span class="step">2.16</span> <strong>Lock</strong> the <em>placeholder</em> layer and <strong>drag it under</strong> the <em>mask</em> layer.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_017.gif" alt="Switching the placement of the layers." width="211" height="64" /></p>
<p><span class="step">2.17</span> <strong>Right-click</strong> on the <em>mask</em> layer and select the <strong>Mask</strong> option from the menu that pops up (also called the contextual menu). The <em>mask</em> layer will instantly turn into a mask, masking the <em>placeholder</em> layer beneath it.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_018.gif" alt="The mask layer masking the layer below it." width="214" height="65" /></p>
<p><span class="step">2.18</span> <strong>Click</strong> on the <strong>Scene 1</strong> link above the layers to go back to the main timeline.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_019.gif" alt="Exiting the movie clip symbol timeline." width="194" height="39" /></p>
<p><span class="step">2.19</span> The <em>menu holder</em> movie clip will be selected by default, which you can see in the Property inspector. Go right there and give at an <strong>Instance name</strong>: call it <em>galleryMenu_mc</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_020.gif" alt="The Instance name of the movie clip which will hold the galleries menu." width="315" height="52" /></p>
<p>You have probably noticed that this movie clip is almost invisible — it is represented by its registration point (see1 in the screenshot below) and central point (see 2) only. This is because the mask inside it isn&#8217;t visible, which is normal.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_021.gif" alt="The registration and central point of a movie clip." width="134" height="213" /></p>
<p>Fine — the menu is pretty much ready now, it can receive the buttons. But you have to actually make a button that is going to be pulled out of the Library at runtime (while the Flash SWF movie is running, that is) and placed inside the menu, as many times as there will be sections inside your gallery.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>3. Creating the menu button and setting it up for use at runtime</h3>
<p><span class="step">3.1</span> You should be on the main timeline now. <strong>Lock</strong> the <em>gallery menu</em> layer and <strong>create a new layer</strong>. You don&#8217;t have to gave any specific name to this new layer at all, because it will serve as a temporary layer only, to create the menu button specimen, after which you will remove it.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_022.gif" alt="A temporary layer was just created." width="212" height="64" /></p>
<p><span class="step">3.2</span> Select the Rectangle tool <strong>(R)</strong>. The settings for this tool should have remained unchanged from the previous use of it: the stroke color (outline) should be blocked, the Object Drawing and Snap to Object options turned off.</p>
<p>You can select any color you like for the fill. I chose a nice hue of blue, #00789F. Now <strong>draw a 200 by 20 pixel rectangle</strong> anywhere on the stage. You can draw any rectangle at first and then set these exact dimensions in the Property inspector after.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_023.gif" alt="A precisely drawn elongated rectangle on the stage." width="200" height="89" /></p>
<p>These exact dimensions are important, especially the width, because the mask that you made in the previous section is also 200 pixels wide. They have to match (or the mask can eventually be a little wider than the button) if you want your menu to look professionally designed — clean and sharp.</p>
<p><span class="step">3.3</span> <strong>Select</strong> the rectangle and choose <strong>Modify &gt; Convert to Symbol</strong>. Select <strong>Movie clip</strong> as type, call it <em>gallery section button</em> and click <strong>OK</strong>.</p>
<p><strong>A small note here:</strong> the movie clip that you just made is called <em>gallery section <strong>button</strong></em>, although it is a movie clip. Don&#8217;t let that confuse you. I chose to give it such a name because it will in fact serve as a button. Why a movie clip then? Because a movie clip symbol is far more versatile and usable than a button — its possibilities of creation and manipulation are far greater than those of a button symbol. And even if in this particular project a button symbol would maybe serve as well as a movie clip for all purposes, I have just acquired a habit of making movie clips instead of buttons :-).</p>
<p><span class="step">3.4</span> Choose the Selection tool <strong>(V)</strong> and <strong>double-click</strong> on the <em>gallery section button</em> movie clip on the stage, to enter inside it.</p>
<p><span class="step">3.5</span> Call the movie clip&#8217;s first layer <em>bkg</em> (because this will be the button&#8217;s background).</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_024.gif" alt="The first layer inside the button movie clip." width="294" height="76" /></p>
<p><span class="step">3.6</span> <strong>Right-click</strong> on <strong>frame 2</strong> in this layer and select <strong>Insert Keyframe</strong> from the contextual menu.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_025.gif" alt="Inserting a new keyframe into a layer." width="371" height="132" /></p>
<p><span class="step">3.7</span> In the newly made keyframe, the rectangle will automatically be selected. Just change its color to some other of your choice — I used #7C3F52. Do this by <strong>clicking on the fill color square</strong> in the <strong>Colors</strong> section of the <strong>Tools</strong> panel, all the while the rectangle is selected.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_026.gif" alt="Changing the fill color for a shape." width="125" height="111" /></p>
<p>Why was this done? Because you need to have a rollover effect for your menu to make it more user-friendly and easier to navigate. So that&#8217;s why you have to have two keyframes, with the same rectangle inside, but differently colored. You will enable this rollover visual change via ActionScript later.</p>
<p><span class="step">3.8</span> <strong>Lock</strong> the <em>bkg</em> layer and <strong>make a new layer</strong> above it and call it <em>label</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_027.gif" alt="A second layer, for the button's label, has just been made." width="218" height="64" /></p>
<p>This new layer will automatically have the same timeline duration as the one below it (2 frames long), which is fine, because the label (the text that will appear on the button) must be visible in both states — the initial one as well as the rollover.</p>
<p><span class="step">3.9</span> Select the Text tool <strong>(T)</strong>. In the Property inspector, do the following choices and tweaks:</p>
<ol>
<li>Select <strong>Dynamic Text</strong>.</li>
<li>Select a font that you like.</li>
<li>Select <strong>14</strong> as font size, or bigger if necessary. The important thing is that the text field&#8217;s height should approximately match the height of the rectangular background. You&#8217;ll see that once you make the actual text field, so you may need to re-adjust this value as necessary.</li>
<li>Select <strong>white</strong> for the text color — this choice will make the button labels visible in both states — initial and rollover.</li>
<li>Select the <strong>left</strong> alignment for the text field. It looks well, unlike the central alignment which would look awkward on this kind of menu and would also make things more difficult to read.</li>
<li>Select Anti-alias for <strong>readability</strong> in the rendering menu.</li>
<li>Make sure that the <strong>Selectable</strong> option stays turned <strong>off</strong>. If you turn it on, your menu buttons will suck royally and possibly won&#8217;t be clickable at all.</li>
<li>Make sure that <strong>Single line</strong> is selected. Multiline doesn&#8217;t make any sense for a text field inside a menu button, right?</li>
</ol>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_028.gif" alt="Selecting the options for the Text tool before using it." width="494" height="84" /></p>
<p><span class="step">3.10</span> <strong>Click and drag</strong> on the stage with the Text tool to create a dynamic text field. Create it over the button&#8217;s backround rectangle, so that the dimensions of the two approximately match. Hit <strong>Esc</strong> when finished and you&#8217;ll exit the text field and see a blue border appear around it.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_029.gif" alt="Creating a dynamic text field in Flash." width="207" height="77" /></p>
<p><span class="step">3.11</span> Now go over to the Property inspector and type in the <strong>Instance name</strong> for your <strong>dynamic text field</strong>: call it <em>sectionTitle_txt</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_030.gif" alt="The Instance name of the dynamic text field." width="149" height="51" /></p>
<p><span class="step">3.12</span> On the right side of the same panel, click the <strong>Embed</strong> button.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_030a.gif" alt="The emebed option for dynamic text fields." width="77" height="23" /></p>
<p>The <strong>Character Embedding</strong> window will open up. Select multiple character groups by <strong>Shift-clicking</strong> them: choose the <strong>Uppercase</strong>, <strong>Lowercase</strong>, <strong>Numerals</strong> and <strong>Punctuation</strong> options. Click <strong>OK</strong>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_030b.gif" alt="Embedding characters in a dynamic textfield." width="180" height="240" /></p>
<p>Embedding the characters in the dynamic text field will ensure the continuity of design accross different platforms and operating systems. No matter if a user has your menu font of choice installed or not, he/she will see the exact same font, thanks to the embed option.</p>
<p>The four groups of characters that you have embedded in your dynamic text field will cover 99% percent of possible gallery names. Of course, you may choose to add any additional special and exotic characters if you wish so. Bear in mind that the embedding of these characters will add about 20-30 KB to your final SWF file.</p>
<p><span class="step">3.13</span> <strong>Lock</strong> the <em>label</em> layer. Make a <strong>new layer</strong> and call it <em>actions</em>. You can lock this layer also, since ActionScript code can be placed inside it while it is locked too.</p>
<p><strong>Click</strong> on the <em>actions</em> layer&#8217;s <strong>first frame</strong> to select it.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_031.gif" alt="Adding the layer for ActionScript inside the gallery section button movie clip." width="221" height="83" /></p>
<p><span class="step">3.14</span> Open up the Actions panel by selecting <strong>Window &gt; Actions</strong>. Enter the following code inside it:</p>
<p class="ascode">stop();</p>
<p>This simple action prevents the playhead from going forward, as any animation in Flash naturally does. You will create programming code later that will move the playhead to the next frame while the user is over a particular button with his/her mouse, to create the rollover effect I told you about just a few steps before.</p>
<p><span class="step">3.15</span> Fine! The button is finished now! Click on the <strong>Scene 1</strong> link to go back to the main scene.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_032.gif" alt="Going back to the root timeline." width="238" height="38" /></p>
<p><span class="step">3.16</span> <strong>Delete</strong> the temporary layer inside which the button was created (<em>Layer 2</em>). This will delete the button from the stage too. You should have only the <em>gallery menu</em> layer on the main scene now. However, the <em>gallery section button</em> is stored inside the Library.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_033.gif" alt="The temporary layer was removed." width="211" height="46" /></p>
<p><span class="step">3.17</span> Go to the Library <strong>(Window &gt; Library)</strong>. <strong>Right-click</strong> on the <em>gallery section button</em> movie clip inside the Library and select  the <strong>Linkage</strong> option from the contextual menu.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_034.gif" alt="Selecting the Linkage option for a movie clip symbol inside the Library." width="222" height="260" /></p>
<p><span class="step">3.18</span> In the <strong>Linkage Properties</strong> window that appears, <strong>check</strong> the <strong>Export for ActionScript</strong> option. The <strong>Export in first frame</strong> option will automatically become checked too. You can leave it like that, it&#8217;s fine.</p>
<p>As for the <strong>Identifier</strong> option, you can also leave it at the default value, which is the name of the movie clip symbol itself — <em>gallery section button</em> in this case. Click <strong>OK</strong>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_035.gif" alt="asd" width="300" height="149" /></p>
<p>The Identifier name will serve to pull the button dynamically from the Library and place it inside the menu that you have created on the previous page. This is very, very practical, because you will change just the images and the XML file once the SWF is finished.</p>
<p>This makes possible for dynamic menu creation, also thanks to the dynamic text field inside the button — each button will have its label match the section of the gallery it represents. Why create every single button manually, re-open the FLA, re-export it as a SWF when you can solve this with ActionScript and have the menu created in a split second!</p>
<p>You will now make the remaining elements, so that your photo galleries menu is complete. Namely, you will make two buttons for scrolling through the menu and a title that tells the users what&#8217;s the menu about. Before that, you&#8217;ll just position the <em>galleryMenu_mc</em> movie clip.</p>
<p><strong>Save your document</strong> before proceeding to the next section of this lesson, where the creation of menu navigation buttons is explained.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>4. Making the menu navigation buttons</h3>
<p><span class="step">4.1</span> You have to select the <em>galleryMenu_mc</em> movie clip to be able to position it. Since this movie clip is almost invisible, it isn&#8217;t as easily selectable as any othe movie clip might be. Here&#8217;s how you do it (follow the pictures below the list):</p>
<ol>
<li><strong> Unlock</strong> the <em>gallery menu</em> layer.</li>
<li><strong>Click</strong> on the layer&#8217;s <strong>first frame</strong> to select it.</li>
<li>The Property inspector tells you that a frame has been selected.</li>
<li>Once you select a frame, all the content inside it is selected too. Because of this, the movie clip you are looking for will appear. <strong>Click</strong> on the movie clip <strong>once</strong> with the Selection tool <strong>(V)</strong> to select it (you must click on its registration point since no other content of this symbol is visible).</li>
<li>The movie clip is selected, which is indicated in the Property inspector.</li>
</ol>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_036.gif" alt="The procedure of selecting a movie clip symbol with low visibility." width="343" height="159" /></p>
<p><span class="step">4.2</span> Enter the following values for the movie clip&#8217;s coordinates (inside the Property inspector): <strong>10</strong> for <strong>X</strong> and <strong>99</strong> for <strong>Y</strong>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_037.gif" alt="The movie clip's position as seen in the Property inspector." width="64" height="50" /></p>
<p>Fine. Let me show you now how to create a couple of sleek navigational buttons.</p>
<p><span class="step">4.3</span> First, make a line that will separate the menu buttons from the menu navigation. Select the Line tool <strong>(N)</strong>. In the Property inspector, select <strong>black</strong> for the line color and <strong>hairline</strong> for the line thickness.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_038.gif" alt="Defining the type of line for drawing in Flash." width="296" height="28" /></p>
<p><span class="step">4.4</span> Hold down <strong>Shift</strong> on your keyboard, <strong>click</strong> with your mouse somewhere above the <em>galleryMenu_mc</em> movie clip and draw a horizontal line. Holding Shift will enable you to make a perfect horizontal line. You can select the line later and position it via the Property inspector. Also, make it as wide as the menu, to have a more coherent and professional design.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_039.gif" alt="Drawing a very thin line and adjusting its dimensions." width="200" height="129" /></p>
<p><span class="step">4.5</span> Select the Rectangle tool <strong>(R)</strong>. Go to the <strong>Options</strong> part of the Tools panel and make sure that both the <strong>Object Drawing</strong> and <strong>Snap to Objects</strong> options are <strong>turned off</strong> (see 1 and 2 on the screenshot below).</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_040.gif" alt="Tweaking the options for the Rectangle tool in Flash." width="82" height="72" /></p>
<p>Next, click on the <strong>Set Corner Radius</strong> button (see 3 above). In the Rectangle settings window that will show up, enter <strong>7</strong> as the corner radius value, then click <strong>OK</strong>. This will enable you to draw rectangles with smooth, rounded corners.</p>
<p><span class="step">4.6</span> Go over to the Color Mixer panel (to access it, select <strong>Window &gt; Color Mixer</strong>, although it is probably open already, by default). Block the stroke color and make a nice bluish-turquoise linear gradient for the fill color, like this:</p>
<ol>
<li>Click the small <strong>pencil icon</strong>.</li>
<li>Click the little square  next to it and select the <strong>No Color</strong> option (the white square with the  red diagonal line).</li>
<li>Click the <strong>paint bucket icon</strong> to select the fill color.</li>
<li>Select the <strong>Linear</strong> option in the Type menu.</li>
<li>Click on the left color (the small square) in the gradient stripe to select it.</li>
<li>Enter the <strong>hexadecimal code</strong> for this color: I chose #00789F.</li>
<li>Repeat the two previous steps for the <strong>right-side color</strong>: select it and enter #81E6FE as its code.</li>
</ol>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_041.gif" alt="Creating a linear gradient for the fill color in the Color Mixer panel in Flash." width="223" height="202" /></p>
<p><span class="step">4.7</span> Hold <strong>Shift</strong> (to draw a square and not a rectangle), <strong>click</strong> on the stage and draw a <strong>29 by 29 pixel</strong> square.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_042.gif" alt="A gradient-filled square with rounded corners." width="133" height="50" /></p>
<p>This square looks nice, but since it is a navigational element, I think that it would look much better if the gradient spreads from top to bottom instead from left to right. Follow the next step to see how to do this simple modification.</p>
<p><span class="step">4.8</span> Select the Gradient Transform Tool <strong>(F)</strong>. Turn <strong>on</strong> the <strong>Snap to Objects</strong> option in the Tools panel. Now, rotate the graident like this:</p>
<ol>
<li><strong>Click</strong> on the <strong>square</strong> that you drew in the previous step to select it. The controls for gradient modification will appear.</li>
<li><strong>Click</strong> the circle with the small black arrow in it and <strong>start dragging</strong> your mouse <strong>counter-clockwise</strong>.</li>
<li>Once you reach a <strong>90-degree turn</strong>, release your mouse button. There!</li>
</ol>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_043.gif" alt="Rotating a linear gradient fill in Flash." width="359" height="54" /></p>
<p><span class="step">4.9</span> Select the Selection tool <strong>(V)</strong> and turn <strong>off</strong> the Snap to Objects option. <strong>Click</strong> on the gradient-filled square to select it.</p>
<p><span class="step">4.10</span> Select <strong>Modify &gt; Convert to Symbol</strong> to make a symbol out of this square. This time, select <strong>Button</strong> as type (<strong>not</strong> Movie clip), call it <em>scroll menu down</em> and click <strong>OK</strong>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_044.gif" alt="Creating a button symbol." width="300" height="101" /></p>
<p><span class="step">4.11</span> <strong>Double-click</strong> on the newly made <em>scroll menu down</em> button on the stage to enter inside it. Once inside the button&#8217;s timeline, <strong>lock</strong> the first layer and call it <em>bkg</em>. <strong>Make a new layer</strong> above it and call it <em>arrow</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_045.gif" alt="Adding a layer inside the button symbol." width="322" height="96" /></p>
<p><span class="step">4.12</span> <strong>Draw a white arrow</strong> that is pointing downwards, inside  the <em>arrow</em> layer.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_046.gif" alt="The button with the arrow added to it." width="33" height="33" /></p>
<p>You can do it easily like this (see the sequence of images below):</p>
<ol>
<li>Using the Rectangle tool <strong>(R)</strong>, draw a <strong>square</strong> (I made a 19 by 19 pixel square).</li>
<li>Choose the Selection tool <strong>(V)</strong> and bring your cursor near the square&#8217;s <strong>upper right corner</strong>. A small right angle will appear near your cursor.</li>
<li><strong>Click and drag</strong> your mouse   toward the <strong>square&#8217;s center</strong>. Once your cursor is near the center, a circle will appear, indicating that it is ready to snap into place.</li>
<li><strong>Release</strong> your mouse button and you&#8217;ve got yourself a nice triangle.</li>
<li>Select the Free Transform Tool <strong>(Q)</strong> and <strong>rotate </strong>the triangle by <strong>45 degrees counter-clockwise</strong>. There! You have the arrow for your button now.</li>
</ol>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_047.gif" alt="Creating a triangle in Flash." width="246" height="133" /></p>
<p>Note that I have used the blue color just to show you how it&#8217;s done. You can use any color you want while making the triangle — once you move it over the button&#8217;s background, change its color to white.</p>
<p><span class="step">4.13</span> Add a <strong>third layer</strong> inside the button and call it <em>label</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_048.gif" alt="The layer for the label was just added." width="245" height="85" /></p>
<p><span class="step">4.14</span> Select the Text tool <strong>(T)</strong> and change the type of text field to <strong>Static Text</strong> in the Property inspector. Click somewhere over the button&#8217;s background area and type <em>DOWN</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_049.gif" alt="A text label was added to the menu button." width="402" height="96" /></p>
<p>As you can see above, I chose a <a href="http://flashexplained.com/resources/wpdir-sites/cat-5/pixel-fonts/free-pixel-and-bitmap-fonts/">pixel font</a> for the label (it looks cool). If you do the same, be sure to set the rendering option to <strong>Bitmap text</strong>, which is the best for pixel and bitmap fonts. Also, most pixel fonts have to be typed with a font size of <strong>8</strong>, to render properly and sharply.</p>
<p><span class="step">4.15</span> Click the <strong>Scene 1</strong> link to go back to the main scene, because the button is complete now.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_050.gif" alt="Exiting a button symbol." width="183" height="38" /></p>
<p><span class="step">4.16</span> Assign an <strong>Instance name</strong> to this button because you&#8217;ll need to manipulate it via Actioncript later. Name it <em>menuDown_btn</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_051.gif" alt="The Instance name of a menu button." width="164" height="51" /></p>
<p>Place this button above the thin line, on the right.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_052.gif" alt="The first menu navigation button in its final position." width="222" height="42" /></p>
<p>Now you need to make the second button, for scrolling the menu upwards. This one is going to be easy to do, because you&#8217;ll just clone the existing button and make a few modifications.</p>
<p><span class="step">4.17</span> Go to the <strong>Library</strong>. Find the <em>scroll menu down</em> button symbol, <strong>right-click</strong> on it and select <strong>Duplicate</strong> from the contextual menu.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_053.gif" alt="Duplicating a symbol in the Library." width="169" height="157" /></p>
<p>In the Duplicate Symbol dialog that appears, enter <em>scroll menu up</em> as the new symbol&#8217;s name, leave the other options as they are and click <strong>OK</strong>.</p>
<p><span class="step">4.18</span> <strong>Double-click</strong> on the newly made <em>scroll menu up</em> button symbol inside the Library to acces its timeline. Once inside, <strong>unlock</strong> the <em>arrow</em> layer.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_054.gif" alt="Unlocking the layer with the arrow icon." width="258" height="88" /></p>
<p><span class="step">4.19</span> Select the triangular arrow shape in this layer. Now select <strong>Modify &gt; Transform &gt; Flip Vertical</strong>. The arrow will now point upwards, thanks to the flipping you did. Also, Change the static text from <em>DOWN</em> to <em>UP</em>. Remember, these changes will <strong>not</strong> affect the first button you made, because the duplicated <em> scroll menu up</em> button is an independent symbol, not linked to any other one in any way.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_055.gif" alt="The newly made button for scrolling up the menu." width="34" height="33" /></p>
<p><span class="step">4.20</span> Click on the <strong>Scene 1</strong> link above the timeline to exit the button&#8217;s timeline and to return to the main one.</p>
<p><span class="step">4.21</span> <strong>Click</strong> on the <em>scroll menu up</em> button inside the Library once, <strong>hold</strong> your mouse button and <strong>drag out</strong> an instance of it out onto the scene. Place it next to the <em>scroll menu down</em> button, like shown below.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_056.gif" alt="The two menu buttons side by side." width="201" height="34" /></p>
<p><span class="step">4.22</span> Select the &#8220;UP&#8221; button and assign it an <strong>Instance name</strong>: call it <em>menuUp_btn</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_057.gif" alt="The Instance name of the button that serves to scroll the menu up." width="164" height="51" /></p>
<p><span class="step">4.23</span> Add some text near the buttons, so that the users actually know what&#8217;s the menu about — don&#8217;t leave anyone guessing. Do this with the Text tool <strong>(T)</strong> set to <strong>Static text</strong>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_058.gif" alt="The menu title was just added." width="201" height="34" /></p>
<div class="note">
<p>Always think about the user who is the least web-savvy. Creating a user-friendly site with the lowest common denominator in mind will enable you to have a much bigger public and also, the users will want to return to your site because they found it easy to use.</p>
</div>
<p><span class="step">4.24</span> <strong>Lock</strong> the <em>gallery menu</em> layer.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_059.gif" alt="Locking the first layer in your document." width="215" height="46" /></p>
<p>That&#8217;s it for the menu! You have completed it.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>5. Creating the image placeholders</h3>
<p><span class="step">5.1</span> Create a new layer and call it <em>images holder</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_060.gif" alt="A layer that will be host to a placeholder movie clip has been added." width="210" height="64" /></p>
<p><span class="step">5.2</span> Drag out an instance of the <em>empty movie clip </em>symbol from the Library into this new layer. As this movie clip is completely devoid of any graphical content, it is shown as a registration point only.</p>
<p>Assign an <strong>Instance name</strong> for this important movie clip into which all images will be loaded: name it <em>imagesHolder_mc</em>. <strong>Position</strong> it like this: set its <strong>X to 260</strong> and <strong>Y to 100</strong>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_061.gif" alt="Positioning and naming the new empty movie clip." width="164" height="152" /></p>
<p>This will place the <em>imagesHolder_mc</em> movie clip close to the menu, on its right, like shown below.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_062.gif" alt="The movie clip which will hold the loaded external images is next to the menu." width="255" height="45" /></p>
<p>When the overal dimensions of the movie are taken, this is a good position. I had a general idea about the gallery&#8217;s layout, but I arrived at this final dimensions and positions through the creation process itself. As I said, you can change these dimensions to suit you as you please later, just stick with them now, until you complete this lesson. The same goes for the placement of the elements: the menu doesn&#8217;t necessarily have to be on the left, vertically positioned, etc. I just made these choices for this tutorial.</p>
<p><span class="step">5.3</span> Make a third layer. You will create two movie clips here that will be present inside the Library only (for dynamic use, like the menu section button that you have made earlier). After they are complete, you will erase them from the stage and assign them identifiers in the Library to be able to use them via ActionScript later.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_063.gif" alt="A third layer has been created." width="211" height="83" /></p>
<p><span class="step"><a id="step54" name="step54"></a>5.4</span> Select the Rectangle tool <strong>(R)</strong>, use <strong>white for the fill</strong> color and <strong>black for the stroke</strong> color. Select <strong>hairline</strong> for the line type. Make sure that <strong>Stroke hinting</strong> is turned <strong>on</strong>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_064.gif" alt="The main options of the Rectangle tool." width="297" height="57" /></p>
<p><span class="step">5.5</span> Draw a <strong>88&#215;61 pixel</strong> rectangle on the stage. This will be the background for gallery thumbnails that will be loaded later.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_065.gif" alt="A small, white-filled rectangle has been drawn." width="93" height="127" /></p>
<p>Again, I chose these dimensions because they suit me for this tutorial. You may chose other dimensions. What is important is that <strong> you should create thumbnails with appropriate dimensions</strong> in Photoshop (or Fireworks) later. To obtain a nice appearance for your thumbnails, I suggest that you make them a little bit smaller than the rectangular backgound that you have just created. The white background being 88&#215;61 pixels, I decided to make my thumbnails <strong>81&#215;54 pixels</strong>.</p>
<p><span class="step">5.6</span> <strong>Select</strong> the rectangle that you just drew (<em><strong>both</strong></em> the outline and the fill). Then select <strong>Modify &gt; Convert to Symbol</strong> (shortcut key: <strong>F8</strong>). Select <strong>Movie clip</strong> as type (be careful not to choose the Button type, as it may have stayed from before), call it <em>thumbnail holder</em> and click <strong>OK</strong>.</p>
<p><span class="step">5.7</span> <strong>Double-click</strong> on the newly made movie clip to enter it. <strong>Lock</strong> the first layer and call it <em>bkg</em>. Make a <strong>new layer</strong> and call it <em>image holder</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_066.gif" alt="Adding a layer for the image holder inside the thumbnail holder movie clip." width="269" height="94" /></p>
<p><span class="step">5.8</span> <strong>Click and drag out</strong> and instance of the <em>empty movie clip</em> from the Library and into the <em>image holder</em> layer. In the Property inspector, give it the <strong>Instance name</strong> <em>thumbImage_mc</em> and position it so that both its <strong>X and Y coordinates are 4</strong>. You can see the movie clip below (its registration point), over the rectangle&#8217;s upper left corner.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_067.gif" alt="Adding an instance of the empty movie clip symbol inside the thumbnail holder." width="164" height="196" /></p>
<p><span class="step">5.9</span> <strong>Lock</strong> the <em>image holder</em> layer and <strong>make a new layer</strong> above it and name it <em>text</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_068.gif" alt="A layer for the numerical preloader has been added inside the thumbnail holder movie clip symbol." width="215" height="84" /></p>
<p>This is the layer where you&#8217;ll be placing a dynamic text field, so that <strong>a numerical (percentage) preloader</strong> can be displayed while the thumbnail is loading. Making a preloader for thumbnails is a nice thing: you give your users all the information about loading, even for such small images. This also covers the slow-speed modem users, by telling them how much they must wait before everything is loaded.</p>
<p><span class="step"><a id="step510" name="step510"></a>5.10</span> Select the Text tool <strong>(T)</strong>. Set its properties like this:</p>
<ol>
<li>Use <strong>Dynamic Text</strong>, which is understandable, since this text field will show the preloading process via some ActionScript code.</li>
<li>Select the same <strong>font type</strong> that you did before, to have a coherent design for your gallery.</li>
<li>Select an appropriate <strong>font size</strong> — I chose 14 for the button labels before so I did the same here.</li>
<li>Select <strong>black</strong> as the color, to be highly visible against the thumbnail holder&#8217;s white background.</li>
<li>Select <strong>left</strong> text alignment.</li>
<li>Choose <strong>Anti-alias for readability</strong>.</li>
<li>Like in most cases in this tutorial, make sure that the <strong>Selectable</strong> option stays turned <strong>off</strong>.</li>
<li>The <strong>Single line </strong>option should be used for this text field.</li>
</ol>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_069.gif" alt="Selecting the options for the dynamic text field." width="494" height="84" /></p>
<p><span class="step"><a id="step511" name="step511"></a>5.11</span> <strong>Click and drag</strong> your mouse to make a text field. Press <strong>Esc</strong> on your keyboard to exit the text field edit mode. Go to the Property inspector and give your text field an Instance name: call it <em>percent_txt</em>. Position it in the <strong>middle</strong> of your thumbnail holder movie clip.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_070.gif" alt="asdadsasd" width="156" height="193" /></p>
<p>Now, click the <strong>Embed</strong> button (it&#8217;s on the right side of the Property inspector when the text field is selected). Do the following:</p>
<ol>
<li>Select the <strong>Numeral</strong> option (you need all the numbers, since this is a percentage preloader). See 1 in the scrrenshot below.</li>
<li>Click inside the input field below the <strong>Include these characters</strong> text and type the percentage sign (%) inside it (see 2 in the screenshot below).</li>
<li>Click <strong>OK</strong>.</li>
</ol>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_070a.gif" alt="Embedding characters in a dynamic text field in Flash." width="180" height="240" /></p>
<p>Having the characters of the specific font you selected embedded inside your text field assures the coherence of your design and makes sure that all users will see the same thing.</p>
<p><span class="step">5.12</span> <strong>Lock</strong> the <em>text</em> layer and click on the <strong>Scene 1</strong> link to return to the main scene.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_071.gif" alt="Exiting the thumbnail holder movie clip after all the work inside it has been done." width="269" height="113" /></p>
<p><span class="step">5.13</span> <strong>Erase</strong> the <em>thumbnail holder</em> movie clip from the scene.</p>
<p><span class="step">5.14</span> Go over to the <strong>Library</strong> and find the <em>thumbnail holder</em> movie clip inside it.  <strong>Right-click</strong> on it and select the <strong>Linkage</strong> option. <strong>Check</strong> the <strong>Export for ActionScript</strong> option (this is what enables you to pull out the movie clip from the Library dynamically). The <strong>Export in first frame</strong> option will automatically become checked. Leave the <strong>Identifier</strong> as it is: <em>thumbnail holder</em>. Click <strong>OK</strong>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_072.gif" alt="Assigning a linkage identifier to a movie clip symbol." width="300" height="149" /></p>
<p>There! Your <em>thumbnail holder</em> movie clip symbol is now ready to be used by ActionScript. Specifically, you will use the <code>attachMovie()</code> method in your code later to pull this symbol from the Library and place it on the stage.</p>
<p>Now that the thumbnail holder is complete, you will create a similar but slightly different <strong>holder for the images</strong> — the big ones that will be loaded as a user clicks on a thumbnail. You will follow the same procedure as you did for the thumbnail holder movie clip.</p>
<p><span class="step">5.15</span> Select the Rectangle tool <strong>(R)</strong>. Draw a <strong>475&#215;317 pixel</strong> rectangle using the same options that you did in <a href="#step54">step 5.4</a>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_073.gif" alt="A big white rectangle with a black border." width="476" height="388" /></p>
<p><span class="step">5.16</span> <strong>Select the rectangle</strong> (both its fill and outline) and press <strong>F8</strong> (or select <strong>Modify &gt; Convert to Symbol</strong>) to convert it into a symbol. Select <strong>Movie clip</strong> as type, call it <em>big image holder </em> and click <strong>OK</strong>.</p>
<p><span class="step">5.17</span> <strong>Double-click</strong> on the <em>big image holder</em> movie clip on the stage to enter inside it. Call the first layer <em>bkg</em> and <strong>lock</strong> it. Make a <strong>new layer</strong> above it and call it <em>image holder</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_074.gif" alt="Stacking layers inside the big image holder movie clip symbol." width="266" height="93" /></p>
<p><span class="step">5.18</span> <strong>Click and drag out</strong> an instance of the <em>empty movie clip</em> symbol out of the Library and into the new layer (<em>image holder</em>) that you made in the previous step. Make the following adjustements:</p>
<ol>
<li>Give the movie clip an <strong>Instance name</strong>: call it <em>imageHolder_mc</em>.</li>
<li>Make both the <strong>X</strong> and <strong>Y</strong> coordinates of the movie clip equal <strong>4</strong>.</li>
</ol>
<p>The <em>empty movie clip</em> is represented by its registration point, since it contains no graphics at all (which is normal, because it will be used to load external JPEG images). I have marked it with a red arrow in the screenshot below so that you can more easily see it.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_075.gif" alt="The holder movie clip for the JPG images that will be loaded later." width="202" height="235" /></p>
<p>This movie clip is placed near the background rectangle&#8217;s upper left corner. This is a fine position for the JPEG image that will be loaded — its upper left corner will cooincide with the registration point of <em>empty movie clip</em>. You could reposition it later with ActionScript if you want, but I think there is no need to do that. This position is just fine.</p>
<p><span class="step">5.19</span> <strong>Lock</strong> the <em>image holder</em> layer and <strong>make a new one</strong> and call it <em>text</em>. You will place a dynamic text field for the preloader here, just like you did for the thumbnail holder.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_076.gif" alt="Adding a layer for the preloader for the big JPEG image." width="269" height="112" /></p>
<p><span class="step">5.20</span> Select the Text tool <strong>(T)</strong> and choose the same options as you did with it in step <a href="#step510">5.10.</a>, <strong>change only the font size</strong> — increase it more than twice. I chose 30.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_077.gif" alt="Text tool options in the Property inspector in Flash." width="494" height="84" /></p>
<p><span class="step">5.21</span> Click and drag to <strong>create a text field</strong>. Place it over the middle of the big rectangle. It should be large enough for three numbers and the percentage sign to show inside it. Press <strong>Esc</strong> to exit the text field. The <strong>Instance name</strong> for this text field can be the same as it was for the thumbnail holder (<em>percent_txt</em>), since these are two different movie clips and there will be no conflicts.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_078.gif" alt="A dynamic text field with its Instance name." width="480" height="383" /></p>
<p>You need to embed the appropriate characters in this text field too:</p>
<ol>
<li>Click the <strong>Embed</strong> button in Property inspector.</li>
<li>Select the <strong>Numerals</strong> option and insert the % character where appropriate, just like you did in <a href="#step511">step 5.11</a>.</li>
<li>Click <strong>OK</strong>.</li>
</ol>
<p><span class="step">5.22</span> <strong>Lock</strong> the <em>text</em> layer and click on the <strong>Scene 1</strong> link inside this movie clip to exit it. Once on the main stage, <strong>erase</strong> this movie clip from it.</p>
<p><span class="step">5.23</span> Find the <em>big image holder</em> movie clip inside the Library and <strong>right-click</strong> on it, then select <strong>Linkage</strong> from the context menu. <strong>Click</strong> the <strong>Export for ActionScript</strong> option to check it, leave the <strong>Identifier</strong> as <em>big image holder</em> and click <strong>OK</strong>.</p>
<p><strong>Save your work now</strong> if you haven&#8217;t already done so! Make this a habit, but especially in long projects like this one. Proceed to the next section to see how to create a text field where gallery and image descriptions will appear.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>6. Creating a text field for gallery and image descriptions</h3>
<p><span class="step">6.1</span> You should be on the main scene (timeline) now. Call the current layer (the one which you used to create the image placeholders) <em>description text</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_079.gif" alt="Adding a third layer to the main scene." width="209" height="84" /></p>
<p><span class="step">6.2</span> Select the Text tool <strong>(T)</strong>. This time, you will select different options than you did for the percentage preloaders inside the image placeholders. Select:</p>
<ol>
<li><strong>Dynamic text</strong>, of course.</li>
<li>Choose a font that is <strong>readable</strong>. Avoid exotic fonts.</li>
<li>Choose a <strong>size</strong> that is <strong>suitable for reading</strong>. Font sizes <strong>11</strong> or <strong>12</strong> work just fine.</li>
<li>I suggest that you select <strong>black</strong> for the color of your text, to have a good contrast with the white background and make the text easy to read.</li>
<li>Select <strong>left alignment</strong>. You may also select the <strong>Justify</strong> option. Avoid right or central alignment - this is never used in a &#8220;normal&#8221; text — that is, text that isn&#8217;t a title or a link, but a standard paragraph.</li>
<li>Select <strong>Anti-alias for readability</strong> (you will have to embed the characters because of this later).</li>
<li>You can either turn on or off the <strong>Selectable</strong> option — this is entirely up to you, whether you&#8217;ll enable your users to select the description text or not.</li>
<li>Make  sure to choose the <strong>Multiline</strong> option, as your descriptions may be several lines long, you never know, right? Better to make sure :-).</li>
</ol>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_080.gif" alt="Property inspector set for the Text tool." width="494" height="84" /></p>
<p><span class="step">6.3</span> <strong>Click</strong> on the stage and <strong>drag</strong> your mouse to create a text field. Hit <strong>Esc</strong> to exit the text field editing mode. Your text field&#8217;s dimensions should be about <strong>475&#215;100 pixels</strong>. Also, pay attention to its position: try to align it with the image placeholder and think about how much space will take an image once it&#8217;s loaded. In the screenshot below you can see the position and dimensions of the text field.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_081.gif" alt="The big dynamic text field on the stage." width="480" height="165" /></p>
<p><span class="step">6.4</span> Assign an <strong>Instance name</strong> to the text field to be able to manipulate it later via ActionScript: call it <em>desc_txt</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_082.gif" alt="The Instance name for the description text field." width="147" height="49" /></p>
<p><span class="step">6.5</span> Click the <strong>Embed</strong> button while the text field is selected to include the necessary characters in it and have nice, readable descriptions which are going to be nicely rendered: select the <strong>Basic Latin</strong> category and click <strong>OK</strong>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_083.gif" alt="Embedding the basic set of common characters in a text field." width="240" height="153" /></p>
<p>The last (yes, the last one, indeed <img src='http://flashexplained.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> thing that you need to create in this document is your logo. After that, the things that remain to be done are the external XML file, the folders with their respective photos and thumbnails and lastly, the magnificent ActionScript code that will make possible for the whole thing to work.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>7. Making the logo</h3>
<p><span class="step">7.1</span> <strong>Lock</strong> the <em>description text</em> layer and make <strong>a new layer</strong> and call it <em>logo</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_084.gif" alt="The fourth layer has been added to the main scene." width="209" height="101" /></p>
<p><span class="step">7.2</span> Now, this is just a suggestion fo the logo. You can make any kind of logo/header that you like, but I recommend that you follow my proposals here, just to be able to follow this tutorial more easily.</p>
<p>Select the Rectangle tool <strong>(R)</strong> and draw a <strong>700 by 40 pixels</strong> rectangle. Place it above the gallery menu. I have also drawn a thin white line through the lower part of the rectangle and changed the fill color of the lower part.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_085.gif" alt="The background for the logo." width="300" height="214" /></p>
<p><span class="step">7.3</span> Select the Text tool <strong>(T)</strong> and switch the type of the text field to <strong>Static text</strong>. Click and type anything you want over the rectangle.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_086.gif" alt="The logo with text." width="300" height="214" /></p>
<p><span class="step">7.4</span> <strong>Select</strong> the whole logo — both the rectangle and the text — and then choose <strong>Modify &gt; Convert to Symbol </strong> (shortcut key: <strong>F8</strong>). Select <strong>Movie clip</strong> as type, call it <em>logo</em> and click <strong>OK</strong>.</p>
<div class="note">
<p>I didn&#8217;t make separate layers for the background rectangle and the text inside the <em>logo</em> movie clip, but just selected the whole thing and made a movie clip symbol out of it. It is usually recommended to make separate layers for different elements inside a symbol, but logos aren&#8217;t supposed to change much, so I guess a single layer should pose no problems at all. Of course, if you are going to animate an element inside your logo or are planning to make changes later, you should place each element on its own layer.</p>
</div>
<p><span class="step">7.5</span> While the newly made <em>logo</em> movie clip symbol is selected on the stage, go over to the Property inspector and assign it an <strong>Instance name</strong>: call it <em>logo_mc</em>. Also, you can set both of its <strong>coordinates</strong> to <strong>10</strong>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_087.gif" alt="The logo movie clip's Instance name, dimensions and coordinates." width="162" height="106" /></p>
<p>You could have left the logo as it is without having to convert it into a movie clip symbol. But having a movie clip enables you to position it via ActionScript later if needed — you won&#8217;t need to do that manually, which is much more practical.</p>
<p><span class="step">7.6</span> <strong>Lock</strong> the <em>logo</em> layer and make a <strong>new layer</strong> and call it <em>actions</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_088.gif" alt="Adding a layer for ActionScrpt code." width="208" height="121" /></p>
<p>You won&#8217;t be entering any ActionScript code here right now. First you have to have an XML file where all the gallery data will be stored, some images and an exact folder hierarchy. So let me show you how to do all that before the coding part comes up. Before that, <strong>save your document!</strong></p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>8. Creating the XML file with image galleries data</h3>
<p><span class="step">8.1</span> First, <a href="http://www.flashexplained.com/img/actionscript/materials/image-gallery-XML.zip">download the XML file</a> that I created for this tutorial.</p>
<p>Before I tell you how this XML file will relate to your image galleries, the folders they are in, etc, I just want to say that I won&#8217;t explain the principles of XML and its interaction with Flash here, because I already made <a href="http://flashexplained.com/actionscript/how-to-make-a-dynamic-hangman-game-in-flash-8-with-xml-and-actionscript/#xmlrules">a detailed explanation of XML</a> in my <a href="http://flashexplained.com/actionscript/how-to-make-a-dynamic-hangman-game-in-flash-8-with-xml-and-actionscript/">Hangman game tutorial</a>, and there is no sense repeating it if it&#8217;s already written, right? <img src='http://flashexplained.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>If you&#8217;re not familiar with XML, I heartily recommend that you go and read the rules of XML and how Flash loads and parses XML data, before proceeding.</p>
<p>So, the XML file that you have just downloaded looks something like this (I haven&#8217;t displayed the whole file here for the sake of brevity and screen real estate):</p>
<p class="ascode"><span class="style4">&lt;?xml version=&quot;1.0&quot;?&gt;</span><br />
<span class="style1">&lt;galleries&gt;</span><br />
<span class="indent1"><span class="style2">&lt;gallery title=&quot;architecture&quot; intro=&quot;These are the photos of various buildings in the cities, towns and villages I visited during my voyages.&quot;&gt;</span><br />
</span><span class="indent2"><span class="style3">&lt;image&gt;</span>Dallas.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>Tresnjevka. I love the atmosphere on this one.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>Motovun.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>New York.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>Paris.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent1 style2">&lt;/gallery&gt;</span><br />
<span class="indent1"><span class="style2">&lt;gallery title=&quot;essays&quot; intro=&quot;A collection of various photos which either do not fit any other category - experiments and such.&quot;&gt;</span><br />
</span><span class="indent2"><span class="style3">&lt;image&gt;</span>Color mayhem!<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>The sleeping monster.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>Let me out!<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>A barrel on the side of the trail.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>Subterranean passage.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>A train in snow.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent1 style2">&lt;/gallery&gt;</span><br />
<span class="style1">&lt;/galleries&gt;</span></p>
<p>After the XML declaration comes the <strong>root node</strong>, of course. I chose to call it <strong><code> galleries</code></strong>. Within this, root node, every other bit of data is contained.</p>
<p class="ascode"><span class="style1">&lt;galleries&gt;</span><br />
&#8230;<br />
<span class="style1">&lt;/galleries&gt;</span></p>
<p>Every <strong>child node</strong> of the root node is called <strong><code>gallery</code></strong>. I chose to give each of these child nodes the same name (<code>gallery</code>) <strong>on purpose</strong>.   You will see later why (when I&#8217;ll explain the ActionScript code) — this is related to parsing the XML data.</p>
<p class="ascode"><span class="indent1"><span class="style2">&lt;gallery title=&quot;architecture&quot; intro=&quot;These are the photos of various buildings in the cities, towns and villages I visited during my voyages.&quot;&gt;</span><br />
</span>&#8230;<br />
<span class="indent1 style2">&lt;/gallery&gt;</span></p>
<p>Each <strong><code>gallery</code></strong> node has <strong>two attributes</strong> inside it: <strong><code>title</code></strong> and <strong><code>intro</code></strong>. I chose these names because I think they are logical: the first one refers to the title of each gallery and the second one tells the user what&#8217;s the gallery about. Remember, you may call your attributes any way you like, as long as you stick to the rules of XML.</p>
<p>The <strong><code>title</code></strong> attribute is very important: its value (between the quotation marks: <code>title="<strong>architecture</strong>&#8220;</code>) has a special functionality:</p>
<ul>
<li>It will appear on this particular gallery&#8217;s button in the gallery menu — it will become a <strong>button label</strong>.</li>
<li>This value is also the <strong>name of the folder</strong> inside which the images belonging to this particular gallery will be stored.</li>
</ul>
<p>So, as you&#8217;ll see a little bit later, the values of these attributes will have to be followed strictly, because the application will be made as a case-sensitive one. This means that the name of a folder must be exactly the same as the value of the title attribute for a particular gallery. If, as in the above example, the value of the title attribute for a gallery is <em>essays</em>, the name of the folder must be <em>essays</em> too. It cannot be <em>Essays</em> or <em>ESSAYS</em>.</p>
<p>The value of the attribute <strong><code>intro</code></strong> will be displayed inside the big dynamic text field below the thumbnails when the user clicks on any of the gallery buttons inside the menu. Once he chooses a gallery, the thumbnails will be loaded and displayed and the description text will be shown beneath them.</p>
<p><span class="ascode"><span class="indent1"><span class="style2">&lt;gallery title=&quot;architecture&quot; intro=&quot;</span><strong>These are the photos of various buildings in the cities, towns and villages I visited during my voyages.</strong><span class="style2">&quot;&gt;</span></span></span></p>
<p>So, the intro text can be anything you want. And it has no relation with the naming of the folders and galleries. It just describes a particular gallery.</p>
<p>Now, each <strong><code>gallery</code></strong> node has many child nodes, each of which is called <strong><code>image</code></strong>. Again, I chose to give them all the same name on purpose, because this will enable Flash to parse the XML data much more efficiently, and will save you a lot of trouble.</p>
<p><span class="ascode"><span class="indent2"><span class="style3">&lt;image&gt;</span>A barrel on the side of the trail.<span class="style3">&lt;/image&gt;</span></span></span></p>
<p>Between the opening and closing tags of each <code>image</code> node, there is a child node, which is in fact <strong>the description of the image</strong>. This description will appear in the big text field when the user clicks on a thumbnail and the big image starts to load.</p>
<div class="note">
<p>You may have as many galleries as you like, as long as each one is referenced in the XML file, and the corresponding folder exists. This is possible because in this tutorial you will see how to create a menu that can contain a basically limitless number of buttons (each button corresponds to a gallery).</p>
</div>
<p>And that would be it concerning the XML file.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>9. Creating the folder structure for the image gallery</h3>
<p><span class="step">9.1</span> As the first thing, you should have a separate folder (directory) inside which <strong>all </strong>the files that make up your gallery will be stored (SWF, HTML, XML, images). For the sake of simplicity, I chose to call this folder <strong>root</strong>.</p>
<p>As you can see in the screenshot below, both the <strong>SWF</strong> file (the one you are learning to create in this lesson) and the <strong>HTML</strong> page inside which it will be embedded should be placed inside this main (root) folder.</p>
<p><span class="step">9.2</span> Also, create <strong>a new folder</strong> inside the root folder and call it <em>gallery</em>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_089.gif" alt="The root directory of the ultimate image gallery." width="127" height="65" /></p>
<p>I chose to call the page <em>mypage.html</em> and the SWF file <em>imagegallery.swf</em>. You can call them as you like. It is the <em>gallery</em> folder that must have that exact name, because you will be using it in ActionScript later.</p>
<p>Of course, you can choose other file/folder placements, but I strongly recommend that you follow the one explained here, not only because you need it to complete this lesson, but also because I think that this folder hierarchy and structure is really one of the simplest and most easiest to use. Thanks to it, you will be able to modify or update your image gallery in a snap!</p>
<p><span class="step">9.3</span> The <strong>XML</strong> file that you have downloaded earlier must be placed inside the <em>gallery</em> folder. This file should be named <em>gallery.xml</em>.</p>
<p>Also, the <em>gallery</em> folder will contain <strong>all the sub-galleries</strong>: different sections of your image gallery, which will correspond to the menu buttons.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_090.gif" alt="The gallery folder expanded." width="127" height="167" /></p>
<p>What&#8217;s very important, I repeat it again, is that these <strong>subfolders must have the same names as they are defined inside the XML file.</strong> Otherwise, Flash won&#8217;t be able to find the folders if there are differences between them. They must match perfectly, including uppercase and lowercase letters.</p>
<div class="note">
<p>Using only lowercase letters for folder names will prevent a lot of possible mistakes. I recommend that you use them only, because you can change them into uppercase letters once these names are loaded in Flash, which you will do later in this lesson.</p>
</div>
<p><span class="step">9.4</span> Each gallery subfolder (like <em>architecture</em>, <em>essays</em>, etc in the above example) will contain the <strong>big images</strong>, the ones that are loaded and show up once a user clicks on a thumbnail.</p>
<p>These images should be named <em>1.jpg</em>, <em>2.jpg</em>, <em>3.jpg</em>&#8230; In short, <strong>each image name is a number</strong>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_091.gif" alt="The big images folder expanded." width="127" height="269" /></p>
<p>The numbers must follow the natural order, i.e. if you happen to dislike an image and want to remove it from the gallery, you should rename the other ones so that the order remains unbroken. For example, look at the screenshot above. If you want to remove the image <em>3.jpg</em>, you should rename <em>4.jpg</em> to <em>3.jpg</em> and <em>5.jpg</em> to <em>4.jpg</em>. This is important because of two things:</p>
<ol>
<li>Flash will load the exact number of images as there are inside the XML file.</li>
<li>The images will be looked for and once found, loaded in a sequential order — the thumbnails, and after that, the corresponding big image, for each thumbnail.</li>
</ol>
<p><span class="step">9.5</span> Here is what you should do to have the <strong>thumbnails</strong> load and display properly for each gallery:</p>
<ol>
<li>The thumbnails for each image gallery section must be placed in a folder called <em>thumbs</em>. Each gallery section must have such a folder inside itself.</li>
<li>The number of thumbnail images must match the number of big images.</li>
<li>The thumbnails must have the same file names as their bigger counterparts. So, for example, the thumbnail, for say, image <em>14.jpg</em> should also be called <em>14.jpg</em>.</li>
</ol>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_092.gif" alt="The thumbs folder is expanded." width="131" height="354" /></p>
<div class="note">
<p>In this project, the number of thumbnails for each section is limited to 20. It was my choice to make it this way, based on the gallery&#8217;s overall layout and concept. You can increase this number if you want, but then you&#8217;ll need to rearrange your gallery elements&#8217; position and dimensions to accomodate a higher number of thumbnails. I recommend that you stick with my concept until the end of this tutorial and then experiment later. Of you do need more thumbnails for a particular gallery section, I suggest that you split it into two or more sections. For example, if you have tons of photos from a summer vacation, split them into different sections, like summer vacation 1, summer vacation 2, etc.</p>
</div>
<p>The screenshot below shows the maximum number of thumbnails for a single gallery section.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_093.jpg" alt="An image gallery section with twenty thumbnails." width="400" height="181" /></p>
<p>A small reminder: for this project, the <strong>big images</strong> should be resized/cropped to <strong>469&#215;311 pixels</strong>. The thumbnails should be made to be <strong>81&#215;54 pixels</strong>. Again, I repeat, this suits this particular project you are learning to create right now. Once you get hold of how things function, make any other Flash image gallery system. And <a href="#respond">post a comment</a> with a link to it, I&#8217;d love to see it! <img src='http://flashexplained.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>And this wraps it up for the file/folder hierarchy. The last, and probably one of the most important things, is the ActionScript programming code that powers up the gallery.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>10. Inserting the ActionScript code</h3>
<p><span class="step">10.1</span> Go back to your document. <strong>Lock</strong> the <em>actions</em> layer and <strong>click on its first keyframe</strong> to select it. As you may already know, a layer does <strong>not</strong> have to be unlocked for you to be able to insert ActionScript code inside it. In fact, I always lock the layer where my code is contained, to minimize errors — not to insert any graphics in it by mistake.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_094.gif" alt="Selecting the first keyframe in the actions layer." width="262" height="121" /></p>
<div class="note">
<p>If possible, always place all of your ActionScript code into one layer, and also, into as few keyframes as you can. The layer which contains your ActionScript code should be made exclusively for that purpose. There is just no sense in placing any graphics or symbols inside it. Also, place the layer with ActionScript either on top of all layers or below all the other layers so that you can find it very quick when you need it. This is a time-tested and a very convenient practice!</p>
</div>
<p><span class="step">10.2</span> Select <strong>Window &gt; Actions</strong> to open the Actions panel.</p>
<p><span class="step">10.3</span> Insert the following ActionScript code inside the panel:</p>
<p class="ascode">var menuSpeed:Number = 6;<br />
var menuDown:Button = menuDown_btn;<br />
var menuUp:Button = menuUp_btn;<br />
menuUp._alpha = 0;<br />
menuUp.enabled = false;<br />
var firstLook:Boolean = true;<br />
var menuButtons:MovieClip = galleryMenu_mc.buttonsHolder_mc;<br />
var galleryMask:MovieClip = galleryMenu_mc.galleryMask_mc;<br />
galleryMask._height = 391;<br />
var imagesHolder:MovieClip = imagesHolder_mc;<br />
var descText:TextField = desc_txt;<br />
var imagesInGallery:Array = new Array();<br />
var galleryNames:Array = new Array();<br />
var galleryIntros:Array = new Array();<br />
var descriptions:Array = new Array();<br />
var tracker:Number = new Number();<br />
var whatIsLoading:String = new String();<br />
var galleryBtnLeftMargin:Number = 10;<br />
var galleryBtnUpperMargin:Number = 60;<br />
var galleryBtnVSpace:Number = 23;<br />
var thumbMarginX:Number = 96;<br />
var thumbMarginY:Number = 68;<br />
imagesHolder._x = 243;<br />
imagesHolder._y = galleryBtnUpperMargin;<br />
logo_mc._x = logo_mc._y=galleryBtnLeftMargin;<br />
desc_txt._x = 243;<br />
desc_txt._y = 400;<br />
descText.text = &quot;Click on a gallery name on the left to load its thumbnails. Remember, you can click on a thumbnail only when all the thumbnails in a gallery have been loaded. When you click on a thumbnail to see the big image, clicking on the big image will close it and you will return to the gallery. Use the button(s) above the galleries to scroll through them.&quot;;<br />
import flash.filters.DropShadowFilter;<br />
var shadowEffect:DropShadowFilter = new DropShadowFilter(3, 45, 0&#120;000000, 100, 3, 3, 1, 3);<br />
var thumbsFilter:Array = [shadowEffect];<br />
var loader:MovieClipLoader = new MovieClipLoader();<br />
var myListener:Object = new Object();<br />
loader.addListener(myListener);<br />
myListener.onLoadInit = function(target:MovieClip) {<br />
<span class="indent1">if (whatIsLoading == &quot;thumb&quot;) {</span><br />
<span class="indent2">currentThumbnail.percent_txt._visible = false;</span><br />
<span class="indent2">currentThumbnail.filters = thumbsFilter;</span><br />
<span class="indent2">thumbClickable();</span><br />
<span class="indent2">tracker++;</span><br />
<span class="indent2">if (tracker&lt;howManyImages) {</span><br />
<span class="indent2">loadThumbnail();</span><br />
<span class="indent2">} else {</span><br />
<span class="indent2">enableThumbs();</span><br />
<span class="indent2">}</span><br />
<span class="indent1">} else if (whatIsLoading == &quot;big&quot;) {</span><br />
<span class="indent2">target._alpha = 0;</span><br />
<span class="indent2">displayBigImage.percent_txt._visible = false;</span><br />
<span class="indent2">displayBigImage.filters = thumbsFilter;</span><br />
<span class="indent2">bigClickable();</span><br />
<span class="indent2">fadeIn();</span><br />
<span class="indent1">}</span><br />
};<br />
myListener.onLoadProgress = function(target:MovieClip, loaded:Number, total:Number) {<br />
<span class="indent1">percent = Math.floor(loaded/total*100);</span><br />
<span class="indent1">if (whatIsLoading == &quot;thumb&quot;) {</span><br />
<span class="indent2">currentThumbnail.percent_txt._visible = true;</span><br />
<span class="indent2">currentThumbnail.percent_txt.text = percent+&quot;%&quot;;</span><br />
<span class="indent1">} else if (whatIsLoading == &quot;big&quot;) {</span><br />
<span class="indent2">displayBigImage.percent_txt._visible = true;</span><br />
<span class="indent2">displayBigImage.percent_txt.text = percent+&quot;%&quot;;</span><br />
<span class="indent1">}</span><br />
};<br />
var imageGallery:XML = new XML();<br />
imageGallery.ignoreWhite = true;<br />
imageGallery.onLoad = function(success) {<br />
<span class="indent1">if (success) {</span><br />
<span class="indent2">parseGalleries();</span><br />
<span class="indent1">} else {</span><br />
<span class="indent2">descText.text = &quot;Sorry the image data just didn&#8217;t load.&quot;;</span><br />
<span class="indent1">}</span><br />
};<br />
imageGallery.load(&quot;gallery/gallery.xml&quot;);<br />
function parseGalleries():Void {<br />
<span class="indent1">if (imageGallery.firstChild.nodeName == &quot;galleries&quot;) {</span><br />
<span class="indent1">var rootNode:XMLNode = imageGallery.firstChild;</span><br />
<span class="indent1">for (i=0; i&lt;rootNode.childNodes.length; i++) {</span><br />
<span class="indent2">if (rootNode.childNodes[i].nodeName == &quot;gallery&quot;) {</span><br />
<span class="indent2">currentGallery = rootNode.childNodes[i];</span><br />
<span class="indent2">imagesInGallery.push(currentGallery.childNodes.length);</span><br />
<span class="indent2">galleryNames.push(currentGallery.attributes.title);</span><br />
<span class="indent2">galleryIntros.push(currentGallery.attributes.intro);</span><br />
<span class="indent2">currentGalleryTitle = rootNode.childNodes[i].attributes.title;</span><br />
<span class="indent2">currentGalleryButton = galleryMenu_mc.buttonsHolder_mc.attachMovie(&quot;gallery section button&quot;, &quot;galleryButton&quot;+i, galleryMenu_mc.buttonsHolder_mc.getNextHighestDepth());</span><br />
<span class="indent2">currentGalleryButton._x = 0;</span><br />
<span class="indent2">currentGalleryButton._y = galleryBtnVSpace*i;</span><br />
<span class="indent2">currentGalleryButton.sectionTitle_txt.text = &quot;0&quot;+(i+1)+&quot; &quot;+currentGalleryTitle.toUpperCase();</span><br />
<span class="indent2">for (j=0; j&lt;currentGallery.childNodes.length; j++) {</span><br />
<span class="indent2">if (currentGallery.childNodes[j].nodeName == &quot;image&quot;) {</span><br />
<span class="indent2">currentDescription = currentGallery.childNodes[j].firstChild.toString();</span><br />
<span class="indent2">descriptions.push(currentDescription);</span><br />
<span class="indent2">}</span><br />
<span class="indent2">}</span><br />
<span class="indent2">}</span><br />
<span class="indent1">}</span><br />
<span class="indent1">}</span><br />
<span class="indent1">numberOfGalleries = i;</span><br />
<span class="indent1">enableButtons(numberOfGalleries);</span><br />
}<br />
function enableButtons(numberOfGalleries:Number):Void {<br />
<span class="indent1">for (i=0; i&lt;numberOfGalleries; i++) {</span><br />
<span class="indent2">pressedButton = galleryMenu_mc.buttonsHolder_mc[&quot;galleryButton&quot;+i];</span><br />
<span class="indent2">pressedButton.onRollOver = function():Void  {</span><br />
<span class="indent2">this.gotoAndStop(2);</span><br />
<span class="indent2">};</span><br />
<span class="indent2">pressedButton.onRollOut = function():Void  {</span><br />
<span class="indent2">this.gotoAndStop(1);</span><br />
<span class="indent2">};</span><br />
<span class="indent1">pressedButton.onPress = function():Void  {</span><br />
<span class="indent2">removeMovieClip(thumbsDisplayer);</span><br />
<span class="indent2">removeMovieClip(displayBigImage);</span><br />
<span class="indent2">tracker = 0;</span><br />
<span class="indent2">thumbsDisplayer = imagesHolder.createEmptyMovieClip(&quot;thumbsDisplayer_mc&quot;, imagesHolder.getNextHighestDepth());</span><br />
<span class="indent2">clickedGallery = Number(this._name.substr(13));</span><br />
<span class="indent2">howManyImages = imagesInGallery[clickedGallery];</span><br />
<span class="indent2">whichGallery = galleryNames[clickedGallery];</span><br />
<span class="indent2">descText.text = galleryIntros[clickedGallery];</span><br />
<span class="indent2">currentRow = 0;</span><br />
<span class="indent2">currentColumn = 0;</span><br />
<span class="indent2">loadThumbnail();</span><br />
<span class="indent1">};</span><br />
<span class="indent1">}</span><br />
<span class="indent1">enableGalleryNavigation();</span><br />
}<br />
function loadThumbnail() {<br />
<span class="indent1">currentThumbnail = thumbsDisplayer.attachMovie(&quot;thumbnail holder&quot;, &quot;thumbnail&quot;+(tracker+1), thumbsDisplayer.getNextHighestDepth());</span><br />
<span class="indent1">target = currentThumbnail.thumbImage_mc;</span><br />
<span class="indent1">if ((tracker%5) == 0 &amp;&amp; tracker != 0) {</span><br />
<span class="indent2">currentRow += 1;</span><br />
<span class="indent1">}</span><br />
<span class="indent1">if (currentColumn&gt;3) {</span><br />
<span class="indent2">currentColumn = 0;</span><br />
<span class="indent1">} else if (tracker == 0) {</span><br />
<span class="indent2">currentColumn = 0;</span><br />
<span class="indent1">} else {</span><br />
<span class="indent2">currentColumn += 1;</span><br />
<span class="indent1">}</span><br />
<span class="indent1">currentThumbnail._x = currentColumn*thumbMarginX;</span><br />
<span class="indent1">currentThumbnail._y = currentRow*thumbMarginY;</span><br />
<span class="indent1">currentThumbnail.percent_txt._visible = true;</span><br />
<span class="indent1">thumbNumber = currentThumbnail._name.substr(9);</span><br />
<span class="indent1">thumbPath = &quot;gallery/&quot;+whichGallery+&quot;/thumbs/&quot;+thumbNumber+&quot;.jpg&quot;;</span><br />
<span class="indent1">whatIsLoading = &quot;thumb&quot;;</span><br />
<span class="indent1">loader.loadClip(thumbPath, target);</span><br />
}<br />
function thumbClickable():Void {<br />
<span class="indent1">currentThumbnail.onPress = function() {</span><br />
<span class="indent2">bigNumber = this._name.substr(9);</span><br />
<span class="indent2">displayBigImage = imagesHolder.attachMovie(&quot;big image holder&quot;, &quot;bigImage_mc&quot;, imagesHolder.getNextHighestDepth());</span><br />
<span class="indent2">target = displayBigImage.imageHolder_mc;</span><br />
<span class="indent2">bigImagePath = &quot;gallery/&quot;+whichGallery+&quot;/&quot;+bigNumber+&quot;.jpg&quot;;</span><br />
<span class="indent2">whatIsLoading = &quot;big&quot;;</span><br />
<span class="indent2">disableThumbs();</span><br />
<span class="indent2">loader.loadClip(bigImagePath, target);</span><br />
<span class="indent2">if (clickedGallery&gt;0) {</span><br />
<span class="indent2">var descPosition:Number = 0;</span><br />
<span class="indent2">for (i=0; i&lt;clickedGallery; i++) {</span><br />
<span class="indent2">descPosition += imagesInGallery[i];</span><br />
<span class="indent2">}</span><br />
<span class="indent2">descPosition = descPosition+Number(bigNumber)-1;</span><br />
<span class="indent2">imageDesc = descriptions[descPosition];</span><br />
<span class="indent2">} else {</span><br />
<span class="indent2">imageDesc = descriptions[Number(bigNumber)-1];</span><br />
<span class="indent2">}</span><br />
<span class="indent2">descText.text = imageDesc;</span><br />
<span class="indent1">};</span><br />
<span class="indent1">currentThumbnail.enabled = false;</span><br />
}<br />
function disableThumbs():Void {<br />
<span class="indent1">for (i=0; i&lt;howManyImages; i++) {</span><br />
<span class="indent2">thumbsDisplayer[&quot;thumbnail&quot;+(i+1)].enabled = false;</span><br />
<span class="indent1">}</span><br />
}<br />
function enableThumbs():Void {<br />
<span class="indent1">for (i=0; i&lt;howManyImages; i++) {</span><br />
<span class="indent2">thumbsDisplayer[&quot;thumbnail&quot;+(i+1)].enabled = true;</span><br />
<span class="indent1">}</span><br />
}<br />
function bigClickable():Void {<br />
<span class="indent1">displayBigImage.onPress = function() {</span><br />
<span class="indent2">removeMovieClip(this);</span><br />
<span class="indent2">enableThumbs();</span><br />
<span class="indent2">descText.text = galleryIntros[clickedGallery];</span><br />
<span class="indent1">};</span><br />
}<br />
function fadeIn():Void {<br />
<span class="indent1">target.onEnterFrame = function():Void  {</span><br />
<span class="indent2">this._alpha += 10;</span><br />
<span class="indent2">if (this._alpha&gt;=100) {</span><br />
<span class="indent2">delete this.onEnterFrame;</span><br />
<span class="indent2">this._alpha = 100;</span><br />
<span class="indent2">}</span><br />
<span class="indent1">};</span><br />
}<br />
function enableGalleryNavigation():Void {<br />
menuDown.onPress = function() {<br />
<span class="indent1">if (firstLook) {</span><br />
<span class="indent2">menuUp._alpha = 100;</span><br />
<span class="indent2">menuUp.enabled = true;</span><br />
<span class="indent2">firstLook = false;</span><br />
<span class="indent1">}</span><br />
<span class="indent1">var menuTop:Number = menuButtons._height-Math.abs(menuButtons._y);</span><br />
<span class="indent1">if (menuButtons._y&lt;=0 &amp;&amp; menuTop&gt;=galleryMask._height) {</span><br />
<span class="indent2">var targetPos:Number = menuButtons._y-galleryMask._height;</span><br />
<span class="indent2">menuDown.enabled = false;</span><br />
<span class="indent2">menuUp.enabled = false;</span><br />
<span class="indent2">menuButtons.onEnterFrame = function():Void  {</span><br />
<span class="indent2">menuButtons._y += (targetPos-menuButtons._y)/menuSpeed;</span><br />
<span class="indent2">if (menuButtons._y&lt;=(targetPos+0.8)) {</span><br />
<span class="indent2">menuButtons._y = Math.round(targetPos);</span><br />
<span class="indent2">delete menuButtons.onEnterFrame;</span><br />
<span class="indent2">menuDown.enabled = true;</span><br />
<span class="indent2">menuUp.enabled = true;</span><br />
<span class="indent2">}</span><br />
<span class="indent2">};</span><br />
<span class="indent1">}</span><br />
};<br />
menuUp.onPress = function() {<br />
<span class="indent1">var menuTop:Number = menuButtons._height-Math.abs(menuButtons._y);</span><br />
<span class="indent1">if (menuButtons._y&lt;0 &amp;&amp; menuTop&gt;0) {</span><br />
<span class="indent2">var targetPos:Number = menuButtons._y+galleryMask._height;</span><br />
<span class="indent2">menuDown.enabled = false;</span><br />
<span class="indent2">menuUp.enabled = false;</span><br />
<span class="indent2">menuButtons.onEnterFrame = function():Void  {</span><br />
<span class="indent2">menuButtons._y += (-menuButtons._y+targetPos)/menuSpeed;</span><br />
<span class="indent2">if (menuButtons._y&gt;=(targetPos-0.8)) {</span><br />
<span class="indent2">menuButtons._y = Math.round(targetPos);</span><br />
<span class="indent2">delete menuButtons.onEnterFrame;</span><br />
<span class="indent2">menuDown.enabled = true;</span><br />
<span class="indent2">menuUp.enabled = true;</span><br />
<span class="indent2">}</span><br />
<span class="indent2">};</span><br />
<span class="indent1">}</span><br />
};<br />
}</p>
<p>Yep, this a really big piece of ActionScript code! More than 230 lines of it! Now <strong>save your work</strong> and go onto the next section to see how to test your SWF movie and to understand all this programming code.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>11. Testing the image gallery</h3>
<p><span class="step">11.1</span> Before testing your gallery, check if all the elements are in place:</p>
<ul>
<li>The images, along with their thumbnails, placed in appropriate folders.</li>
<li>The XML file, with all the elements, some of which must match gallery folders&#8217; names.</li>
<li>The Flash document (.fla file) your currently working on, must be saved in the appropriate place.</li>
</ul>
<p><span class="step">11.2</span> Select <strong>Control &gt; Test Movie</strong>. The gallery menu should appear, with each of the sections buttons having its label. Click on them and see if everything loads properly: the thumbnails, and then the big images as you click on each thumbnail.</p>
<p><span class="step">11.3</span> You should check now if the preloader works: still in the SWF preview window, select <strong>View &gt; Download Settings &gt; 56K</strong> and after that <strong>View &gt; Simulate Download</strong>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_095.gif" alt="Simulating a slower Internet connection in Flash." width="347" height="265" /></p>
<p>You will see a blank screen for a short period of time, because you have just made Flash simulate downloading from the Web, to see the preloader in action. When I say preloader, I mean the one for the images, because this gallery hasn&#8217;t got its own, main preloader — it&#8217;s easy to create one, if you want to know how, just check out my <a href="http://www.flashexplained.com/category/preloaders/">preloader tutorials</a>. I won&#8217;t delve into that here, because I want to concentrate on the image gallery.</p>
<p>So, once the gallery has appeared, try clicking on a section button — you should see the preloader for each thumbnail appear, and if you click on a thumbnail, the big image should begin preloading. Each image may take a bit to load, because you have chosen the simulated download setting for one of the slowest connections — a plain 56K modem.</p>
<p>Fine. Let me explain you now the almighty ActionScript routines that are responsible for this image gallery working so nicely.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>12. The ActionScript code behind the image gallery explained</h3>
<p>I will explain you the ActionScript programming code by section, for easier understanding. The code consists of the following parts:</p>
<ol>
<li>Defining variables and positioning the main gallery elements</li>
<li>Importing the DropShadow filter</li>
<li>Creation of the MovieClipLoader and Listener objects and the functions that enable preloading</li>
<li>Loading XML</li>
<li>Parsing XML
<ul>
<li>Retrieving gallery data (titles and descriptions)</li>
<li>Creating menu section buttons dynamically</li>
</ul>
</li>
<li>Defining the functionality of the menu section buttons
<ul>
<li>Enabling the display of  the roll over and roll out states</li>
<li>Defining which thumbnails shall be loaded</li>
</ul>
</li>
<li>Thumbnail positioning and thumbnail preloading</li>
<li>Defining the functionality of the thumbnails
<ul>
<li>Big image preloading</li>
<li>Disabling the thumbnails while the big image is preloading</li>
<li>Selecting the right description for the chosen image</li>
</ul>
</li>
<li>Making the big image clickable</li>
<li>Fading in the loaded big image</li>
<li>Creating the scrolling functionality for the gallery sections menu</li>
</ol>
<p>Let&#8217;s start!</p>
<p><span class="step">12.1</span> <strong>Defining variables and positioning the main gallery elements</strong></p>
<p>As you can see, some of the variables here are created to serve as <strong>shortcuts</strong> to various movie clips, buttons and text fields:</p>
<p class="ascode">var menuDown:Button = menuDown_btn;<br />
var menuUp:Button = menuUp_btn;<br />
var menuButtons:MovieClip = galleryMenu_mc.buttonsHolder_mc;<br />
var galleryMask:MovieClip = galleryMenu_mc.galleryMask_mc;<br />
var imagesHolder:MovieClip = imagesHolder_mc;<br />
var descText:TextField = desc_txt;</p>
<p>This is done in order <strong>to reference them more easily</strong> and to do it a lot more faster. For example, imagine if you wanted to point to the <code>menuDown_btn</code> button from a <code>galleryMask_mc</code> movie clip&#8217;s event handler. Without the shortcut, you would have to do it like this:</p>
<p class="ascode">this._parent._parent.menuDown_btn</p>
<p>But when you have defined the variables as you did above, so that they serve as references to various objects in your SWF movie, all you have to do is write them and Flash instantly knows what movie clip or button you&#8217;re talking about, no matter where you reference it. So, instead of writing the above path, all you do is write <code>menuDown</code> and that&#8217;s it!</p>
<p>And of course, when you are referencing a Movie clip symbol, you have to define the variable which serves as its shortcut as a <strong>Movie clip type of variable</strong>:</p>
<p class="ascode">var imagesHolder:<strong>MovieClip</strong> = imagesHolder_mc;</p>
<p>In a similar way, variables that reference buttons must of the <code>Button</code> type, and of the <code>TextField</code> type for text fields.</p>
<p>Next, <strong>the speed at which the menu will scroll</strong> is defined, in the variable <code>menuSpeed</code>. This value will be used later, when the scrolling of the menu is going to be defined.</p>
<p class="ascode">var menuSpeed:Number = 6;<br />
menuUp._alpha = 0;<br />
menuUp.enabled = false;</p>
<p>As you can see above, the <strong><code>menuUp</code> button</strong>, which is used to scroll the menu upwards is first made <strong>invisible</strong> by turning its <strong><code>_alpha</code></strong> (transparency) property to <strong>0</strong> (zero) and then <strong>disabled</strong> by setting its <strong><code>enabled</code></strong> property to <strong><code>false</code></strong>.</p>
<p>Why is this done? To simply turn off and make invisible the button, not to confuse your users. I have done a little bit of testing and people told me that they don&#8217;t know which button to press in the beginning. Since the menu can only be scrolled downwards at first, it makes sense to remove the <code>menuUp</code> button. This also removes any confusion. So, later you&#8217;ll see the explanation for the code that makes the button in question appear, but only once a user has clicked on the <code>menuDown</code> button.</p>
<div class="note">
<p>You must always think about your users and make your websites as user-friendly as possible. This can be tricky with Flash, as it offers far more possibilities than plain old HTML, where navigation is reduced to textual or image links. Flash offers basically infinite possibilities to create rich, interactive experiences, and that&#8217;s why you must be careful: Don&#8217;t let yourself be seduced by the vast array of eye-candy gizmos that can be made — always keep the user in mind! Have someone try out your Flash project before you launch it: even just a little bit of testing with real users (NOT web designers and such, who are web and computer-savvy) can go a long way towards improving the user experience. I always test my projects before going live. I suggest you do the same and make this a habit.</p>
</div>
<p>The variable <strong>firstLook</strong> is of the <strong>Boolean</strong> type, which means that its value can equal only <strong><code>true</code></strong> or <strong><code>false</code></strong>. This variable will help Flash determine if the user is using the gallery section menu for the first time. You&#8217;ll see it later: If the user is indeed using the menu for the first time — by pressing the <strong>menuDown</strong> button, the <strong>menuUp</strong> button will appear and become enabled (clickable). After that, the <strong>firstLook</strong> variable&#8217;s value will be set to <strong><code>false</code></strong>, because once the button for scrolling the menu up appears, there is no need and sense to do it again.</p>
<p class="ascode">var firstLook:Boolean = true;</p>
<p>After that, the height of the <strong>galleryMask</strong> movie clip is set via the <strong><code>_height</code></strong> property of the Movie clip class. This value is expressed in <strong>pixels</strong>. I have set it to 391 pixels, because I have found that this value is fine for showing up a certain number of gallery section buttons. It just looked good to me, after some experimentation.</p>
<p class="ascode">galleryMask._height = 391;</p>
<p>See now why it&#8217;s fine to make a movie clip out of a mask? You can easily readjust its dimensions via ActionScript — there is no need for you to go back inside the gallery menu movie clip each time that you want to change it, select the mask, resize it manually, etc. With ActionScript, the change is done in a snap!</p>
<p>Now come four variables of the <strong>Array</strong> type. An array is like a big variable: it can store many values, be those values of the Number type, String (text) type or something else. Think of them as of filing cabinets, where each drawer contains a value. They are perfect for storing many values, which will be used later at different points in your code.</p>
<p class="ascode">var imagesInGallery:Array = new Array();<br />
var galleryNames:Array = new Array();<br />
var galleryIntros:Array = new Array();<br />
var descriptions:Array = new Array();</p>
<p>They serve to contain the following values:</p>
<ul>
<li>The <strong>imagesInGallery</strong> array will store the information on the <strong>number of images in each gallery section</strong>.</li>
<li>The <strong>galleryNames</strong> array will keep <strong>the names (titles) of the sections</strong> of your image gallery. If you recall, these are the names of the folders of different gallery sections, which are exactly the same as the values of the title attributes of gallery nodes inside your XML file.</li>
<li>The <strong>galleryIntros</strong> array will store <strong>the descriptions for each gallery section</strong>. These are the values of the intro attributes belonging to each gallery node in your XML file.</li>
<li>The <strong>descriptions</strong> array will store inside itself the textual description for each image in your gallery, which is going to be pulled out from the XML file too.</li>
</ul>
<p>All of these arrays will be populated (filled with data) during the XML parsing process, which is explained later.</p>
<p>The <strong>tracker</strong> variable is of the <strong>Number</strong> type (which means it stores numerical values) and it will serve to keep track of the <strong>number of thumbnails</strong> when user has clicked on a gallery section and will also serve to <strong>place the thumbnails</strong> correctly and evenly into rows.</p>
<p class="ascode">var tracker:Number = new Number();</p>
<p>The <strong>whatIsLoading</strong> variable is of the <strong>String</strong> type (meaning it will contain text values). This variable&#8217;s value will serve to tell Flash if the image that is being loaded is a thumbnail or a big image and to react appropriately in each case.</p>
<p class="ascode">var whatIsLoading:String = new String();</p>
<p>The variables that follow serve to position different elements of your gallery on the stage:</p>
<p class="ascode">var galleryBtnLeftMargin:Number = 10;<br />
var galleryBtnUpperMargin:Number = 60;<br />
var galleryBtnVSpace:Number = 23;<br />
var thumbMarginX:Number = 96;<br />
var thumbMarginY:Number = 68;<br />
imagesHolder._x = 243;<br />
imagesHolder._y = galleryBtnUpperMargin;<br />
logo_mc._x = logo_mc._y = galleryBtnLeftMargin;</p>
<p>The <strong>galleryBtnLeftMargin</strong> and <strong>galleryBtnUpperMargin</strong> variables hold the values that serve to position the <strong>imagesHolder</strong> movie clip (which will contain all the thumbnails and big images, once they load) and also to position the <strong>logo</strong>. The variable called <strong>galleryBtnVSpace</strong> determines <strong>the vertical space between each of the section buttons</strong> inside the gallery menu. If you remember, the height of this button was made to be 20 pixels, so adding three more pixels should be just fine. The <strong>thumbMarginX</strong> and <strong>thumbMarginY</strong> variables&#8217; values determine <strong>the spacing between thumbnails</strong> of each gallery section.</p>
<p>Next comes the positioning of the big dynamic text field, referred to as <strong>desc_txt</strong>&#8230;</p>
<p class="ascode">desc_txt._x = 243;<br />
desc_txt._y = 400;</p>
<p>&#8230;or using the shortcut (see above), <strong>descText</strong>. Below is the text that will appear when the gallery loads and there hasn&#8217;t been any interaction with it yet from the user. You <strong>must</strong> give your users some guidelines for them to be able to use your image gallery more easily.</p>
<p class="ascode">descText.text = &quot;Click on a gallery name on the left to load its thumbnails. Remember, you can click on a thumbnail only when all the thumbnails in a gallery have been loaded. When you click on a thumbnail to see the big image, clicking on the big image will close it and you will return to the gallery. Use the button(s) above the galleries to scroll through them.&quot;;</p>
<p>Of course, you could have devised a graphical element to do this: for example, to give a hint that the big image will close once clicked upon, a &#8220;close&#8221; button with a small x inside it could be made to show up. There are always many ways to improve your user&#8217;s experience. Choose what works best and what you think goes well with your gallery&#8217;s overall design.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<p><span class="step">12.2</span> <strong>Importing the DropShadow filter</strong></p>
<p>I decided to apply the DropShadow filter to the thumbnails to make them even nicer. The first thing that you must do before applying a filter to an object inside Flash is to <strong>import</strong> it. When you do this, Flash reads from your disk (specifically, from a folder within the Flash installation) and inserts all the needed code for a particular filter into your SWF movie. Then it can be used and applied, once the importation has been made.</p>
<p class="ascode">import flash.filters.DropShadowFilter;</p>
<p>After that, a variable of the <code>DropShadowFilter</code> type is created.</p>
<p class="ascode">var shadowEffect:DropShadowFilter = new DropShadowFilter(3, 45, 0&#120;000000, 100, 3, 3, 1, 3);</p>
<p>The values between the parenthesis are as follows: distance, angle, color, alpha, blurX, blurY, strength and quality. They are pretty much self-explanatory. After that, you add the <strong>shadowEffect</strong> variable which contains the filter to the <strong>thumbsFilter</strong> array, which will then be applied to the thumbnails.</p>
<p class="ascode">var thumbsFilter:Array = [shadowEffect];</p>
<p>For a more detailed explanation of how a filter in Flash works and why you need to create an array that will contain it, check out my tutorial on <a href="http://flashexplained.com/actionscript/applying-the-blur-filter-to-buttons-via-actionscript/">the use of the blur filter in Flash</a>.</p>
<p><span class="step"><a id="step123" name="step123"></a>12.3</span> <strong>Creation of the MovieClipLoader and Listener objects and the functions that enable preloading</strong></p>
<p>If you wish to preload external JPEG images  into Flash across all browsers, the best method available is the one that uses the <strong>MovieClipLoader</strong> object. This particular object is specifically made for external content loading. It is great and you will use it to load and preload both the thumbnails and the big images! Here&#8217;s how it works:</p>
<ol>
<li>The first thing that you must do is create an instance of the <strong>MovieClipLoader</strong> object. I chose to call the variable which will contain it <code>loader</code>.</li>
</ol>
<p class="ascode">var loader:MovieClipLoader = new MovieClipLoader();</p>
<ol>
<li>Then, you need to make a <strong>listener</strong> object, which can be a movie clip or an Object object (a generic object, let&#8217;s say so). It will listen to what the MovieClipLoader object is doing and will react when things start happening: for example, when the loading is started by the MovieClipLoader or is in progress, the listener is aware of that and reacts by running specific functions (which will, for example, tell Flash how much has been loaded, etc). I called the listener object <code>myListener</code>.</li>
</ol>
<p class="ascode">var myListener:Object = new Object();</p>
<ol>
<li>And to have the MovieClipLoader and the listener work together nicely, you must <strong>associate the listener object to the MovieClipLoader</strong>, like this, using the <code>addListener</code> method:</li>
</ol>
<p class="ascode">loader.addListener(myListener);</p>
<p>Fine. But, before any loading/preloading is going to be done, you must first and foremost write two important functions:</p>
<ul>
<li>One that will tell Flash what to do <strong>while an image is being loaded</strong> (called <code>onLoadProgress</code>),</li>
<li>And the other that will tell it what to do <strong>once the loading is complete</strong> (called <code>onLoadInit</code>).</li>
</ul>
<p>I repeat, these functions must be created before any loading begins. Flash must know what to do in advance! On a sideline note, this method of preloading is also explained extensively in my <a href="http://flashexplained.com/menus-interfaces/how-to-make-a-complete-flash-website-navigation-system-with-a-built-in-preloader-for-external-content/">menu preloader system</a> tutorial. Let me show you now how have I set up the listener object&#8217;s <code>onLoadInit()</code> function for the gallery.</p>
<p class="ascode">myListener.onLoadInit = function(target:MovieClip) {<br />
<span class="indent1">if (whatIsLoading == &quot;thumb&quot;) {</span><br />
<span class="indent2">currentThumbnail.percent_txt._visible = false;</span><br />
<span class="indent2">currentThumbnail.filters = thumbsFilter;</span><br />
<span class="indent2">thumbClickable();</span><br />
<span class="indent2">tracker++;</span><br />
<span class="indent2">if (tracker&lt;howManyImages) {</span><br />
<span class="indent2">loadThumbnail();</span><br />
<span class="indent2">} else {</span><br />
<span class="indent2">enableThumbs();</span><br />
<span class="indent2">}</span><br />
<span class="indent1">} else if (whatIsLoading == &quot;big&quot;) {</span><br />
<span class="indent2">target._alpha = 0;</span><br />
<span class="indent2">displayBigImage.percent_txt._visible = false;</span><br />
<span class="indent2">displayBigImage.filters = thumbsFilter;</span><br />
<span class="indent2">bigClickable();</span><br />
<span class="indent2">fadeIn();</span><br />
<span class="indent1">}</span><br />
};</p>
<p>Flash will <strong>automatically execute</strong> the <code>onLoadInit()</code> function once the external JPG image (or a SWF, or a GIF&#8230;) has been <strong>entirely downloaded</strong> to the user&#8217;s hard disk.</p>
<p>First, the function is defined with a <strong>parameter</strong> (the thing between the function&#8217;s parenthesis): the <strong>target </strong>variable which is a <strong>Movie clip</strong>.   This is the empty movie clip into which the external image will be loaded.</p>
<p class="ascode">myListener.onLoadInit = function(<strong>target:MovieClip</strong>) {</p>
<p>Inside the function (meaning between its curly braces: <code>{</code> and <code>}</code>), the first thing that shows up is an <strong><code>if/else if</code> conditional statement</strong>:</p>
<p class="ascode"><span class="indent1"><strong>if (whatIsLoading </strong>==<strong> &quot;thumb&quot;) {</strong></span><br />
<span class="indent2">currentThumbnail.percent_txt._visible = false;</span><br />
<span class="indent2">currentThumbnail.filters = thumbsFilter;</span><br />
<span class="indent2">thumbClickable();</span><br />
<span class="indent2">tracker++;</span><br />
<span class="indent2">if (tracker&lt;howManyImages) {</span><br />
<span class="indent2">loadThumbnail();</span><br />
<span class="indent2">} else {</span><br />
<span class="indent2">enableThumbs();</span><br />
<span class="indent2">}</span><br />
<span class="indent1"><strong>} else if (whatIsLoading </strong>==<strong> &quot;big&quot;) {</strong></span><br />
<span class="indent2">target._alpha = 0;</span><br />
<span class="indent2">displayBigImage.percent_txt._visible = false;</span><br />
<span class="indent2">displayBigImage.filters = thumbsFilter;</span><br />
<span class="indent2">bigClickable();</span><br />
<span class="indent2">fadeIn();</span><br />
<span class="indent1"><strong>}</strong></span></p>
<p>As you can see, this conditional statement looks at the value of the <strong>whatIsLoading</strong> variable to decide what to do next. This value is of the string type (meaning it&#8217;s text) and can equal either <strong>&#8220;thumb&#8221;</strong> or <strong>&#8220;big&#8221;</strong>. These two values stand for thumbnail and big image. I defined them as such because it&#8217;s logical and I can instantly see what do they refer to.</p>
<p>As I said, this function is defined before the actual loading starts. So, as you will see later, <strong>once the loading of an external JPEG image has been triggered, the value of the whatIsLoading variable will be set to either &#8220;thumb&#8221; or &#8220;big&#8221;.</strong> It is set to &#8220;thumb&#8221; when the user clicks on a gallery section button — when the thumbnails of that section should be loaded and displayed. It is set to &#8220;big&#8221; when the user has clicked on a thumbnail to see the big image.</p>
<p>So, what happens when the value is set to &#8220;thumb&#8221;? The following:</p>
<p class="ascode">currentThumbnail.percent_txt._visible = false;<br />
currentThumbnail.filters = thumbsFilter;<br />
thumbClickable();<br />
tracker++;<br />
if (tracker &lt; howManyImages) {<br />
<span class="indent1">loadThumbnail();</span><br />
} else {<br />
<span class="indent1">enableThumbs();</span><br />
}</p>
<p>Here  is the above code, broken down line by line:</p>
<ul>
<li>The <strong>dynamic text field</strong> inside the <strong>thumbnail holder</strong> movie clip of the currently loaded thumbnail is hidden by setting its <code>_visible</code> property to <code>false</code> (remember, this is the text field that you created earlier in this tutorial, where the percentage preloader will show up during preloading).</li>
<li>The <strong>drop shadow effect</strong> is applied to the thumbnail holder via the movie clip&#8217;s <code>filters</code> property.</li>
<li>The <code>thumbClickable()</code> function is invoked (meaning it is called), which will define <strong>what will happen when the user clicks on a thumbnail:</strong> she or he will begin the loading of its bigger counterpart (the big image). This function comes later in the code, you&#8217;ll see it explained too.</li>
<li>The <code>tracker</code> variable is <strong>incremented by one</strong> (1 is added to its current value) — that&#8217;s what the two plus signs (++) stand for. Remember, this variable is used to let Flash know which thumbnail is currently being loaded/has been loaded, where it should be placed, etc.</li>
<li>Then,  an <strong><code>if/else</code> conditional statement</strong> shows up, which does the following:</li>
<li>if the value of <strong>tracker</strong> variable is <strong>lesser than</strong> the value of <strong>howManyImages</strong> variable, the <code>loadThumbnail()</code> function will be invoked and <strong>the next thumbnail will be loaded</strong>.</li>
<li>If that condition isn&#8217;t true (when <code>tracker</code>&#8217;s value is equal to or bigger than <code>howManyImages</code>&#8216; value), then the thumbnails <strong>will be enabled</strong>. This means that they will be clickable.</li>
</ul>
<p>The above means the following: <code>tracker</code> keeps track of the number of thumbnails in the current gallery section (the one that the user chose to see). The variable <code>howManyImages</code> holds the number of images that exist in the chosen gallery section. So, if the current thumbnail isn&#8217;t the last one — meaning if there are more to be loaded — more <strong>will</strong> be loaded.</p>
<p>And when all the thumbnails have been loaded, they are all enabled. <strong>This means that the user isn&#8217;t able to click on any of the thumbnails until all of them have been completely loaded.</strong> I made this to be so because I like it like that and also because I don&#8217;t have to deal with additional interaction stuff which I&#8217;d have to, if I hadn&#8217;t done this.</p>
<p>And now, what happens when the value of the <strong>whatIsLoading</strong> variable has been set to <strong>&#8220;big&#8221;</strong>? A slightly different thing:</p>
<p class="ascode">target._alpha = 0;<br />
displayBigImage.percent_txt._visible = false;<br />
displayBigImage.filters = thumbsFilter;<br />
bigClickable();<br />
fadeIn();</p>
<p>Here&#8217;s the breakdown of the above code:</p>
<ul>
<li>The <code>_alpha</code> property <strong>(transparency)</strong> of the <code>target</code> movie clip (the one into which the big image will be loaded) is set to zero, meaning that <strong>it will become invisible</strong>. I have chosen to do this to be able to apply the nice fade-in effect to the big image later :). Why make a simple instant appearance when you can create a cool fade-in effect?</li>
<li>Then, as was the case with the thumbnails, the <strong>dynamic text field</strong> of the <strong>big image holder</strong> is made invisible (<code>_visible = false</code>), because the percentage preloader needs to disappear once the big image has been fully loaded.</li>
<li>The <strong>drop shadow filter</strong> is applied to the big image, as it was for the thumbnails.</li>
<li>The <strong>big image is made clickable</strong> by calling the <code>bigClickable()</code> function, which you&#8217;ll see later. This makes possible for the user to click the big image, and once that has been done, the image will be removed and the thumbnails will be visible again.</li>
<li>And finally, the <code>fadeIn()</code> function is invoked <strong>to smoothly fade in the big image,</strong> from invisibility to complete opaqueness.</li>
</ul>
<p>Cool! What comes next is the <code>onLoadProgress()</code> function <strong>which monitors the downloading of the image(s)</strong> to the user&#8217;s computer. This function is used to create the preloaders.</p>
<p class="ascode">myListener.onLoadProgress = function(target:MovieClip, loaded:Number, total:Number) {<br />
<span class="indent1">percent = Math.floor(loaded/total*100);</span><br />
<span class="indent1">if (whatIsLoading == &quot;thumb&quot;) {</span><br />
<span class="indent2">currentThumbnail.percent_txt._visible = true;</span><br />
<span class="indent2">currentThumbnail.percent_txt.text = percent+&quot;%&quot;;</span><br />
<span class="indent1">} else if (whatIsLoading == &quot;big&quot;) {</span><br />
<span class="indent2">displayBigImage.percent_txt._visible = true;</span><br />
<span class="indent2">displayBigImage.percent_txt.text = percent+&quot;%&quot;;</span><br />
<span class="indent1">}</span><br />
};</p>
<p>This function comes with three parameters:</p>
<ul>
<li><strong>target </strong>— the empty movie clip which into which the external JPEG is loaded,</li>
<li><strong>loaded</strong> — how much of the image has been loaded so far, in bytes and</li>
<li><strong>total</strong> — the total file size of the image that is being loaded.</li>
</ul>
<p>Inside the function, the first line servers to calculate <strong>the percentage of the image that has been loaded so far</strong> (<code>loaded/total*100</code>) which is then rounded to the nearest lower value with the <code>floor()</code> method of the <code>Math</code> object.</p>
<p class="ascode">percent = Math.floor(loaded/total*100);</p>
<p>Next comes a conditional <code>if/else if</code> statement, which, much like in the previous function, determines if the value of the <code>whatIsLoading</code> variable equals either &#8220;thumb&#8221; or &#8220;big&#8221;. Then, whether it is a thumbnail that is being loaded or a big image, what goes on is basically the same: the <strong>percent_txt</strong> dynamic text field inside the image holder becomes <strong>visible</strong> and inside it the information on <strong>how much of the image has been loaded so far</strong> is displayed, using the <strong>percent</strong> variable followed by the % character.</p>
<p>For the thumbnail:</p>
<p class="ascode">currentThumbnail.percent_txt._visible = true;<br />
currentThumbnail.percent_txt.text = percent+&quot;%&quot;;</p>
<p>&#8230;as well as for the big image:</p>
<p class="ascode">displayBigImage.percent_txt._visible = true;<br />
displayBigImage.percent_txt.text = percent+&quot;%&quot;;</p>
<p>The <code>currentThumbnail</code> and <code>displayBigImage</code> variables are defined later, you&#8217;ll see. There is a lot going on here in those two functions that hasn&#8217;t appeared or been defined in your code yet, but that is, I repeat, because these functions, which are connected to the <strong>MovieClipLoader</strong> object and its associated <strong>listener</strong> object <strong>have to be defined before you actually proceed to load the external JPEG images.</strong></p>
<p>Great! Let&#8217;s move on to the XML loading part now.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<p><span class="step">12.4</span> <strong>Loading XML</strong></p>
<p>To load XML data from an external XML file into Flash, you must do the following:</p>
<ol>
<li>Create a new <strong>XML object</strong>.</li>
<li>Create an <strong><code>onLoad()</code> function</strong> which will tell Flash what to do after loading has been finished, whether it was performed successfully  or not.</li>
<li>Tell Flash to <strong>load the XML data</strong> from the external XML file.</li>
</ol>
<p>Here is the code that does exactly that:</p>
<p class="ascode">var imageGallery:XML = new XML();<br />
imageGallery.ignoreWhite = true;<br />
imageGallery.onLoad = function(success) {<br />
<span class="indent1">if (success) {</span><br />
<span class="indent2">parseGalleries();</span><br />
<span class="indent1">} else {</span><br />
<span class="indent2">descText.text = &quot;Sorry the image data just didn&#8217;t load.&quot;;</span><br />
<span class="indent1">}</span><br />
};<br />
imageGallery.load(&#8221;gallery/gallery.xml&#8221;);</p>
<p>The first line creates a new <strong>XML object</strong>. I chose to call it <code>imageGallery</code>.</p>
<p class="ascode">var imageGallery:XML = new XML();</p>
<p>The second one tells Flash to <strong>ignore the white space</strong> between the chunks of data inside the XML file:</p>
<p class="ascode">imageGallery.ignoreWhite = true;</p>
<p>This must be done, yes, because blank spaces in an XML file are considered by Flash as data, too. That&#8217;s why you must tell Flash to skip it because otherwise you&#8217;ll have a mess to deal with.</p>
<p>Now comes the <code>onLoad()</code> function of your XML object. This function (similarly as the ones used for preloading with the MovieClipLoader and its listener) <strong>must be defined before</strong> the actual XML loading takes place. Flash must know in advance what to do once the XML data has been loaded.</p>
<p class="ascode">imageGallery.onLoad = function(success) {<br />
<span class="indent1">if (success) {</span><br />
<span class="indent2">parseGalleries();</span><br />
<span class="indent1">} else {</span><br />
<span class="indent2">descText.text = &quot;Sorry the image data just didn&#8217;t load.&quot;;</span><br />
<span class="indent1">}</span><br />
};</p>
<p>As you can see above, the <code>onLoad()</code> function has one parameter: <code>success</code>. This is a parameter that gets automatically passed to this function upon XML data loading. It holds a <strong>Boolean</strong> type of value, which means that it equals either <strong>true</strong> or <strong>false</strong>. It yields as <strong>true</strong> if the XML data loading was performed <strong>successfully</strong> and <strong>false</strong> if it was <strong>not</strong>.</p>
<p>Inisde the function, there is a simple <code>if/else</code> <strong>conditional logic</strong> used to help Flash decide what to do if the loading was successful or not. The line</p>
<p class="ascode">if (success)</p>
<p>is the shorthand way of writing</p>
<p class="ascode">if (success == true)</p>
<p>And the <code>else</code> part, of course, is activated only when <code>success</code> turns out to be <code>false</code>. So, when XML data loading has been successful, the <code>parseGalleries()</code> function is invoked (invoked means called in programmers&#8217; jargon). I chose that name for the function, because it will literally parse the XML data to extract every bit of information that is needed for the creation of the image gallery.</p>
<p class="ascode">parseGalleries();</p>
<p>If the loading of XML data fails, you have to inform your users about that.</p>
<p class="ascode">descText.text = &quot;Sorry the image data just didn&#8217;t load.&quot;;</p>
<p>The above text is what will appear in the big dynamic text field. Basically, I don&#8217;t know what else can be done if the loading process fails. The user can try to reload the page, but most likely he or she will just close the page with the image gallery and move. If you have created a good XML file and tested your SWF and seen that it works online with no problems, there is not much that you can do if now and then some user can&#8217;t see the gallery because the XML data failed to load. That is beyond your power: maybe the server where you host your image gallery went down for a moment or the user has a too strong firewall, router, etc. But it happens rarely. Most people should see your Flash image gallery with no problems at all.</p>
<p>And now, once you have defined what Flash should do upon loading the XML data, tell it to load it! LIke this:</p>
<p class="ascode">imageGallery.load(&quot;gallery/gallery.xml&quot;);</p>
<p>Notice the path to the XML file: it is stored inside the <strong>gallery</strong> folder that you have created earlier in this tutorial, when you created the whole folder structure. This can be a source of problems too! If you change the folder inside which your XML file resides or the name of the XML file itself, you must change it in the above line of code too!</p>
<div class="note">
<p>When loading external data, you must reference it in relation to the HTML file inside which your SWF file is embedded, NOT in relation to the SWF file itself, regardless where it is situated. The HTML page is what&#8217;s important!</p>
</div>
<p>In the next step, I will show you how the parsing of XML data is done.</p>
<p><span class="step">12.5</span> <strong>Parsing XML: Retrieving gallery data (titles and descriptions) and creating the menu section buttons dynamically</strong></p>
<p>Below is the <code>parseGalleries()</code> function which serves to parse the XML data and store it in various variables. It looks big&#8230; scary&#8230; doesn&#8217;t it? <img src='http://flashexplained.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> No, it is not! It is just a little bit long, but everything inside it is perfectly logical and understandable and I will explain it to you in no time at all! So let&#8217;s get on with it.</p>
<p class="ascode">function parseGalleries():Void {<br />
<span class="indent1">if (imageGallery.firstChild.nodeName == &quot;galleries&quot;) {</span><br />
<span class="indent1">var rootNode:XMLNode = imageGallery.firstChild;</span><br />
<span class="indent1">for (i=0; i&lt;rootNode.childNodes.length; i++) {</span><br />
<span class="indent2">if (rootNode.childNodes[i].nodeName == &quot;gallery&quot;) {</span><br />
<span class="indent2">currentGallery = rootNode.childNodes[i];</span><br />
<span class="indent2">imagesInGallery.push(currentGallery.childNodes.length);</span><br />
<span class="indent2">galleryNames.push(currentGallery.attributes.title);</span><br />
<span class="indent2">galleryIntros.push(currentGallery.attributes.intro);</span><br />
<span class="indent2">currentGalleryTitle = rootNode.childNodes[i].attributes.title;</span><br />
<span class="indent2">currentGalleryButton = galleryMenu_mc.buttonsHolder_mc.attachMovie(&quot;gallery section button&quot;, &quot;galleryButton&quot;+i, galleryMenu_mc.buttonsHolder_mc.getNextHighestDepth());</span><br />
<span class="indent2">currentGalleryButton._x = 0;</span><br />
<span class="indent2">currentGalleryButton._y = galleryBtnVSpace*i;</span><br />
<span class="indent2">currentGalleryButton.sectionTitle_txt.text = &quot;0&quot;+(i+1)+&quot; &quot;+currentGalleryTitle.toUpperCase();</span><br />
<span class="indent2">for (j=0; j&lt;currentGallery.childNodes.length; j++) {</span><br />
<span class="indent2">if (currentGallery.childNodes[j].nodeName == &quot;image&quot;) {</span><br />
<span class="indent2">currentDescription = currentGallery.childNodes[j].firstChild.toString();</span><br />
<span class="indent2">descriptions.push(currentDescription);</span><br />
<span class="indent2">}</span><br />
<span class="indent2">}</span><br />
<span class="indent2">}</span><br />
<span class="indent1">}</span><br />
<span class="indent1">}</span><br />
<span class="indent1">numberOfGalleries = i;</span><br />
<span class="indent1">enableButtons(numberOfGalleries);</span><br />
}</p>
<p>As you probably noticed, there is a semicolon (<code>:</code>) followed by the ActionScript keyword <code>Void</code> in the first line of function&#8217;s code.</p>
<p class="ascode">function parseGalleries():Void {</p>
<p>This keyword tells Flash that the <code>parseGalleries()</code> function <strong>does not return a value</strong>. It is good to specify this, although it isn&#8217;t obligatory. When you have a function that does return a value to the caller, you have to specify this. For example, you may have a function which serves to perform a simple mathematical calculation and so instead of <code>Void</code>, you would write <code>Number</code> after the function&#8217;s name and the semicolon, because the function would return a numerical value.</p>
<p>Inside the function, almost all of the code (except two lines) is contained within an <code>if</code> <strong>conditional statement</strong>:</p>
<p class="ascode">if (imageGallery.firstChild.nodeName == &quot;galleries&quot;) {</p>
<p>Notice that I said an <code>if</code> conditional statement, <strong>not</strong> an <code>if/else</code> one. Why? Because there is no &#8220;else&#8221; situation here. The <code>if</code> conditional is used here as to say to Flash <em>&#8220;<strong>When</strong> you find the root node with the name <code>galleries</code>, do the following&#8221;</em>. Also, there is no <code>else</code>, because Flash <strong>will</strong> find the node named <code>galleries</code> because you created it in the XML file. This is a fail-safe procedure! <img src='http://flashexplained.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Remember, an XML file has <strong>only one root node</strong>. So when you say <code>imageGallery.firstChild.nodeName</code>, you tell Flash to look up the name of the root node — it is the first child of the XML file (which was converted to XML object when loaded into Flash) itself.</p>
<p class="ascode"><span class="style4">&lt;?xml version=&quot;1.0&quot;?&gt;</span><br />
<span class="style1">&lt;galleries&gt;</span><br />
<span class="indent1">&#8230; </span><br />
<span class="style1">&lt;/galleries&gt;</span></p>
<p>After that, a <strong>shortcut</strong> variable called <code>rootNode</code> is created that <strong>points to this root node</strong>:</p>
<p class="ascode">var rootNode:XMLNode = imageGallery.firstChild;</p>
<p>This is much like the variables that you have created at the very start of your ActionScript code to be able to reference movie clips and buttons in a shorthand and practical manner.</p>
<p>Next, you have a <strong><code>for</code> loop</strong> that is used to loop through all the <strong>child nodes of the root node</strong>.</p>
<p class="ascode">for (i=0; i&lt;rootNode.childNodes.length; i++) {</p>
<p>To be sure that Flash really loops through all the child nodes of the root node, you set the condition of the loop as follows: <code>i</code> must be <strong>less than the total number of child nodes</strong> (<code>rootNode.childNodes.length</code>). Why less than and not equal to the number of child nodes? Because the loop starts with <code>i</code> set to <strong>zero</strong>. Like the position of elements in an array and the position of characters in a string, for example, the XML nodes are also counted starting from zero. It is just how it&#8217;s done in ActionScript and the majority of programming languages.</p>
<p>What follows is an <code>if</code> conditional statement, again. Exactly like for the root node, you tell Flash here to look for child nodes of the root node that are called <code>gallery</code>.</p>
<p class="ascode">if (rootNode.childNodes[i].nodeName == &quot;gallery&quot;) {</p>
<p class="ascode"><span class="style4">&lt;?xml version=&quot;1.0&quot;?&gt;</span><br />
<span class="style1">&lt;galleries&gt;</span><br />
<span class="indent1"><span class="style2">&lt;gallery title=&quot;architecture&quot; intro=&quot;These are the photos of various buildings in the cities, towns and villages I visited during my voyages.&quot;&gt;</span><br />
</span><span class="indent2">&#8230;</span><br />
<span class="indent1 style2">&lt;/gallery&gt;</span><br />
<span class="indent1"><span class="style2">&lt;gallery title=&quot;essays&quot; intro=&quot;A collection of various photos which either do not fit any other category - experiments and such.&quot;&gt;</span><br />
</span><span class="indent2">&#8230;</span><br />
<span class="indent1 style2">&lt;/gallery&gt;</span><br />
<span class="style1">&lt;/galleries&gt;</span></p>
<p>The variable <code>i</code> will be replaced by the number of the current loop, of course: 0, 1, 2, 3, etc&#8230; so all child nodes will be parsed.</p>
<p>The <strong>gallery that is currently being parsed</strong> is stored in the <code>currentGallery</code> variable:</p>
<p class="ascode"><span class="indent2">currentGallery = rootNode.childNodes[i];</span></p>
<p>This si done to be able to reference it more easily in the next few lines of code.</p>
<p>Next, the construct <code>currentGallery.childNodes.length</code> is used to pull out the <strong>number of images in the current gallery section</strong>. This value is in turn stored inside the <code>imagesInGallery</code> <strong>array</strong> (which you created when you defined all the variables) via the <code>push()</code> method of the Array object.</p>
<p class="ascode"><span class="indent2">imagesInGallery.push(currentGallery.childNodes.length);</span></p>
<p>The <code>imagesInGallery</code> array is very important because the values stored inside it (the number of images in each gallery section) will be used later to tell Flash how many thumbnails should be loaded for a given gallery section.</p>
<p>Next, the value of the <code>title</code> <strong>attribute</strong> for the current <code>gallery</code> node is extracted and stored inside the <code>galleryNames</code> <strong>array</strong> via its <code>push()</code> method. This value will be later used to tell Flash <strong>what gallery section the user has chosen</strong> and also to give Flash the proper <strong>path to the section&#8217;s folder</strong>.</p>
<p class="ascode"><span class="indent2">galleryNames.push(currentGallery.attributes.title);</span></p>
<p>Using the same procedure as above, the value of the <code>intro</code> attribute is extracted and stored inside the <code>galleryIntros</code> array. These values will be used to show what&#8217;s the current gallery section about — this is the <strong>description text</strong> which will appear in the big dynamic text field once the user clicks on a gallery section button.</p>
<p class="ascode"><span class="indent2">galleryIntros.push(currentGallery.attributes.intro);</span></p>
<p>Next, by using the procedure that you understand well by now, the value of the <code>title</code> attribute of the current gallery section is extracted and stored inside the <code>currentGalleryTitle</code> variable. There is an important distinction here: before, the same attribute&#8217;s value was extracted and placed inside an <strong>array</strong> along with its counterparts from other <code>gallery</code> nodes and now it is placed inside a simple, plain <strong>variable</strong>. This is done because this variable&#8217;s value will be used very soon.</p>
<p class="ascode"><span class="indent2">currentGalleryTitle = rootNode.childNodes[i].attributes.title;</span></p>
<p>And now, the <em><strong>gallery section button</strong></em> movie clip is being extracted from the Library dynamically and placed inside the gallery menu:</p>
<p class="ascode"><span class="indent2">currentGalleryButton = galleryMenu_mc.buttonsHolder_mc.attachMovie(&quot;gallery section button&quot;, &quot;galleryButton&quot;+i, galleryMenu_mc.buttonsHolder_mc.getNextHighestDepth());</span></p>
<p>The gallery section button that you have created earlier is being attached inside the gallery menu, more specifically to the <strong>buttonsHolder_mc</strong> empty movie clip inside it: <code>galleryMenu_mc.buttonsHolder_mc.attachMovie</code>. As you remember, thsi is the empty clip beneath the mask in the gallery menu movie clip. The <code>attachMovie()</code> method has 3 parameters:</p>
<ol>
<li>The <strong>Linkage identifier</strong> which is used to pull a movie clip dynamically out of the Library: <strong>&#8220;gallery section button&#8221;</strong> in this case.</li>
<li>The <strong>new instance name</strong> of the newly attached movie clip. This will be different for each gallery section of course, so it has to be created dynamically: <code>"galleryButton"+i</code>. So, as the loop goes on, this instance name will be <em>galleryButton0</em>, <em>galleryButton1</em>, <em>galleryButton2</em>, etc.</li>
<li>The <strong>depth level</strong> of the attached movie clip. This parameter must also be different for each attached movie clip, because if it stays the same, each subsequent movie clip will replace the previous one, because <strong>there cannot be two movie clips present on a same depth level</strong>. So, the convenient <code>getNextHighestDepth()</code> method is used to place each movie clip on a separate depth level. Think of the depth levels as invisible layers inside the empty movie clip where you are attaching your buttons.</li>
</ol>
<p>And the <code>currentGalleryButton</code> variable is used as a shortcut for this newly attached movie clip — the current gallery section button. And now, you see why it is very practical to use such &#8220;variable shortcuts&#8221; — there are many things that you will now do with the attached movie clip. The first one is positioning:</p>
<p class="ascode">currentGalleryButton._x = 0;<br />
currentGalleryButton._y = galleryBtnVSpace*i;</p>
<p>The first line above serves to position each gallery section button <strong>horizontally</strong>, via the movie clip <code>_x</code> property, which defines its horizontal position in relation to the left edge of the stage, expressed in <strong>pixels</strong>. This value is 0 (zero) for each gallery section button, because they must be aligned flawlessly inside the menu.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_096.gif" alt="The horizontal position of the gallery sections buttons." width="220" height="174" /></p>
<p>On the other side, the <strong>vertical position</strong> of each section button inside the gallery menu is determined dynamically, because you have to put some space between them: <code>galleryBtnVSpace*i</code>. If you remember, when you defined all the variables, the <code>galleryBtnVSpace</code> was set to the value of 23. Like I said, I chose this value in relation to the height of the buttons, to be able to space them nicely. Since in every loop iteration this value is multiplied by <code>i</code>, the position of buttons will be: 0, 23, 46, 69, etc.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_097.gif" alt="The vertical positions of gallery menu sections buttons." width="306" height="117" /></p>
<p>And now you must define the <strong>label</strong> for the current gallery section button:</p>
<p class="ascode">currentGalleryButton.sectionTitle_txt.text = &quot;0&quot;+(i+1)+&quot; &quot;+currentGalleryTitle.toUpperCase();</p>
<p>As you can see above, this label is composed of a few things, all were my choice. I could have just slapped the plain gallery section title over each button, but I wanted to add numbers and also put all the letters into capitals:</p>
<ul>
<li>I added a zero (<code>"0"</code>) in front of each number because it looks cool :-).</li>
<li>After the zero comes the number, which is defined as <code>i+1</code> because I didn&#8217;t want the first label to be preceded with <code>"00"</code>, but <code>"01"</code>. Remember, in the main loop, the variable <code>i</code> starts as zero.</li>
<li>Then comes a blank space, to separate the number from the title: <code>" "</code>.</li>
<li>Then I transformed the titles into uppercase: <code>currentGalleryTitle.toUpperCase()</code>. That&#8217;s why I advise to always write such elements inside your XML file in lowercase letters: it is easy to transform them any way you like with ActionScript later.</li>
</ul>
<p>And now comes <strong>the <code>for</code> loop which passes through each <code>image</code> element</strong> inside each gallery node:</p>
<p class="ascode">for (j=0; j&lt;currentGallery.childNodes.length; j++) {<br />
<span class="indent1">if (currentGallery.childNodes[j].nodeName == &quot;image&quot;) {</span><br />
<span class="indent2">currentDescription = currentGallery.childNodes[j].firstChild.toString();</span><br />
<span class="indent2">descriptions.push(currentDescription);</span><br />
<span class="indent1">}</span><br />
}</p>
<p>Since this loop is contained within the main loop, you must naturally change the variable: it is <code>j</code> here. The condition for the loop to continue the iterations is that <strong><code>j</code></strong>, which starts at <strong>0</strong>, must be <strong>lesser than the number of the child nodes</strong> of the current <code>gallery</code> node, i.e. the number of <code>image</code> nodes.</p>
<p>Again, you have an <strong><code>if</code></strong> which checks that the name of each node looked at is indeed <code>"image"</code> and not something else. Like before, this is a way of telling Flash to look at precisely these nodes.</p>
<p class="ascode"><span class="style4">&lt;?xml version=&quot;1.0&quot;?&gt;</span><br />
<span class="style1">&lt;galleries&gt;</span><br />
<span class="indent1"><span class="style2">&lt;gallery title=&quot;architecture&quot; intro=&quot;These are the photos of various buildings in the cities, towns and villages I visited during my voyages.&quot;&gt;</span><br />
</span><span class="indent2"><span class="style3">&lt;image&gt;</span>Dallas.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>Tresnjevka. I love the atmosphere on this one.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>Motovun.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>New York.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>Paris.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent1 style2">&lt;/gallery&gt;</span><br />
<span class="indent1"><span class="style2">&lt;gallery title=&quot;essays&quot; intro=&quot;A collection of various photos which either do not fit any other category - experiments and such.&quot;&gt;</span><br />
</span><span class="indent2"><span class="style3">&lt;image&gt;</span>Color mayhem!<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>The sleeping monster.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>Let me out!<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>A barrel on the side of the trail.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>Subterranean passage.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent2"><span class="style3">&lt;image&gt;</span>A train in snow.<span class="style3">&lt;/image&gt;</span></span><br />
<span class="indent1 style2">&lt;/gallery&gt;</span><br />
<span class="style1">&lt;/galleries&gt;</span></p>
<p>Then, as each <code>image</code> node is found, its <strong>first child&#8217;s value is converted to a String</strong> (text) value.</p>
<p class="ascode">currentDescription = currentGallery.childNodes[j].firstChild.toString();</p>
<p>For example, the value of the first child node of the fourth <code>image</code> node in the first <code>gallery</code> node above is <em>New York</em>. And since this is an <strong>XML node</strong>, it has to be converted to a <strong>String</strong> value, for Flash to be able to display in the dynamic text field later and not to spit out a type mismatch error. Yes, the text between the <code>&lt;image&gt;</code> opening and closing tag is considered the <code>image</code> node&#8217;s first child.</p>
<p>And the text (which is the description of each particular image) is then stored inside the <code>descriptions</code> array.</p>
<p class="ascode">descriptions.push(currentDescription);</p>
<p>Finally, after the big <code>for</code> loop has ended after going through all the <code>gallery</code> nodes, the value of <code>i</code>, which matches the number of galleries (sections) is stored inside the <code>numberOfGalleries</code> variable.</p>
<p class="ascode">numberOfGalleries = i;</p>
<p>This number will be used later to determine the number of gallery section buttons and loop through all of them.</p>
<p>And finally, the <code>enableButtons()</code> function is called and the variable <code>numberOfGalleries</code> is passed to it.</p>
<p class="ascode">enableButtons(numberOfGalleries);</p>
<p>Whew! That was all about XML parsing and data extraction! Cool! Jump to the next step to see how the functionality of the gallery menu section buttons is created.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<p><span class="step">12.6</span> <strong>Defining the functionality of the menu section buttons: Enabling the display of the roll over and roll out states and defining which thumbnails shall be loaded</strong></p>
<p>Here&#8217;s the <code>enableButtons()</code> function which has <code>numberOfGalleries</code> passed as a parameter to it (which is of the <code>Number</code> type) and it does not return a value, hence the <code>Void</code> keyword:</p>
<p class="ascode">function enableButtons(numberOfGalleries:Number):Void {<br />
<span class="indent1">for (i=0; i&lt;numberOfGalleries; i++) {</span><br />
<span class="indent2">pressedButton = galleryMenu_mc.buttonsHolder_mc[&quot;galleryButton&quot;+i];</span><br />
<span class="indent2">pressedButton.onRollOver = function():Void  {</span><br />
<span class="indent2">this.gotoAndStop(2);</span><br />
<span class="indent2">};</span><br />
<span class="indent2">pressedButton.onRollOut = function():Void  {</span><br />
<span class="indent2">this.gotoAndStop(1);</span><br />
<span class="indent2">};</span><br />
<span class="indent1">pressedButton.onPress = function():Void  {</span><br />
<span class="indent2">removeMovieClip(thumbsDisplayer);</span><br />
<span class="indent2">removeMovieClip(displayBigImage);</span><br />
<span class="indent2">tracker = 0;</span><br />
<span class="indent2">thumbsDisplayer = imagesHolder.createEmptyMovieClip(&quot;thumbsDisplayer_mc&quot;, imagesHolder.getNextHighestDepth());</span><br />
<span class="indent2">clickedGallery = Number(this._name.substr(13));</span><br />
<span class="indent2">howManyImages = imagesInGallery[clickedGallery];</span><br />
<span class="indent2">whichGallery = galleryNames[clickedGallery];</span><br />
<span class="indent2">descText.text = galleryIntros[clickedGallery];</span><br />
<span class="indent2">currentRow = 0;</span><br />
<span class="indent2">currentColumn = 0;</span><br />
<span class="indent2">loadThumbnail();</span><br />
<span class="indent1">};</span><br />
<span class="indent1">}</span><br />
<span class="indent1">enableGalleryNavigation();</span><br />
}</p>
<p>Almost all the code of the <code>enableButtons()</code> function is wrapped in a <code>for</code> <strong>loop</strong> which serves to pass through all the <strong>gallery section buttons</strong> and define their <strong>onRollOver</strong>, <strong>OnRollOut</strong> and <strong>onPress</strong> event handler functions.</p>
<p class="ascode">for (i=0; i&lt;numberOfGalleries; i++) {</p>
<p>Now you see how important the <code>numberOfGalleries</code> variable is — without it, you wouldn&#8217;t be able to know the number of gallery section buttons.</p>
<p>The first thing that needs to be done is to set up another <strong>shorcut</strong>: a variable which will point to each button in your gallery menu as the loop progresses: <code>pressedButton</code>.</p>
<p class="ascode">pressedButton = galleryMenu_mc.buttonsHolder_mc[&quot;galleryButton&quot;+i];</p>
<p>Of course, Flash will process the expression between the angled brackets: <code>[</code> and <code>]</code>, which will result in <em>galleryButton0</em>, <em>galleryButton1</em>, <em>galleryButton2</em>, etc.</p>
<p>Now comes the definition of the <strong>onRollOver</strong> event handler function, which gets executed when the user <strong>rolls her mouse over a button</strong> in the gallery section menu:</p>
<p class="ascode">pressedButton.onRollOver = function():Void  {<br />
<span class="indent1">this.gotoAndStop(2);</span><br />
};</p>
<p>Basically, what happens is that the movie clip&#8217;s (which acts as a gallery section button) <strong>playhead gets sent to the second frame</strong>, where there is a different background color, to accentuate the rollover effect.</p>
<p>After that, the <strong>rollOut</strong> event handler function is defined, which gets run <strong>once the mouse has been pulled out of the button area</strong>. This returns the movie clip&#8217;s playhead to the first frame, putting it back to its primary state.</p>
<p class="ascode">pressedButton.onRollOut = function():Void  {<br />
<span class="indent1">this.gotoAndStop(1);</span><br />
};</p>
<div class="note">
<p>In both event handler functions, the keyword <code>this</code> points to the gallery section button movie clip itself, because it is contained inside the functions (inside the curly braces). Thanks to this, there is no need to specify the full path to the movie clip.</p>
</div>
<p>The diagram below explains this functionality well. The gallery section button has a blue background in the first frame and a crimson one in the second frame, when the onRollOver event has been fired and its event handler function executed.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_098.gif" alt="The rollover/rollout functionality of image gallery buttons explained." width="414" height="179" /></p>
<p>And now, a very important event handler function comes up: <code>onPress</code>, which governs what actions will be taken when the user has <strong>clicked a button</strong>. What will happen is the following:</p>
<ol>
<li>Any previously existing thumbnails and big image will be removed.</li>
<li>The tracking of the number of thumbnails  will be reset to zero.</li>
<li>A new empty movie clip which will hold all the section&#8217;s thumbnails will be created.</li>
<li>The following information will be retrieved and stored: what gallery section was selected, how many images are in it, the name (title) of the section and its description.</li>
<li>The variables which keep track of the rows and columns into which the thumbnails are placed will be reset to zero.</li>
<li>The function for loading the section&#8217;s thumbnails will be invoked.</li>
</ol>
<p class="ascode">pressedButton.onPress = function():Void  {<br />
<span class="indent1">removeMovieClip(thumbsDisplayer);</span><br />
<span class="indent1">removeMovieClip(displayBigImage);</span><br />
<span class="indent1">tracker = 0;</span><br />
<span class="indent1">thumbsDisplayer = imagesHolder.createEmptyMovieClip(&quot;thumbsDisplayer_mc&quot;, imagesHolder.getNextHighestDepth());</span><br />
<span class="indent1">clickedGallery = Number(this._name.substr(13));</span><br />
<span class="indent1">howManyImages = imagesInGallery[clickedGallery];</span><br />
<span class="indent1">whichGallery = galleryNames[clickedGallery];</span><br />
<span class="indent1">descText.text = galleryIntros[clickedGallery];</span><br />
<span class="indent1">currentRow = 0;</span><br />
<span class="indent1">currentColumn = 0;</span><br />
<span class="indent1">loadThumbnail();</span><br />
};</p>
<p>Any thumbnails or big images that may have been loaded before are removed with the <code>removeMovieClip()</code> method. If there weren&#8217;t any present, it doesn&#8217;t matter — nothing will happen. This is done by removing the <strong>placeholder movie clips</strong> that are created when the user clicks on a gallery section button or a thumbnail.</p>
<p class="ascode">removeMovieClip(thumbsDisplayer);<br />
removeMovieClip(displayBigImage);</p>
<p>Then, the tracker is reset to zero.</p>
<p class="ascode">tracker = 0;</p>
<p>And the <code>thumbsDisplayer</code> <strong>empty movie clip</strong> is created from scratch, using the <code>createEmptyMovieClip()</code> method. <strong>It will hold all the thumbnails</strong> of the gallery section that was selected by the user. This movie clip is created inside the <code>imagesHolder</code> movie clip, the empty movie clip which you have created on the stage during the first stages of this tutorial. You could have created this latter one dynamically via ActionScript too, but I wanted things to be a little more diverse and simplified. Not everything needs to be done through coding.</p>
<p class="ascode">thumbsDisplayer = imagesHolder.createEmptyMovieClip(&quot;thumbsDisplayer_mc&quot;, imagesHolder.getNextHighestDepth());</p>
<p>There are two parameters used in the <code>createEmptyMovieClip()</code> method:</p>
<ul>
<li>The first is the <strong>instance name</strong> of the newly made empty movie clip.</li>
<li>The second one is the <strong>depth level</strong> into which the new movie clip is placed. Again, the best thing to do is to use the <code>getNextHighestDepth()</code> method because with it, Flash automatically assigns the first free depth to the new movie clip. And of course, this depth level is the first free inside the <code>imagesHolder</code> movie clip, the one inside which the new empty movie clip is being created.</li>
</ul>
<p>Now the <code>clickedGallery</code> variable gets its value assigned. This value will be the identification number of the gallery section movie clip which was clicked. Since <strong>it is being extracted from the movie clip&#8217;s instance name</strong>, you need to pass it through the <code>Number()</code> method to convert the character into a number.</p>
<p class="ascode">clickedGallery = Number(this._name.substr(13));</p>
<p>The <code>substr()</code> method of the String object is used to do the extraction, since the instance name of the movie clip is a string (text) value. It goes on like this: suppose that the user clicked on the fourth gallery section button (which is the <em>monochrome</em> section in my gallery example). The instance name of the clicked movie clip will be <strong>galleryButton3</strong>. Yes, there is the number 3 at the end of the instance name, because, as you remember, in the <code>for</code> loop which is used to create these buttons, the starting value is always zero. The extraction would proceed like this (this is pseudo-code, not real one, just to show you how this process goes):</p>
<p class="ascode">clickedGallery = Number(this._name.substr(13));<br />
clickedGallery = Number(&quot;galleryButton3&quot;.substr(13));<br />
clickedGallery = Number(3);<br />
clickedGallery = 3;</p>
<p>The first parameter of the <code>substr()</code> method is <strong>the starting point of extraction.</strong> The first character in a string (a piece of text) has the position 0 (zero).</p>
<p>The second parameter is <strong>the number of characters to be extracted</strong> (the <strong>length</strong> of the new, extracted string). And if it is omitted (like above), then all the characters from that point until the end of the string will be extracted. So it doesn&#8217;t matter if your button has the name galleryButton3, galleryButton42 or galleryButton128, the number will always get extracted properly, because the extraction starts at position 13 and gets any remaining characters in the string from that point on.</p>
<p>After the extraction has been done, <strong>the result is converted to a mathematical value from a plain text character.</strong></p>
<p>And this final value is used three times after that:</p>
<p class="ascode">howManyImages = imagesInGallery[clickedGallery];<br />
whichGallery = galleryNames[clickedGallery];<br />
descText.text = galleryIntros[clickedGallery];</p>
<p>Specifically, It is used to:</p>
<ol>
<li>See <strong>how many images</strong> are in the selected gallery section (<code>howManyImages</code>).</li>
<li>What is the <strong>name/title</strong> of the selected gallery section (<code>whichGallery</code>).</li>
<li>Get and display the <strong>description</strong> for the selected gallery section ( <code>descText.text</code>).</li>
</ol>
<p>All three values are extracted from different <strong>arrays</strong>. In all three cases, this happens in the same manner, so I will explain it for the gallery title, for example. Let&#8217;s suppose again that the user clicked on the fourth (<em>monochrome</em> ) button, so the value of the <code>clickedGallery</code> variable is 3. Flash will proceed like this:</p>
<p class="ascode">whichGallery = galleryNames[clickedGallery];<br />
whichGallery = galleryNames[3];<br />
whichGallery = &quot;monochrome&quot;;</p>
<p>Why so? Because the number between the angled brackets: <code>[</code> and <code>]</code> points to the value at the position no. 3 inside the <code>galleryNames</code> array. You may already know it, but here it is: the first value inside an array in ActionScript has the position 0. The image below explains this nicely.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_099.gif" alt="The position of elements inside an array." width="493" height="28" /></p>
<p>Now you see how the values for the other two variables were extracted from their respective arrays, too.</p>
<p>Next, the values of the variables which serve to place the thumbnails into rows of five are reset to zero:</p>
<p class="ascode">currentRow = 0;<br />
currentColumn = 0;</p>
<p>Then the <code>loadThumbnail()</code> function is invoked, <strong>which will load the thumbnails</strong> for the chosen gallery section. This functions comes in the code just after the current one. Remember that all of this happens when the user has clicked on a gallery section button.</p>
<p class="ascode">loadThumbnail();</p>
<p>Once all of three event handler functions (onRollOver, onRollOut and onPress) for all the gallery section menu buttons have been properly defined, there is still one line of code (outside the <code>for</code> loop, so it is executed once the loop has reached its end) that is going to be run:</p>
<p class="ascode">enableGalleryNavigation();</p>
<p>This calls the <code>enableGalleryNaviagtion()</code> function which sets up the scrollability of the menu via the two buttons (up and down). This function will be defined at the end of all the gallery&#8217;s code.</p>
<p>Let me explain you now what happens when a gallery section button has been clicked and the thumbnails begin to load via the <code>loadThumbnail()</code> function.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<p><span class="step">12.7</span> <strong>Thumbnail positioning and thumbnail preloading</strong></p>
<p>So, the user has clicked on a gallery section to see its images. Here is the function that will attach the thumbnail holders, place them in an orderly fashion and trigger the preloading, so that the user can see that something is actually happening!</p>
<p class="ascode">function loadThumbnail() {<br />
<span class="indent1">currentThumbnail = thumbsDisplayer.attachMovie(&quot;thumbnail holder&quot;, &quot;thumbnail&quot;+(tracker+1), thumbsDisplayer.getNextHighestDepth());</span><br />
<span class="indent1">target = currentThumbnail.thumbImage_mc;</span><br />
<span class="indent1">if ((tracker%5) == 0 &amp;&amp; tracker != 0) {</span><br />
<span class="indent2">currentRow += 1;</span><br />
<span class="indent1">}</span><br />
<span class="indent1">if (currentColumn&gt;3) {</span><br />
<span class="indent2">currentColumn = 0;</span><br />
<span class="indent1">} else if (tracker == 0) {</span><br />
<span class="indent2">currentColumn = 0;</span><br />
<span class="indent1">} else {</span><br />
<span class="indent2">currentColumn += 1;</span><br />
<span class="indent1">}</span><br />
<span class="indent1">currentThumbnail._x = currentColumn*thumbMarginX;</span><br />
<span class="indent1">currentThumbnail._y = currentRow*thumbMarginY;</span><br />
<span class="indent1">currentThumbnail.percent_txt._visible = true;</span><br />
<span class="indent1">thumbNumber = currentThumbnail._name.substr(9);</span><br />
<span class="indent1">thumbPath = &quot;gallery/&quot;+whichGallery+&quot;/thumbs/&quot;+thumbNumber+&quot;.jpg&quot;;</span><br />
<span class="indent1">whatIsLoading = &quot;thumb&quot;;</span><br />
<span class="indent1">loader.loadClip(thumbPath, target);</span><br />
}</p>
<p>The first action inside the function is the process of attaching a <strong>thumbnail holder</strong> movie clip from the Library, to the <strong>thumbsDisplayer</strong> empty movie clip. This is done with the <code>attachMovie()</code> method which you have already encountered in this tutorial.</p>
<p class="ascode">currentThumbnail = thumbsDisplayer.attachMovie(&quot;thumbnail holder&quot;, &quot;thumbnail&quot;+(tracker+1), thumbsDisplayer.getNextHighestDepth());</p>
<p>The parameters of the method are as follows:</p>
<ol>
<li>The <strong>Linkage identifier</strong>, which serves to pull the movie clip out of the Library: <strong>&#8220;thumbnail holder&#8221;</strong>.</li>
<li>The new <strong>instance name</strong> of the attached movie clip: <strong>&#8220;thumbnail&#8221;+(tracker+1)</strong>. So the Instance names will be <em>thumbnail1</em>, <em>thumbnail2</em>, <em>thumbnail3</em>&#8230; and so on, until <em>thumbnail20</em>. Remember, I created the gallery so that each section can have a maximum of 20 thumbnails. I have written <code>(tracker + 1)</code> here because I don&#8217;t want the name of the first thumbnails to be <em>thumbnail0</em>, but <em>thumbnail1</em>. Why? Because I will need to extract that number later to point to the thumbnail JPEG image, and the first thumbnail in each gallery section is name <em>1.jpg</em> and <strong>not</strong> <em>0.jpg</em>.</li>
<li>And of course, the <strong>depth level</strong> assignment via the <code>getNextHighestDepth()</code> method.</li>
</ol>
<p>And the newly attached movie clip is referenced by the <strong><code>currentThumbnail</code></strong> variable.</p>
<p>Next, the <strong>target</strong> variable is defined, which will tell Flash where the external thumbnail <strong>will be loaded into</strong>. As you can see in the line of ActionScript code below, it is being loaded inside the <code>thumbImage_mc</code> empty movie clip of the current thumbnail holder.</p>
<p class="ascode"><span class="indent1">target = currentThumbnail.thumbImage_mc;</span></p>
<p>And now come the chunks of code which serve to position the thumbnails into rows, 5 thumbnails per row. First, the <strong>counting of rows</strong> is done.</p>
<p class="ascode"><span class="indent1">if ((tracker%5) == 0 &amp;&amp; tracker != 0) {</span><br />
<span class="indent2">currentRow += 1;</span><br />
<span class="indent1">}</span></p>
<p>The important thing to be aware of here is that this line serves to place thumbnails in rows of 5, so the condition(s) will be fulfilled for thumbnail number 6, 11and 16 (when <code>tracker</code> equals 5, 10 or 15). This means that when those thumbnails&#8217; turn comes, <strong>the value of the <code>currentRow</code> variable will be increased by 1</strong> (<code>currentRow += 1</code>).</p>
<p>There are <strong>two conditions</strong> in the <code>if</code> conditional statement here and both must be fulfilled in order for the code inside the curly brackets to be executed:</p>
<ul>
<li>The <strong>remainder</strong> of <code>tracker</code> divided by 5 must be <strong>equal to zero.</strong> It is divided by 5 because I want 5 thumbnails to be inside a row. Check out my tutorial on <a href="http://flashexplained.com/actionscript/how-to-use-the-modulo-operator-in-actionscript/">the use of the modulo operator in ActionScript</a> to see how it is done.</li>
<li>The <strong>value</strong> of <code>tracker</code> variable must <strong>not equal zero.</strong> This one serves only <strong>not to increase</strong> the value of <code>currentRow</code> when <code>tracker</code> is still equal to zero. This is a safeguard that ensures the first 5 thumbnails are placed in the first row and not moved below it.</li>
</ul>
<p>For example, what happens at the beginning, when <code>tracker</code> equals 0, or when it equals, say, 3 or 5? Let me show you how Flash makes the calculation in all three cases:</p>
<p class="ascode">(tracker%5) == 0 &amp;&amp; tracker != 0<br />
(0%5) == 0 &amp;&amp; 0 != 0</p>
<p>You don&#8217;t even have to look at the  first condition in the example above, because the second condition is <strong>false</strong>. It says that zero <strong>does not equal</strong> (<code>!=</code>) zero, which is false. And when just one condition turns out as false, the whole thing is scrapped and the code inside the curly braces (<code>currentRow += 1</code>) is skipped altogether.</p>
<p>OK, let&#8217;s see now what happens when <code>tracker</code> equals 3.</p>
<p class="ascode">(tracker%5) == 0 &amp;&amp; tracker != 0<br />
(3%5) == 0 &amp;&amp; 3 != 0<br />
3 == 0 &amp;&amp; 3 != 0</p>
<p>This time, it is the first condition that yields as <strong>false</strong> (it says that 3 equals 0, which is false) and so the whole thing is again false.</p>
<p>And now, the case when the value of tracker reaches either 5, 10 or 15:</p>
<p class="ascode">(tracker%5) == 0 &amp;&amp; tracker != 0<br />
(5%5) == 0 &amp;&amp; 5 != 0<br />
0 == 0 &amp;&amp; 5 != 0</p>
<p>Both conditions are now <strong>true</strong>, because zero does equal zero and five does not equal zero. Here, the value of <code>currentRow</code> will be increased by 1 and this will be used later to place the subsequent five thumbnails into the next row.</p>
<p>Ok, you need now to see the code that will ensure that <strong>the thumbnails are set apart from each other</strong>:</p>
<p class="ascode"><span class="indent1">if (currentColumn&gt;3) {</span><br />
<span class="indent2">currentColumn = 0;</span><br />
<span class="indent1">} else if (tracker == 0) {</span><br />
<span class="indent2">currentColumn = 0;</span><br />
<span class="indent1">} else {</span><br />
<span class="indent2">currentColumn += 1;</span><br />
<span class="indent1">}</span></p>
<p>Translated into english, this <code>if/else if/else</code> conditional statement means this:</p>
<p class="ascode">if (the value of currentColumn is greater then 3 — meaning it is not 0, 1, 2 or 3) {<br />
<span class="indent1">reset the  value of currentColumn to 0</span><br />
} on the other hand, if (tracker equals zero) {<br />
<span class="indent1">reset the  value of currentColumn to 0</span><br />
} and in all other cases, meaning when currentColumn is either 0, 1, 2 or 3 {<br />
<span class="indent1">increase the value of currentColumn by 1</span><br />
}</p>
<p>And finally, the code that actually positions the thumbnails on stage based on what I just explained to you.</p>
<p class="ascode">currentThumbnail._x = currentColumn*thumbMarginX;<br />
currentThumbnail._y = currentRow*thumbMarginY;</p>
<p>The <code>_x</code> and <code>_y</code> properties, as you know by now, position a movie clip horizontally and vertically on the stage. The value of <code>currentColumn</code> is multiplied by <code>thumbMarginX</code> and that of <code>currentRow</code> is multiplied by <code>thumbMarginY</code>. <strong>These two values serve to put some space between the thumbnails.</strong> You defined them at the beginning of your code, remember? They are set to 96 and 68, respectively. This is the value of space between the thumbnails expressed in <strong>pixels</strong>.</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_101.jpg" alt="The spacing between image gallery thumbnails." width="256" height="166" /></p>
<p>And now the <strong>dynamic text field</strong> inside the thumbnail holder is made <strong>visible</strong>:</p>
<p class="ascode">currentThumbnail.percent_txt._visible = true;</p>
<p>Using the <code>substr()</code> method of the <code>String</code> object (a text object, and the name of a movie clip is a piece of text), the <strong>number of the thumbnail</strong> is extracted:</p>
<p class="ascode">thumbNumber = currentThumbnail._name.substr(9);</p>
<p>As I have told previously in this tutorial, the first parameter of the <code>substr()</code> method is <strong>the place where the extraction starts</strong>. And when the second parameter (length) is <strong>omitted</strong>, as above, <strong>all</strong> the characters <strong>from the exatraction point up to the end of the string</strong> will be extracted. Why do this? Because like that, you will be able to extract the number of the thumbnail, whether it is a one or two-digit number. No need to write any conditional statements at all here. The image below explains this clearly (the blue numbers are character positions inside the string):</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_100.gif" alt="The substring method used without the length parameter." width="220" height="132" /></p>
<p>And the value of the <code>thumbNumber</code> variable is used next <strong>to point to the right thumbnail</strong> which needs to be loaded:</p>
<p class="ascode">thumbPath = &quot;gallery/&quot; + whichGallery + &quot;/thumbs/&quot; + thumbNumber + &quot;.jpg&quot;;</p>
<p>The line above is using simple <strong>concatenation</strong> (the joining of two or more strings together) to create the <strong>path</strong> to the thumbnail. Again, remember well that this path is relative to the <strong>HTML page</strong> inside which your image gallery SWF is embedded.</p>
<p>For example, if the third thumbnail of the <em>essays</em> gallery section were to be loaded, Flash would create the path like this:</p>
<p class="ascode">thumbPath = &quot;gallery/&quot; + whichGallery + &quot;/thumbs/&quot; + thumbNumber + &quot;.jpg&quot;;<br />
thumbPath = &quot;gallery/&quot; + &quot;essays&quot; + &quot;/thumbs/&quot; + &quot;3&quot; + &quot;.jpg&quot;;<br />
thumbPath = &quot;gallery/essays/thumbs/3.jpg&quot;;</p>
<p>Subsequently, you have to tell Flash <strong>what is loading</strong>, the thumb or the big image:</p>
<p class="ascode"><span class="indent1">whatIsLoading = &quot;thumb&quot;;</span></p>
<p>And finally, the <code>loadClip()</code> method of the <strong>MovieClipLoader</strong> object (which is called <code>loader</code>, you created it earlier, remember) is used to tell Flash to start loading (and preloading) the current thumbnail:</p>
<p class="ascode"><span class="indent1">loader.loadClip(thumbPath, target);</span></p>
<p>The first parameter inside the parenthesis is the <strong>external file</strong> that is going to be loaded (a JPEG thumbnail in this case). The second parameter is the target <strong>empty movie clip</strong> into which the external file will be loaded.</p>
<p>And now that the <code>loadClip()</code> method has been invoked, the MovieClipLoader and its associated listener will start working together and preload the image and display it, with the DropShadow filter applied to it. You can read again (I recommend it, it will be much more clear to you now) how this is done in the section which explains <a href="#step123">the use of the onLoadInit() and onLoadProgress() methods</a>.</p>
<p>Now you know how the placement and preloading of thumbnails is done! What follows is the explanation of  how the functionality of the thumbnails is defined.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<p><span class="step">12.8</span> <strong>Defining the functionality of the thumbnails</strong></p>
<p>I will show you now the following things that are part of the thumbnails&#8217; functionality:</p>
<ul>
<li><strong>Big image preloading</strong></li>
<li><strong>Disabling the thumbnails while the big image is preloading</strong></li>
<li><strong>Selecting the right description for the chosen image</strong></li>
</ul>
<p class="ascode">function thumbClickable():Void {<br />
<span class="indent1">currentThumbnail.onPress = function() {</span><br />
<span class="indent2">bigNumber = this._name.substr(9);</span><br />
<span class="indent2">displayBigImage = imagesHolder.attachMovie(&quot;big image holder&quot;, &quot;bigImage_mc&quot;, imagesHolder.getNextHighestDepth());</span><br />
<span class="indent2">target = displayBigImage.imageHolder_mc;</span><br />
<span class="indent2">bigImagePath = &quot;gallery/&quot;+whichGallery+&quot;/&quot;+bigNumber+&quot;.jpg&quot;;</span><br />
<span class="indent2">whatIsLoading = &quot;big&quot;;</span><br />
<span class="indent2">disableThumbs();</span><br />
<span class="indent2">loader.loadClip(bigImagePath, target);</span><br />
<span class="indent2">if (clickedGallery&gt;0) {</span><br />
<span class="indent2">var descPosition:Number = 0;</span><br />
<span class="indent2">for (i=0; i&lt;clickedGallery; i++) {</span><br />
<span class="indent2">descPosition += imagesInGallery[i];</span><br />
<span class="indent2">}</span><br />
<span class="indent2">descPosition = descPosition+Number(bigNumber)-1;</span><br />
<span class="indent2">imageDesc = descriptions[descPosition];</span><br />
<span class="indent2">} else {</span><br />
<span class="indent2">imageDesc = descriptions[Number(bigNumber)-1];</span><br />
<span class="indent2">}</span><br />
<span class="indent2">descText.text = imageDesc;</span><br />
<span class="indent1">};</span><br />
<span class="indent1">currentThumbnail.enabled = false;</span><br />
}</p>
<p>The first thing that can be noticed is that nearly all the code inside the <code>thumbClickable()</code> function is stored inside the current thumbnail&#8217;s <strong><code>onPress</code> event handler</strong> function definition. This is to be expected, because the <code>onPress</code> event handler tells Flash what to do when the user click on a thumbnail.</p>
<p class="ascode">currentThumbnail.onPress = function() {</p>
<p>The first that you have to do is make Flash extract the number of the big image that is going to be preloaded once the user clicks on a thumbnail:</p>
<p class="ascode">bigNumber = this._name.substr(9);</p>
<p>This is done in exactly the same manner as it was for the thumbnails (explained on the previous page), so I won&#8217;t repeat myself here.</p>
<p>Next, the <strong>big image holder</strong> movie clip is <strong>pulled out of from the Library</strong> and attached to the <strong>imagesHolder</strong> empty movie clip using the <code>attachMovie()</code> method which you now well by now:</p>
<p class="ascode">displayBigImage = imagesHolder.attachMovie(&quot;big image holder&quot;, &quot;bigImage_mc&quot;, imagesHolder.getNextHighestDepth());</p>
<p>Of course, once again, a variable is used as a <strong>shortcut</strong> to point to the newly attached movie clip: <code>displayBigImage</code>. As a reminder, this movie clip contains:</p>
<ol>
<li>The white background with thin black outline,</li>
<li>The empty movie clip inside which the big JPEG image will be loaded and</li>
<li>The dynamic text field which will display the percentage-based preloader.</li>
</ol>
<p>And so the empty movie clip (mentioned under no.2 above) is defined as the <strong>target</strong> for loading the external JPEG and will be passed as such to the MovieClipLoader later:</p>
<p class="ascode">target = displayBigImage.imageHolder_mc;</p>
<p>The <strong>path to the big JPEG image</strong> is defined in a way similar to those of the thumbnails:</p>
<p class="ascode">bigImagePath =   &quot;gallery/&quot;+whichGallery+&quot;/&quot;+bigNumber+&quot;.jpg&quot;;</p>
<p>The variables <code>whichGallery</code> and <code>bigNumber</code> are used to guide Flash to the right folder and right image. And the path is stored inside the <code>bigImagePath</code> variable.</p>
<p>Just like for the thumbnails before, you have to tell Flash what you&#8217;re loading here too:</p>
<p class="ascode">whatIsLoading = &quot;big&quot;;</p>
<p>And the thumbnails have to be disabled — this will stay so throughout the preloading process and also while the big image is being displayed. They will be re-enabled only once the user has clicked on the big image and it has disappeared, showing the thumbnails again. This is done through the <code>disableThumbs()</code> function which I will explain to you later.</p>
<p class="ascode">disableThumbs();</p>
<p>And now the actual command to load the big image is issued to Flash:</p>
<p class="ascode">loader.loadClip(bigImagePath, target);</p>
<p>The above is done  using the <code>loadclip()</code> method of the MovieClipLoader object, exactly in the same manner as was done for the thumbnails. Only the path and the target empty movie clip are different.</p>
<p>The next chunk of code is the one where <strong>the description for the selected big image</strong> is being searched for, found and displayed in the big text field below the image:</p>
<p class="ascode">if (clickedGallery &gt; 0) {<br />
<span class="indent1">var descPosition:Number = 0;</span><br />
<span class="indent1">for (i=0; i&lt;clickedGallery; i++) {</span><br />
<span class="indent2">descPosition += imagesInGallery[i];</span><br />
<span class="indent1">}</span><br />
<span class="indent1">descPosition = descPosition+Number(bigNumber)-1;</span><br />
<span class="indent1">imageDesc = descriptions[descPosition];</span><br />
} else {<br />
<span class="indent1">imageDesc = descriptions[Number(bigNumber)-1];</span><br />
}<br />
descText.text = imageDesc;</p>
<p>The search for description is placed inside an <code>if/else</code> conditional statement. Basically, this conditional logic boils down to this: if the user has clicked any gallery section than the first one (<code>clickedGallery &gt; 0</code>), a <code>for</code> loop will be initiated for calculating the precise position of the selected image&#8217;s description. If the first gallery section is selected by the user, a much simpler search is performed. I will explain the first case in more detail noe.</p>
<p>First there is the <code>descPosition</code> variable, whose initial value is 0. This variable will hold the number which will be the <strong>image&#8217;s description position</strong> inside the <code>descriptions</code> array.</p>
<p class="ascode">var descPosition:Number = 0;</p>
<p>Then, the <code>for</code> loop is initiated. The condition for the loop to exist is that <code>i</code>, set to zero, must be <strong>lesser than</strong> the value of <code>clickedGallery</code>. Remember, <code>clickedGallery</code> is a variable that holds the <strong>number</strong> of the clicked gallery.</p>
<p class="ascode">for (i=0; i &lt;clickedGallery; i++) {<br />
<span class="indent1">descPosition += imagesInGallery[i];</span><br />
}</p>
<p>Every time a loop iteration is made, the value of <code>descPosition</code> is updated. The value on the equation&#8217;s right side is added to the <code>descPosition</code>&#8217;s current value, through the use of the <strong>addition assignment</strong> (<code>+=</code>) operator. What&#8217;s on the right side is a construct that is pulling values out of the <code>imagesInGallery</code> array. All this is done in order for Flash to be able to find and display the proper image description.</p>
<p>It will be best explained by an example. In my gallery example, suppose the user has clicked on the sixth thumbnail in the third gallery section (it is circled in red below, while the gallery section is in rollover state, just for the purpose of showing it here). The text for this image should be <em>&#8220;Empty silos.&#8221; </em></p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_102.jpg" alt="The sixth thumbnail in the third gallery." width="368" height="163" /></p>
<p>Since the user has clicked the third gallery, the value of <code>clickedGallery</code> is 2, because they start from zero. The first iteration (when <code>i</code> equals 0) goes like this:</p>
<p class="ascode">descPosition += imagesInGallery[i];<br />
0 += imagesInGallery[0];<br />
0 += 5;<br />
5</p>
<p>So the value of <code>descPosition</code> is now 5. Why? Because the array <code>imagesInGallery</code> stores values which correspond to <strong>the number of images in each gallery section.</strong> In my example, they are as follows, from the first to last gallery section: 5,6,19,9,7 (corresponding to <em>architecture</em>, <em>essays</em>, <em>factory</em>, <em>monochrome</em> and <em>nature</em> sections, respectively). The point is that <strong>you have to arrive to the gallery section which the user has selected.</strong></p>
<p>Ok, here comes the next loop iteration, when <code>i</code> equals 1.</p>
<p class="ascode">descPosition += imagesInGallery[i];<br />
5 += imagesInGallery[1];<br />
5 += 6;<br />
11</p>
<p>The value of <code>descPosition</code> is now 11. Why? Simple. Because the loop has come to en and. Once <code>i</code> has reached the value of 1, <strong>the next iteration won&#8217;t be performed because the condition won&#8217;t validate any more</strong>: when <code>i</code> equals 2, the condition <code>i &lt; clickedGallery</code> is <strong>false</strong>, because <code>clickedGallery</code> equals 2, in this particular example.</p>
<p>And after that, the next line is executed, which updates the value of <code>descPosition</code>. Flash has arrived at the third gallery section, but now it must find the description <strong>inside this particular section</strong>. This boils down to adding a number until you reach the matching description.</p>
<p class="ascode">descPosition = descPosition+Number(bigNumber)-1;</p>
<p>Still using the example above, the equation would be calculated like this:</p>
<p class="ascode">descPosition = descPosition+Number(bigNumber)-1;<br />
descPosition = 11+Number(6)-1;<br />
descPosition = 11+6-1;<br />
descPosition = 16;</p>
<p>First, <code>bigNumber</code> had to be <strong>converted into a numerical value</strong> (from a String type to a Number type), because <strong>it was a simple text character,</strong> not a numerical value, since it was pulled out of current big image&#8217;s name.</p>
<p>Then, one is substracted from it, since I chose to give the thumbnails (and subsequently, the big images too) the numbers starting from 1 and not 0.</p>
<p>And there you go! The right description is really chosen: it is the 17th description in the <code>descriptions</code> array, placed at number 16, because the counting inside an array starts from 0. In this case, it is <em>&#8220;Empty silos.&#8221;</em> And that&#8217;s what precisely the next line of code is about: pulling out this description from the <code>descriptions</code> array and putting it inside the <code>imageDesc</code> variable.</p>
<p class="ascode"><span class="indent1">imageDesc = descriptions[descPosition];</span></p>
<p>And now for the <strong>else</strong> part of the conditional statement:</p>
<p class="ascode">} else {<br />
<span class="indent1">imageDesc = descriptions[Number(bigNumber)-1];</span><br />
}</p>
<p>It is used when the user has clicked on the <strong>first gallery section</strong>. No looping is necessary here, because this section&#8217;s descriptions are right at the beginning of the <code>descriptions</code> array. And that&#8217;s why the image description is pulled out from the array in a single line of code.</p>
<p>The description of the big image is subsequently displayed in the big dynamic text field below it:</p>
<p class="ascode">descText.text = imageDesc;</p>
<p>That&#8217;s it for the thumbnail&#8217;s <strong>onPress</strong> event handler. The one line of code that is executed outside this event handler function, but inside the <code>thumbClickable()</code> function is the following:</p>
<p class="ascode">currentThumbnail.enabled = false;</p>
<p>&#8230;which disables the thumbnail until all of them are loaded for the current gallery section. And here come now the two functions that disable and enable the clickability of the thumbnails.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<p>The first one, <code>disableThumbs()</code> serves to <strong>turn off the clickability of the thumbnails. </strong>This function is invoked whenever the user clicks on a thumbnail and the big image starts to load.</p>
<p class="ascode">function disableThumbs():Void {<br />
<span class="indent1">for (i=0; i&lt;howManyImages; i++) {</span><br />
<span class="indent2">thumbsDisplayer[&quot;thumbnail&quot;+(i+1)].enabled = false;</span><br />
<span class="indent1">}</span><br />
}</p>
<p>How does it work? It uses a <code>for</code> loop <strong>to loop through all the thumbnails.</strong> It will loop as many times as there are thumbnails in the selected gallery section (<code>i &lt; howManyImages</code>). Then, they are disabled one by one via turning their <code>enabled</code> property to <code>false</code>. Each thumbnail is accessed through the expression <code>thumbsDisplayer["thumbnail"+(i+1)]</code>. Why <code>i+1</code>? Well, again, I repeat, I have named the thumbnails <em>thumbnail1</em>, <em>thumbnail2</em>, etc, while the starting value of <code>i</code> in the loop is 0.</p>
<p>The function that restores the clickability of the thumbnails,  <code>enableThumbs()</code>,  works in the exact same way, the only difference being the <code>enabled</code> property turned to <code>true</code> this time. This function is invoked either when the user clicks on a gallery section button in the menu and all the thumbnails have been successfully loaded or when the big image was clicked, closed and the thumbnails for the selected section have appeared again.</p>
<p class="ascode">function enableThumbs():Void {<br />
<span class="indent1">for (i=0; i&lt;howManyImages; i++) {</span><br />
<span class="indent2">thumbsDisplayer[&quot;thumbnail&quot;+(i+1)].enabled = true;</span><br />
<span class="indent1">}</span><br />
}</p>
<p>Allright, that&#8217;s it for the thumbnails. But what about the big image? It has to be made clickable, for the user to be able to close it once she or he wishes to return to the thumbnails. That&#8217;s what the <code>bigClickable()</code> function is here for.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<p><span class="step">12.9</span> <strong>Making the big image clickable</strong></p>
<p>Inside the <code>bigClickable()</code> function, the big image&#8217;s <strong>onPress</strong> event handler function is defined.</p>
<p class="ascode">function bigClickable():Void {<br />
<span class="indent1">displayBigImage.onPress = function() {</span><br />
<span class="indent2">removeMovieClip(this);</span><br />
<span class="indent2">enableThumbs();</span><br />
<span class="indent2">descText.text = galleryIntros[clickedGallery];</span><br />
<span class="indent1">};</span><br />
}</p>
<p>The line</p>
<p class="ascode">removeMovieClip(this);</p>
<p>removes the big image with the <code>removeMovieClip()</code> method, inside the parenthesis of which is the movie clip destined for removal. The keyword <code>this</code> points to <strong>the big image itself</strong>, since it is placed inside its <code>onPress</code> event handler function.</p>
<p>After that , the <code>enableThumbs()</code> function call is made. So, the thumbnails will be made clickable again, since the big image has been removed and they can be seen again. You probably noticed that I never made any code that would hide the thumbnails, because the big image effectively covers them all, even when there are twenty of them present. That&#8217;s just how I solved the problem, of course, if you wish, you may choose to hide them.</p>
<p>Lastly, the  description text is reverted to the one that describes the selected gallery section.</p>
<p class="ascode">descText.text = galleryIntros[clickedGallery];</p>
<p>OK! Let me show you now how that nice alpha fade-in effect was achieved.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<p><span class="step">12.10</span> <strong>Fading in the loaded big image</strong></p>
<p>Why go for a simple image appearance when there is eye-candy like the alpha fading in effect at your disposal? <img src='http://flashexplained.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p class="ascode">function fadeIn():Void {<br />
<span class="indent1">target.onEnterFrame = function():Void  {</span><br />
<span class="indent2">this._alpha += 10;</span><br />
<span class="indent2">if (this._alpha&gt;=100) {</span><br />
<span class="indent2">delete this.onEnterFrame;</span><br />
<span class="indent2">this._alpha = 100;</span><br />
<span class="indent2">}</span><br />
<span class="indent1">};</span><br />
}</p>
<p>This function consists of an <strong>onEnterFrame</strong> movie clip event handler. This particular movie clip event is used very often because it makes possible for actions to be performed repeatedly. To be more exact, every line of code contained inside an onEnterFrame event handler will be executed as many times per second as your movie speed is set to. So, if your movie speed is set to 30 fps, the code inside the onEnterFrame event handler will be run 30 times in a second. Ideal for a fade-in effect!</p>
<p>What happens inside is that the <strong><code>_alpha</code></strong> property (transparency) of the target movie clip, into which the big image has been loaded, is <strong>increased by 10</strong> each time the event fires.</p>
<p class="ascode">this._alpha += 10;</p>
<p>Remember that the target movie clip&#8217;s <code>_alpha</code> property was set to 0 (total transparency, i.e. invisibility) once the <code>onLoadInit()</code> function (one of the two preloading functions) saw that the loaded file was the big image.</p>
<p>And once <code>_alpha</code> becomes <strong>equal to or greater than 100</strong> (<code>this._alpha &gt;= 100</code>), the <strong>onEnterFrame event handler is deleted</strong> and the alpha set to 100.</p>
<p class="ascode">if (this._alpha &gt;= 100) {<br />
<span class="indent1">delete this.onEnterFrame;</span><br />
<span class="indent1">this._alpha = 100;</span><br />
}</p>
<p>The keyword <code>this</code> inside the onEnterFrame event handler function points to the <code>target</code> movie clip, because it is placed inside an event handler function associated with it (<code>target.onEnterFrame</code>). This function is invoked once the image has been fully loaded.</p>
<p>And now, the gallery menu scrolling functionality with easing effect is explained. Yes, you are nearing the end of this tutorial :-)!</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<p><span class="step">12.11</span> <strong>Creating the scrolling functionality for the gallery sections menu</strong></p>
<p>I have made an example just for the purpose of showing you how the menu will look like when there are plenty of sections inside it. The section buttons in the example below are not clickable, but the menu is perfectly scrollable. Click on the down button to try it and then the up button when it appears!</p>

<object	type="application/x-shockwave-flash"
			data="http://www.flashexplained.com/img/actionscript/media/menu-easing-scrolling-example.swf"
			width="272"
			height="452">
	<param name="movie" value="http://www.flashexplained.com/img/actionscript/media/menu-easing-scrolling-example.swf" />
</object>
<p>The big function that follows, <code>enableGalleryNavigation()</code>, is made of two main parts: the definitions of <strong>onPress event handler functions </strong>for the two buttons that serve for scrolling the menu: <strong>menuDown</strong> and <strong>menuUp</strong>. Just as a reminder, here is a screenshot of these two buttons:</p>
<p><img src="http://www.flashexplained.com/img/actionscript/ig/ig_103.gif" alt="The buttons for scrolling the gallery section menu up and down." width="199" height="29" /></p>
<p class="ascode">function enableGalleryNavigation():Void {<br />
menuDown.onPress = function() {<br />
<span class="indent1">if (firstLook) {</span><br />
<span class="indent2">menuUp._alpha = 100;</span><br />
<span class="indent2">menuUp.enabled = true;</span><br />
<span class="indent2">var firstLook:Boolean = false;</span><br />
<span class="indent1">}</span><br />
<span class="indent1">var menuTop:Number = menuButtons._height-Math.abs(menuButtons._y);</span><br />
<span class="indent1">if (menuButtons._y&lt;=0 &amp;&amp; menuTop&gt;=galleryMask._height) {</span><br />
<span class="indent2">var targetPos:Number = menuButtons._y-galleryMask._height;</span><br />
<span class="indent2">menuDown.enabled = false;</span><br />
<span class="indent2">menuUp.enabled = false;</span><br />
<span class="indent2">menuButtons.onEnterFrame = function():Void  {</span><br />
<span class="indent2">menuButtons._y += (targetPos-menuButtons._y)/menuSpeed;</span><br />
<span class="indent2">if (menuButtons._y&lt;=(targetPos+0.8)) {</span><br />
<span class="indent2">menuButtons._y = Math.round(targetPos);</span><br />
<span class="indent2">delete menuButtons.onEnterFrame;</span><br />
<span class="indent2">menuDown.enabled = true;</span><br />
<span class="indent2">menuUp.enabled = true;</span><br />
<span class="indent2">}</span><br />
<span class="indent2">};</span><br />
<span class="indent1">}</span><br />
};<br />
menuUp.onPress = function() {<br />
<span class="indent1">var menuTop:Number = menuButtons._height-Math.abs(menuButtons._y);</span><br />
<span class="indent1">if (menuButtons._y&lt;0 &amp;&amp; menuTop&gt;0) {</span><br />
<span class="indent2">var targetPos:Number = menuButtons._y+galleryMask._height;</span><br />
<span class="indent2">menuDown.enabled = false;</span><br />
<span class="indent2">menuUp.enabled = false;</span><br />
<span class="indent2">menuButtons.onEnterFrame = function():Void  {</span><br />
<span class="indent2">menuButtons._y += (-menuButtons._y+targetPos)/menuSpeed;</span><br />
<span class="indent2">if (menuButtons._y&gt;=(targetPos-0.8)) {</span><br />
<span class="indent2">menuButtons._y = Math.round(targetPos);</span><br />
<span class="indent2">delete menuButtons.onEnterFrame;</span><br />
<span class="indent2">menuDown.enabled = true;</span><br />
<span class="indent2">menuUp.enabled = true;</span><br />
<span class="indent2">}</span><br />
<span class="indent2">};</span><br />
<span class="indent1">}</span><br />
};<br />
}</p>
<p>Let&#8217;s see how the functionality of the <strong>menuDown</strong> button is set up. To understand what is going on inside the function, keep in mind the following facts:</p>
<ol>
<li>In <a href="http://flashexplained.com/basics/understanding-how-the-coordinate-system-in-flash-works/">Flash coordinate system</a>, the vertical direction <strong>(Y)</strong> is positive downwards. This means the further you go down from the origin point, the bigger the positive value of an object&#8217;s Y coordinate.</li>
<li>Each movie clip has its own independent coordinate system. The origin of this coordinate system is the movie clip&#8217;s registration point.</li>
</ol>
<p class="ascode">menuDown.onPress = function() {<br />
if (firstLook) {<br />
<span class="indent1">menuUp._alpha = 100;</span><br />
<span class="indent1">menuUp.enabled = true;</span><br />
<span class="indent1">firstLook = false;</span><br />
}<br />
var menuTop:Number = menuButtons._height-Math.abs(menuButtons._y);<br />
if (menuButtons._y&lt;=0 &amp;&amp; menuTop&gt;=galleryMask._height) {<br />
<span class="indent1">var targetPos:Number = menuButtons._y-galleryMask._height;</span><br />
<span class="indent1">menuDown.enabled = false;</span><br />
<span class="indent1">menuUp.enabled = false;</span><br />
<span class="indent1">menuButtons.onEnterFrame = function():Void  {</span><br />
<span class="indent2">menuButtons._y += (targetPos-menuButtons._y)/menuSpeed;</span><br />
<span class="indent2">if (menuButtons._y&lt;=(targetPos+0.8)) {</span><br />
<span class="indent2">menuButtons._y = Math.round(targetPos);</span><br />
<span class="indent2">delete menuButtons.onEnterFrame;</span><br />
<span class="indent2">menuDown.enabled = true;</span><br />
<span class="indent2">menuUp.enabled = true;</span><br />
<span class="indent2">}</span><br />
<span class="indent1">};</span><br />
}<br />
};</p>
<p>The first thing inside the event handler function is an <code>if</code> <strong>conditional statement</strong> which serves <strong>only to activate the menuUp button.</strong> If you remember, the menuUp button is <strong>invisible</strong> in the beginning, to avoid confusing the user. Once the menuDown button has been clicked, its counterpart will appear and the <code>if</code> statement will never be used again, because the condition will yield as false.</p>
<p class="ascode">if (firstLook) {<br />
<span class="indent1">menuUp._alpha = 100;</span><br />
<span class="indent1">menuUp.enabled = true;</span><br />
<span class="indent1">firstLook = false;</span><br />
}</p>
<p>The condition <code>if (firstLook)</code> translates as <code>if (firstLook == true)</code>. And when the <strong>menuDown button</strong> has been <strong>clicked for the first time</strong>, this condition will yield as <strong>true</strong>, because the value of the variable <code>firstLook</code> has been set as true at the very beginning of your code (when all the variables were defined).</p>
<p>So, the code between the curly braces, <code>{</code> and <code>}</code>, will be run. It restores the button&#8217;s alpha (transparency) property to 100, meaning full opaqueness. After that, the button is enabled (it can be clicked).</p>
<p class="ascode">menuUp._alpha = 100;<br />
menuUp.enabled = true;</p>
<p>After that, the variable <code>firstLook</code> is set to <code>false</code> and that&#8217;s why the <code>if</code> statement will be ignored every subsequent time that the menuDown button is clicked: the other button has appeared and that&#8217;s it.</p>
<p class="ascode">firstLook = false;</p>
<p>Next, the <strong>menuTop</strong> variable is defined. Keep in mind that the <strong>menuButtons</strong> variable is <strong>the shortcut for the buttonsHolder_mc movie clip</strong>, which is itself situated inside the galleryMenu_mc movie clip. So, the <strong>menuButtons</strong> movie clip is the one into which all the gallery section buttons were attached from the Library.</p>
<p class="ascode">var menuTop:Number = menuButtons._height - Math.abs(menuButtons._y);</p>
<p>The value of the <code>menuTop</code> variable is the <strong>lowest point of your menu</strong>, all section buttons included. I called it menuTop because the Y coordinate values increase when going down, that&#8217;s why. This value is obtained by <strong>substracting</strong> the <strong>absolute value</strong> (meaning the number itself, whether positive or negative, it will be converted to a positive value) of the <strong>vertical position</strong> (<code>_y</code>) of the <strong>menuButtons</strong> movie clip from its <strong>height</strong>. This value will be used to scroll the menu (to move it) properly, without fear that it will disappear by going off the stage etc.</p>
<p>Next comes an <code>if</code> conditional statement that checks for two things:</p>
<ul>
<li>If the menuButtons vertical position is less than or equal to zero (<code>menuButtons._y &lt;= 0</code>) and</li>
<li>If the value of menuTop is greater than or equal to the height of the galleryMask movie clip, the one that serves as the mask for the menu buttons (<code>menuTop &gt;= galleryMask._height</code>).</li>
</ul>
<p class="ascode">if (menuButtons._y &lt;= 0 &amp;&amp; menuTop &gt;= galleryMask._height) {</p>
<p>These two conditions ensure that:</p>
<ul>
<li>The menu can only be scrolled down if its position is lesser than or equal to zero.</li>
<li>The menu won&#8217;t be scrolled down if its lower (menuTop) edge&#8217;s coordinate is lesser than the lower edge of the mask.</li>
</ul>
<p>So, if these conditions have been met, the menu will be scrolled down, thanks again to an <strong>onEnterFrame</strong> event handler function and a few variables defined before it is executed. The variable that gets defined is the following:</p>
<p class="ascode"><span class="indent1">var targetPos:Number = menuButtons._y - galleryMask._height;</span></p>
<p>The <code>targetPos</code> variable is a reference point up to which the menu will be scrolled. Think of it as an anchor towards which the menu is pulled. Its value is obtained by substracting the <strong>height of the mask</strong> from the <strong>position of the menu buttons</strong>. It makes sense: you have to scroll your menu by the height of its mask, so that each time the buttons below the current ones appear.</p>
<p>Next, both buttons that serve for scrolling the menu (<strong>menuDown</strong> and <strong>menuUp</strong>) are disabled just before the scrolling begins. You don&#8217;t want your menu to be moved up and down without control — it is best to lock it until it has reached the <strong>targetPos</strong> coordinate.</p>
<p class="ascode"><span class="indent1">menuDown.enabled = false;</span><br />
<span class="indent1">menuUp.enabled = false;</span></p>
<p>And now comes the <strong>onEnterFrame</strong> event handler:</p>
<p class="ascode"><span class="indent1">menuButtons.onEnterFrame = function():Void  {</span><br />
<span class="indent2">menuButtons._y += (targetPos-menuButtons._y)/menuSpeed;</span><br />
<span class="indent2">if (menuButtons._y&lt;=(targetPos+0.8)) {</span><br />
<span class="indent2">menuButtons._y = Math.round(targetPos);</span><br />
<span class="indent2">delete menuButtons.onEnterFrame;</span><br />
<span class="indent2">menuDown.enabled = true;</span><br />
<span class="indent2">menuUp.enabled = true;</span><br />
<span class="indent2">}</span><br />
<span class="indent1">};</span></p>
<p>The code line that makes the menu move is the one that adds a value to the menuButtons&#8217; Y coordinate each time the onEnterFrame event is fired:</p>
<p class="ascode">menuButtons._y += (targetPos-menuButtons._y)/menuSpeed;</p>
<p>Remember that the addition assignment operator (<code>+=</code>) adds the value on its right side to the cuurent value of the variable on its left side. And what&#8217;s added is the result of substracting the position of the menu section buttons from the target position point, divided by menu speed. As the menu approaches the target position, the distance is smaller each time and there you have the easing effect. Remember that <strong>the lower the value of menuSpeed, the quicker the menu will move.</strong> I found 6 to be an optimal value in combination with the speed of the SWF, which was set to 30 fps at the beginning.</p>
<p>And each time the menu approaches the target point, a check must be made to see if the point in question has actually been reached. This is done through an if conditional statement, of course.</p>
<p class="ascode">if (menuButtons._y &lt;= (targetPos+0.8)) {</p>
<p>The <code>if</code> conditional checks if the menuButtons movie clip&#8217;s vertical position is lesser than or equal to (<code>&lt;=</code>) the target position plus 0.8 pixels (<code>targetPos+0.8</code>). You have to make this so as a safeguard against waiting too long for the menu to reach the target position. This easing method is described in more detail in my <a href="http://flashexplained.com/actionscript/making-a-sliding-image-mask/">sliding image mask</a> tutorial.</p>
<p>And, once that condition is fulfilled (meaning that the menu has reached the target position),  <strong>its position is fixed in place</strong> by setting it definitely to the <strong>rounded</strong> <code>targetPos</code> value. I recommend that you always do that in cases like this, because objects placed on round pixels are rendered much better than in other cases. Well, Flash 8 renders graphics greatly, but ensuring this with round coordinates doesn&#8217;t hurt.</p>
<p class="ascode">menuButtons._y = Math.round(targetPos);</p>
<p>Then, of course, you should <strong>delete the onEnterFrame event handler</strong>, because it has fulfilled its purpose and it is good to take load of the user&#8217;s computer processor.</p>
<p class="ascode">delete menuButtons.onEnterFrame;</p>
<p>After that, the buttons for scrolling the menu up and down are enabled again.</p>
<p class="ascode">menuDown.enabled = true;<br />
menuUp.enabled = true;</p>
<p>As for the <strong>onPress</strong> event handler function that serves to enable <strong>scrolling the menu up</strong>, the differences are only in the conditions and some other details.</p>
<p class="ascode">menuUp.onPress = function() {<br />
<span class="indent1">var menuTop:Number = menuButtons._height-Math.abs(menuButtons._y);</span><br />
<span class="indent1">if (menuButtons._y&lt;0 &amp;&amp; menuTop&gt;0) {</span><br />
<span class="indent2">var targetPos:Number = menuButtons._y+galleryMask._height;</span><br />
<span class="indent2">menuDown.enabled = false;</span><br />
<span class="indent2">menuUp.enabled = false;</span><br />
<span class="indent2">menuButtons.onEnterFrame = function():Void  {</span><br />
<span class="indent2">menuButtons._y += (-menuButtons._y+targetPos)/menuSpeed;</span><br />
<span class="indent2">if (menuButtons._y&gt;=(targetPos-0.8)) {</span><br />
<span class="indent2">menuButtons._y = Math.round(targetPos);</span><br />
<span class="indent2">delete menuButtons.onEnterFrame;</span><br />
<span class="indent2">menuDown.enabled = true;</span><br />
<span class="indent2">menuUp.enabled = true;</span><br />
<span class="indent2">}</span><br />
<span class="indent2">};</span><br />
<span class="indent1">}</span><br />
};</p>
<p>The main <code>if</code> conditional statement checks if the position of menu buttons movie clip is lesser than zero and if the lower edge point of the menu buttons movie clip is greater than zero. This time, the target position is determined by <strong>adding</strong> the height of the mask to the menuButtons&#8217; current position.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>Conclusion</h3>
<p>Congratulations on going through to the end of this tutorial and learning very much about ActionScript! I am glad that you have followed me until the end. There are some things I want to tell you.</p>
<p>First, this gallery is modular, expandable and pretty powerful. Of course, it could have been done in many other ways: having many thumbnails in each section instead of a maximum of 20, scrolling thorough thumbnails etc. But that would be another gallery.</p>
<p>The main purpose of my tutorial is to teach you to build a powerful dynamic image gallery by combining ActionScript and XML so that you can also build other galleries, which will have different interfaces and menus. I wanted you to show how to handle the main elements of such image galleries: XML, preloading, navigation, visual effects, etc. I hope that you have learned much and that you will use the knowledge in other galleries and create cool Flash websites.</p>
<p>Note also that if you are going to have many, many images (let&#8217;s say, about 100 sections), the XML file is going to be heavy. In that case, you will need to preload the XML too, using the XML object&#8217;s getBytesLoaded and getBytesTotal methods. Also, note that in this tutorial&#8217;s code I have limited the number of pictures to 1000. This is more than enough for any practical purposes. If you need even more than that, just change the if/else if/else statement inside the enableButtons function.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>Afterword</h3>
<p>I have invested much time, energy and work into the creation of this tutorial, because I want you to learn to create cool an amazing stuff in Flash, for free, and with as clear and detailed explanations as possible! Were it printed inside a paper book, the tutorial would be more than 80 pages long! And it&#8217;s <strong>free</strong>.</p>
<p>If you find it useful, please spread the word about flashexplained.com, or better yet, link to flashexplained.com! I will appreciate it very much.</p>
<p>As for any questions considering this tutorial, please remember that I am not answering any such questions by e-mail.</p>
<p>You can download the source files for this lesson below, comprising the entire folder structure (without the images, of course). See you in other <a href="http://www.flashexplained.com/category/actionscript/">ActionScript</a> tutorials!</p>
<p><a class="newlinkexp" href="http://www.flashexplained.com/img/actionscript/materials/AS_XML_image_gallery.zip">Download all the source files here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashexplained.com/actionscript/making-the-ultimate-dynamic-image-gallery-in-flash-8/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Coming soon</title>
		<link>http://flashexplained.com/news/coming-soon/</link>
		<comments>http://flashexplained.com/news/coming-soon/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 10:59:05 +0000</pubDate>
		<dc:creator>Luka</dc:creator>
		
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://flashexplained.com/?p=855</guid>
		<description><![CDATA[Hello everybody,
I am back in Europe. My ISP sucks so you&#8217;ll have to wait a little bit. But, here is a little tease of the tutorials that I am going to create and post soon:

Shape tweens in Flash CS3 explained (how to animate outlines, fills, colors)
How to animate cool effects like blurring, glowing etc.
How to [...]]]></description>
			<content:encoded><![CDATA[<p>Hello everybody,</p>
<p>I am back in Europe. My ISP sucks so you&#8217;ll have to wait a little bit. But, here is a little tease of the tutorials that I am going to create and post soon:</p>
<ul>
<li>Shape tweens in Flash CS3 explained (how to animate outlines, fills, colors)</li>
<li>How to animate cool effects like blurring, glowing etc.</li>
<li>How to create a powerful, dynamic image gallery</li>
</ul>
<p>Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://flashexplained.com/news/coming-soon/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A brief wait &amp; new Flash CS3 tutorials</title>
		<link>http://flashexplained.com/news/a-brief-wait-new-flash-cs3-tutorials/</link>
		<comments>http://flashexplained.com/news/a-brief-wait-new-flash-cs3-tutorials/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 12:25:34 +0000</pubDate>
		<dc:creator>Luka</dc:creator>
		
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://flashexplained.com/?p=839</guid>
		<description><![CDATA[Hi everyone,
This is a flashexplained.com update: I am currently moving from Africa back to Europe. This being said, I won&#8217;t be able to reply to your comments and questions until somewehere after November 15th, once I settle down. I have so much things to do - moving from one continent to another is no small [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone,</p>
<p>This is a <strong>flashexplained.com update</strong>: I am currently moving from Africa back to Europe. This being said, I won&#8217;t be able to reply to your comments and questions until somewehere after <strong>November 15th</strong>, once I settle down. I have so much things to do - moving from one continent to another is no small thing.</p>
<p>Also, there will be just one or two more tutorials for Flash 8, and after that, everything will be made freshly for Flash CS3. Expect new tutorials during the second half of November. In the meantime, enjoy the Flash tutorials and keep on learning.</p>
<p>Luka Maras</p>
]]></content:encoded>
			<wfw:commentRss>http://flashexplained.com/news/a-brief-wait-new-flash-cs3-tutorials/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flash CS3 animation basics: Motion tween</title>
		<link>http://flashexplained.com/animation/flash-cs3-animation-basics-motion-tween/</link>
		<comments>http://flashexplained.com/animation/flash-cs3-animation-basics-motion-tween/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 20:31:17 +0000</pubDate>
		<dc:creator>Luka</dc:creator>
		
		<category><![CDATA[Animation]]></category>

		<category><![CDATA[easing]]></category>

		<category><![CDATA[keyframes]]></category>

		<category><![CDATA[motion tween]]></category>

		<guid isPermaLink="false">http://flashexplained.com/?p=823</guid>
		<description><![CDATA[This lesson will be the first in a series where all the animation techniques in Flash CS3 will be explained in detail. Motion tween animation is one of the most widely used in Flash, so it makes sense to begin with it. You are going to learn:

How to draw a basketball using the great drawing [...]]]></description>
			<content:encoded><![CDATA[<p>This lesson will be the first in a series where all the animation techniques in Flash CS3 will be explained in detail. Motion tween animation is one of the most widely used in Flash, so it makes sense to begin with it. You are going to learn:</p>
<ul class="learningpoints">
<li>How to draw a basketball using the great drawing tools available,</li>
<li>How to create a movieclip symbol, which is a must for any motion tween animation,</li>
<li>How to create keyframes,</li>
<li>How to create easing effect for better realism and more.</li>
</ul>
<p>You can see the example of the animation you are going to create below. It is the classic example: an animated, bouncing ball.</p>

<object	type="application/x-shockwave-flash"
			data="http://www.flashexplained.com/img/animation/media/flashcs3-motion-tween-example.swf"
			width="550"
			height="400">
	<param name="movie" value="http://www.flashexplained.com/img/animation/media/flashcs3-motion-tween-example.swf" />
</object><br />
<span id="more-823"></span></p>
<h3>1. Creating the basketball movieclip</h3>
<p><span class="step">1.1</span> Open a new Flash document by selecting <strong>File &gt; New</strong>. In the window that opens, select <strong>Flash File (ActionScript 3.0)</strong> and click <strong>OK</strong>.</p>
<p><span class="step">1.2</span> Click on the Rectangle tool icon and hold your mouse until the menu appears. Select the Oval tool <strong>(O)</strong>.</p>
<p><img src="/img/animation/cs3mt/cs3mt_001.gif" alt="Selecting the Oval tool in Flash CS3." width="241" height="222" /></p>
<p><span class="step">1.3</span> Go to the the bottom of the Tools panel and block the stroke color, because you won&#8217;t need it here. Just click on the small color square near the pencil icon and when the palette shows up, click the <strong>No color</strong> button (see it in the image below, on the right). For the fill, choose any color you like.</p>
<p><img src="/img/animation/cs3mt/cs3mt_002.gif" alt="Removing the stroke color." width="337" height="267" /></p>
<p><span class="step">1.4</span> At the very bottom of the same panel, check if <strong> Object Drawing</strong> and <strong>Snap to Objects</strong> options are unselected (turned off).</p>
<p><img src="/img/animation/cs3mt/cs3mt_003.gif" alt="Unselecting the object drawing and snap to objects options in Flash CS3." width="203" height="151" /></p>
<p><span class="step">1.5</span> Click anywhere on the stage with the Oval tool <strong>(O)</strong>, start dragging your mouse and draw a circle.</p>
<p><img src="/img/animation/cs3mt/cs3mt_004.gif" alt="A flat color circle drawn on stage in Flash." width="272" height="201" /></p>
<p><span class="step">1.6</span> <strong>Select</strong> the circle by clicking on it with the Selection tool <strong>(V)</strong>. Go to the Property inspector and enter the new dimensions for the circle: <strong>85 px</strong>.</p>
<p><img src="/img/animation/cs3mt/cs3mt_005.gif" alt="Adjustin the dimensions of a drawn shape." width="311" height="190" /></p>
<p><span class="step">1.7</span> Deselect the circle by clicking anywhere on the stage with the Selection tool <strong>(V)</strong>.</p>
<p><span class="step">1.8</span> Select the Paint bucket tool <strong>(K)</strong> and go over to the <strong>Color</strong> panel.</p>
<p><span class="step">1.9</span> In the Colors panel, do the following:</p>
<ul>
<li>Click the paint bucket icon to select the fill color.</li>
<li>Choose <strong>Radial</strong> in the <strong>Type</strong> drop-down menu.</li>
<li>Add two more <strong>crayons</strong> (the little colored squares near the gradient bar). Do this by simply clicking anywhere between the two existing ones, the black and the white.</li>
</ul>
<p><img src="/img/animation/cs3mt/cs3mt_006.jpg" alt="Beginning to adhust the radial fill." width="333" height="304" /></p>
<p><span class="step">1.10</span> Now, <strong>click and drag</strong> the first crayon a little bit to the right and change its color to <strong>#EFA201</strong>.</p>
<p><img src="/img/animation/cs3mt/cs3mt_007.jpg" alt="Adding crayons to the radial fill in Flash CS3." width="213" height="133" /></p>
<p><span class="step">1.11</span> Move the other crayons as well, so that they match the positions shown in the image below. Also, change their colors to (from left to right):</p>
<ul>
<li>#EFA201</li>
<li>#FF5B15</li>
<li>#FF5B15</li>
<li>#000000</li>
</ul>
<p><img src="/img/animation/cs3mt/cs3mt_008.gif" alt="Hexadecimal color values of crayons for the radial color fill." width="251" height="85" /></p>
<p><span class="step">1.12</span> Using the still selected Paint bucket tool <strong>(K)</strong>, click on the circle to fill it with your newly made radial fill.</p>
<p><img src="/img/animation/cs3mt/cs3mt_009.jpg" alt="Filling the circle with the radial fill." width="293" height="144" /></p>
<p><span class="step">1.13</span> Select the Oval tool <strong>(O)</strong>. Go to the Property inspector and select a <strong>solid</strong>, <strong>black</strong> line with a <strong>thickness of 1</strong> for the stroke. Then <strong>block the fill color</strong> by choosing the no color option for it, just like you did before for the stroke color.</p>
<p><img src="/img/animation/cs3mt/cs3mt_010.jpg" alt="The options for the Oval tool in the Property inspector." width="443" height="127" /></p>
<p><span class="step">1.14</span> Draw an ellipse on the stage, like the one shown below.</p>
<p><img src="/img/animation/cs3mt/cs3mt_011.jpg" alt="An ellipse outline." width="318" height="185" /></p>
<p><span class="step">1.15</span> Select the Free transform tool <strong>(Q)</strong> and click on the ellipse with it to select it. Then rotate it. Do this by bringing your mouse over any of the corners, clicking and dragging.</p>
<p><img src="/img/animation/cs3mt/cs3mt_012.gif" alt="Rotating the ellipse." width="493" height="152" /></p>
<p><span class="step">1.16</span> Use the Selection tool <strong>(V)</strong> to:</p>
<ul>
<li>Select the ellipse and drag it over the circle.</li>
<li>Click on an empty area to deselect the ellipse.</li>
<li>Select the outer part of the ellipse, which is sticking out of the circle.</li>
<li>Delete this part by pressing either <strong>Delete</strong> or <strong>Backspace</strong> on your keyboard.</li>
</ul>
<p><img src="/img/animation/cs3mt/cs3mt_013.gif" alt="Adding a nice line to the basketball." width="550" height="106" /></p>
<p><span class="step">1.17</span> Play around with the oval tool to get a few more curves, add them to the circle until you have a nice looking basketball:</p>
<p><img src="/img/animation/cs3mt/cs3mt_014.gif" alt="A basketball drawn in Flash CS3." width="174" height="101" /></p>
<p><span class="step">1.18</span> Now, still using the Selection tool <strong>(V)</strong>, select the whole basketball. Click and drag around it to select all the fills and strokes too.</p>
<p><img src="/img/animation/cs3mt/cs3mt_015.gif" alt="Selecting a drawing." width="317" height="162" /></p>
<p><span class="step">1.19</span> Select <strong>Modify &gt; Convert to Symbol</strong> (or press <strong>F8</strong>) to convert this drawing into a movieclip symbol.</p>
<ul>
<li>Select <strong>Movie clip</strong> as type.</li>
<li>Call it <em>basketball</em> and click <strong>OK</strong>.</li>
</ul>
<p><img src="/img/animation/cs3mt/cs3mt_016.gif" alt="The creation of a movieclip symbol in Flash CS3." width="408" height="137" /></p>
<p>You&#8217;ll notice that a blue outline has appeared around your basketball. This is Flash telling you that this is a symbol and not a simple drawing.</p>
<p><span class="step">1.20</span> Go to the timeline and <strong>click on the little dot</strong> beneath the padlock to lock this layer. Then <strong>double-click</strong> on its name and rename it to <em>basketball</em>.</p>
<p><img src="/img/animation/cs3mt/cs3mt_017.gif" alt="Locking and renaming a layer." width="305" height="189" /></p>
<p><span class="step">1.21</span> Click on the <strong>Insert Layer</strong> button to make a new layer and call it <em>floor</em>.</p>
<p><img src="/img/animation/cs3mt/cs3mt_018.gif" alt="Inserting a fresh layer." width="305" height="189" /></p>
<p><span class="step">1.22</span> Click and drag the <em>floor</em> layer downwards, until you see a thick dotted line appear. Release your mouse button then.</p>
<p><img src="/img/animation/cs3mt/cs3mt_019.gif" alt="Dragging a layer to switch its position on the timeline." width="305" height="189" /></p>
<p><span class="step">1.23</span> The <em>floor</em> layer will now be beneath the <em>basketball</em> layer.</p>
<p><img src="/img/animation/cs3mt/cs3mt_020.gif" alt="The new layer hierarchy." width="305" height="189" /></p>
<p>This makes sense, because the basketball will bounce off the floor, so it has to be in a layer above it.</p>
<p><span class="step">1.24</span> Creating the floor is easy. Just select the Rectangle tool <strong>(R)</strong> and draw a nice rectangle at the bottom of the stage. Make sure it spans the stage from side to side.</p>
<p><img src="/img/animation/cs3mt/cs3mt_021.gif" alt="Drawing a simple rectangle in Flash." width="550" height="352" /></p>
<p>I used a linear gradient because I find it more real that way. I also removed the outline (stroke).</p>
<p><span class="step">1.25</span> <strong>Lock</strong> the <em>floor</em> layer. You won&#8217;t be adding anything inside it anymore. And it&#8217;s better to have it locked so you don&#8217;t put anything in it by accident. I always work like that.</p>
<p>Also, <strong>unlock</strong> the <em>basketball</em> layer.</p>
<p><img src="/img/animation/cs3mt/cs3mt_022.gif" alt="Locking a layer." width="285" height="171" /></p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>2. Making your first motion tween animation</h3>
<p><span class="step">2.1</span> Select the ball by clicking on it <strong>once</strong> with the Selection tool <strong>(V)</strong>. Move it upwards into the start position - somewhere near the top edge of the stage. You can move it either by clicking and dragging it with the Selection tool or by using the <strong>arrow keys</strong> on your keyboard.</p>
<p><img src="/img/animation/cs3mt/cs3mt_023.gif" alt="Placing the ball into the initial position." width="550" height="349" /></p>
<div class="note">
<p>When moving objects with arrow keys in Flash, pressing an arrow key moves your object by 1 pixel at a time. If you want to move it faster, just hold down <strong>Shift</strong> and then press the arrow key(s). Your object will then move by 10 pixels after each press of an arrow key.</p>
</div>
<p><span class="step">2.2</span> <strong>Right-click</strong> in <strong>frame 11</strong> of the <em>basketball</em> layer and select <strong>Insert Keyframe</strong> from the contextual menu.</p>
<p><img src="/img/animation/cs3mt/cs3mt_024.gif" alt="Inserting a new keyframe in the timeline in Flash CS3." width="550" height="170" /></p>
<p>&#8230;and a new keyframe will appear.</p>
<p><img src="/img/animation/cs3mt/cs3mt_025.gif" alt="A new keyframe just appeared." width="550" height="170" /></p>
<div class="note">
<p>A <strong>Keyframe</strong> is a point in your timeline where something changes. Whenever you want to create movement, or animate a property of a movie clip, add something, you must insert a Keyframe. On the other hand, a <strong>Frame</strong> is used to prolong the duration of a Keyframe, whenever you want it to last more, but without changes. You will see this in a moment.</p>
</div>
<p><span class="step">2.3</span> You should move the ball to a point where it will touch the floor. But you can&#8217;t see the floor now, because it exist only in the first frame of its layer. To change this, <strong>right-click</strong> on <strong>frame 11</strong> of the <em>floor</em> layer and select <strong>Insert Frame</strong>.</p>
<p><img src="/img/animation/cs3mt/cs3mt_026.gif" alt="Inserting a simple frame in your timeline." width="550" height="164" /></p>
<p>&#8230;here&#8217;s the result:</p>
<p><img src="/img/animation/cs3mt/cs3mt_027.gif" alt="A frame." width="550" height="164" /></p>
<p>As you can see, the frame is represented by a small rectangle in your timeline. This shows you that the first keyframe of the <em>floor</em> layer lasts until frame 11 without any change. It has been prolonged in duration by the addition of a simple frame. And that&#8217;s exactly what you need, because the floor needs to be seen at all times, together with the ball, but without any changes.</p>
<p>Also, notice that you have added a frame while this layer has been <strong>locked</strong>. That&#8217;s perfectly OK. You can add or remove frames and keyframes from a layer even while it&#8217;s locked. Since you won&#8217;t be making any modifications to the <em>floor</em> layer, it is best to keep it locked, thus preventing any possibility of accidentaly adding or removing something from it.</p>
<p><span class="step">2.4</span> <strong>Click</strong> on the <strong>second keyframe</strong> of the <em>basketball</em> layer to select it and then select the ball on the stage by clicking on it <strong>once</strong> with the Selection tool <strong>(V)</strong>.</p>
<p><img src="/img/animation/cs3mt/cs3mt_028.gif" alt="Selecting a keyframe and a movieclip." width="416" height="256" /></p>
<p><span class="step">2.5</span> Now that you have selected the basketball movieclip, move it towards the floor by using either the combination of <strong>Shift+down arrow</strong> on your keyboard (by far the easiest option) or with your mouse. I recommend using the keyboard, because you will move the ball straight down, while it is possible that you can accidentally move it left or right with your mouse. Since you need the ball to fall straight down, use your keyboard. Move it down to the floor.</p>
<p><img src="/img/animation/cs3mt/cs3mt_029.gif" alt="The ball has been moved down." width="550" height="430" /></p>
<p><span class="step">2.6</span> OK. You will now animate this ball. <strong>Right-click</strong> either on the first keyframe of the <em>basketball</em> layer or anywhere between the two keyframes and select the <strong>Create Motion Tween</strong> option from the contextual menu.</p>
<p><img src="/img/animation/cs3mt/cs3mt_030.gif" alt="Creating a Motion Tween animation in Flash CS3." width="504" height="169" /></p>
<p>If you have done everything as I&#8217;ve shown you up until now, you should see a continuous arrow appear between the two keyframes, on a magenta background.</p>
<p><img src="/img/animation/cs3mt/cs3mt_031.gif" alt="Your fist motion tween made in Flash CS3." width="504" height="169" /></p>
<p>The image above shows how a successful motion tween looks like in the timeline. If anything went wrong, the arrow would be <strong>discontinued</strong> (dashed). That&#8217;s how Flash tells you that something doesn&#8217;t click.</p>
<div class="note">
<p>To be able to make a successful motion tween animation, please note the following: You must use either a movieclip symbol (which is my favorite symbol, because of its versatility) or a graphic symbol. You cannot animate a simple drawing. If you try that, Flash will attempt to animate it, and you will get unexpected and bad results. Also, remember that for a motion tween to be successful, a single symbol must be present in the layer where the animation is taking place (either a movieclip or a graphic symbol). You can not have multiple symbols or a movieclip and some other drawings or objects in the same layer if you want to have a good motion tween animation.</p>
</div>
<p><span class="step">2.7</span> Test your Flash movie by selecting <strong>Control &gt; Test Movie</strong>.</p>
<p>You will see your ball falling to the floor again and again. This is standard Flash behavior - an animation will loop endlessly unless you stop it via ActionScript, but that is not important right now. As you certainly noticed, the ball is somewhat slow. Let&#8217;s speed up the animation. Close the test window by pressing the close button in its upper right corner, to return to the Flash authoring environment.</p>
<p><img src="/img/animation/cs3mt/cs3mt_033.gif" alt="Closing the testing movie window." width="550" height="454" /></p>
<p><span class="step">2.8</span> Select <strong>Modify &gt; Document</strong> to access the Document Properties window. Increase the <strong>Frame rate</strong> to <strong>24 fps</strong>. Click <strong>OK</strong>.</p>
<p><img src="/img/animation/cs3mt/cs3mt_034.gif" alt="Increasing the frame rate option." width="372" height="346" /></p>
<p><span class="step">2.9</span> Test your animation again by selecting <strong>Control &gt; Test Movie</strong>. You should see your ball move much faster now. This is the result of the frame rate increase. The abbreviation <strong>fps</strong> means <em>frames per second</em>. It is the number of frames the playhead in your Flash movie passes through in 1 second.</p>
<p>Fine. Close the test movie window now.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>3. Making the ball bounce</h3>
<p>Now, you are going to repeadetly insert new keyframes and change the position of the ball to be able to create the bouncing movement.</p>
<p><span class="step">3.1</span> To avoid having to prolong the duration of the first keyframe in the floor layer each time you are moving your ball around, insert a <strong>Frame</strong> in frame 80 of the <em>floor</em> layer. Do like you did before: <strong>right-click</strong> on the frame and select <strong>Insert Frame</strong>.</p>
<p><img src="/img/animation/cs3mt/cs3mt_035.gif" alt="Inserting a simple frame in the layer." width="440" height="191" /></p>
<p>You will easily remove any surplus frames later, don&#8217;t worry about it.</p>
<p><img src="/img/animation/cs3mt/cs3mt_036.gif" alt="A frame added at the far end of the timeline." width="440" height="191" /></p>
<p><span class="step">3.2</span> <strong>Right-click</strong> in <strong>frame 21</strong> and insert a <strong>Keyframe</strong> there. If you are not sure where you are in the timeline, just look below the layers. There, you can clearly see where you are. The image below shows you the number of your current keyframe circled in red.</p>
<p><img src="/img/animation/cs3mt/cs3mt_037.gif" alt="A third keyframe is inserted, in the layer where the ball will be animated." width="454" height="176" /></p>
<p><span class="step">3.3</span> Select the ball with the Selection tool <strong>(V)</strong>. You shoul place the ball upwards again, because it is supposed to rebound of the floor. But, this time, you should move it a little bit downwards. I moved it by 40 pixels downwards. Why is this so? Because you must simulate reality. And in the real world, the Earth&#8217;s gravity force pulls the ball so it never returns in its starting position, but always rebounds to a lower position than the last time.</p>
<p><img src="/img/animation/cs3mt/cs3mt_038.gif" alt="Moving the ball down to create more realism." width="349" height="438" /></p>
<p><span class="step">3.4</span> After you have positioned the ball, <strong>right-click</strong> between the <strong>2nd</strong> and <strong>3rd keyframes</strong> in the <em>basketball</em> layer and select <strong>Create Motion Tween</strong> from the contextual menu, just like you did for the first segment of your animation.</p>
<p><img src="/img/animation/cs3mt/cs3mt_039.gif" alt="Adding the second motion tween." width="440" height="175" /></p>
<p>Test your Flash movie again (<strong>Control &gt; Test Movie</strong>) and see how the ball is going up and down. Don&#8217;t be surprised if it suddenly disappears. This is because the <em>floor</em> layer lasts longer than the <em>basketball</em> layer in the timeline.</p>
<p><span class="step">3.5</span> You have to return the ball to the floor now, in a new keyframe. Instead of having to reposition it each time (on the floor, the ball will always land on the same spot) manually, you can accomplish this more easily.</p>
<p><strong>Right-click</strong> on the <strong>second keyframe</strong> in the <em>basketball</em> layer and select <strong>Copy Frames</strong> from the contextual menu.</p>
<p><img src="/img/animation/cs3mt/cs3mt_040.gif" alt="Copying a keyframe in Flash CS3." width="550" height="300" /></p>
<p><span class="step">3.6</span> OK, now <strong>right-click</strong> in <strong>frame 28</strong> and select <strong>Paste Frames</strong>.</p>
<p><img src="/img/animation/cs3mt/cs3mt_041.gif" alt="Pasting a copied keyframe into a new frame." width="550" height="318" /></p>
<p>In this new, 4th keyframe, the ball will be positioned exactly as it is in the 2nd keyframe. This is because when you copy a keyframe in Flash, all of its contents get copied too. Every single object inside it, with all of its properties (position, size, etc) gets copied.</p>
<p><span class="step">3.7</span> Create the 3rd <strong>motion tween</strong> animation by clicking between the 3rd and 4th keyframes and selecting it from the menu.</p>
<p><img src="/img/animation/cs3mt/cs3mt_042.gif" alt="The third motion tween." width="530" height="166" /></p>
<p>You certainly noticed that this segment of the animation, the third motion tween, is a little bit shorter than the previous ones. This is also to make it all look more real: since the Earth&#8217;s gravity pull is acting on the ball, there is now a shorter distance for it to go from the highest point to the floor. The ball&#8217;s fall gets shorter, so you have to make your motion tween shorter accordingly.</p>
<p><span class="step">3.8</span> Repeat the steps from 3.2 to 3.7, each time repositioning the ball in its upper position and just copying and pasting a keyframe for the &#8216;floor&#8217; position. Also, make the motion tween segment smaller each time. You can see how I did it below. The numbers at the bottom of the image indicate the keyframes in the timeline.</p>
<p><img src="/img/animation/cs3mt/cs3mt_043.gif" alt="The positions of the bouncing ball shown in relation to the timeline." width="550" height="215" /></p>
<p><span class="step">3.9</span> Test your movie (<strong>Control &gt; Test Movie</strong>) and see if you are satisfied with the result.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>4. Adding the easing effect to your motion tween animation</h3>
<p>The motion tweens you made so far are fine, but still the animation doesn&#8217;t look realistic. Why? Because currently the ball isn&#8217;t accelerating and decelerating. And the gravity pull does just that: In real life, while the ball is falling, it should be gaining in speed because of the gravitational pull. Meaning its speed should increase as it is approaching the ground. This is called <strong>acceleration</strong>.</p>
<p>Also, when bouncing back up, its speed should decrease, again because of the gravitational pull. As it is moving up, its slowing down. This is called <strong>deceleration</strong>.</p>
<p>Luckily, Flash has just got an option in store for you - the <strong>easing</strong> option - which is made for simulating acceleration and deceleration. Let me show you how to apply it to your current animation.</p>
<p><strong>Save your document</strong> before proceeding! Always remember to do that.</p>
<p><span class="step">4.1</span> Select the first keyframe in the <em>basketball</em> layer.</p>
<p><img src="/img/animation/cs3mt/cs3mt_044.gif" alt="Selecting the first keyframe amongst many." width="347" height="168" /></p>
<p><span class="step">4.2</span> Go to the Property Inspector. You will find the <strong>easing</strong> option on its left side. Click the little arrow next to it and a slider will appear. Drag it down until the value reaches <strong>-100</strong>. This is called <strong>easing in</strong> or accelerating.</p>
<p><img src="/img/animation/cs3mt/cs3mt_045.gif" alt="Setting the easing option." width="382" height="143" /></p>
<p><span class="step">4.3</span> Test your movie (<strong>Ctrl+Enter</strong> on a PC or <strong>Cmd+Return</strong> on a Mac) and watch how the ball accelerates towards the floor during the first segment of the animation.</p>
<p><span class="step">4.4</span> Back to the authoring environment (Flash working space), select the <strong>second keyframe</strong> by clicking on it.</p>
<p><img src="/img/animation/cs3mt/cs3mt_046.gif" alt="Selecting the second keyframe, where deceleration is going to happen." width="421" height="169" /></p>
<p><span class="step">4.5</span> This time, set the <strong>Ease</strong> option to <strong>100</strong>, which means <strong>easing out</strong> or decreasing speed (decelerating).</p>
<p><img src="/img/animation/cs3mt/cs3mt_047.gif" alt="Easing out a motion tween." width="382" height="143" /></p>
<p><span class="step">4.6</span> For each subsequent keyframe, you should set the easing option a value that&#8217;s smaller then the previous one, because the ball is losing power with each bounce. Here&#8217;s how you should set it to get a natural effect - a ball that slowly comes to a halt:</p>
<p><img src="/img/animation/cs3mt/cs3mt_048.gif" alt="Easing options for the whole animation." width="550" height="115" /></p>
<p>And that would be it. Test your movie to see the ball bouncing. You have just learned how to do a basic motion tween animation in Flash CS3, the difference between frames and keyframes, and how to achieve an easing effect. In next Flash CS3 animation lessons, I will explain to you how to animate shapes, morph them, how to animate effects and more.</p>
<p><a href="http://www.flashexplained.com/img/animation/materials/cs3-motion-tween-example.zip">Download the source file for this lesson</a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashexplained.com/animation/flash-cs3-animation-basics-motion-tween/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Glowing neon playback control buttons</title>
		<link>http://flashexplained.com/menus-interfaces/glowing-neon-playback-control-buttons/</link>
		<comments>http://flashexplained.com/menus-interfaces/glowing-neon-playback-control-buttons/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 02:00:34 +0000</pubDate>
		<dc:creator>Luka</dc:creator>
		
		<category><![CDATA[Menus & Interfaces]]></category>

		<category><![CDATA[effects]]></category>

		<category><![CDATA[neon glow]]></category>

		<guid isPermaLink="false">http://flashexplained.com/?p=813</guid>
		<description><![CDATA[In this easy lesson made for Flash 8 professional I will show you how to create a set of cool, neon glow playback control buttons easily. No other applications will be used to create these buttons, because Flash has so much power on its own! You will see:

How to use the basic shapes to create [...]]]></description>
			<content:encoded><![CDATA[<p>In this easy lesson made for <strong>Flash 8 professional</strong> I will show you how to create a set of cool, neon glow playback control buttons easily. No other applications will be used to create these buttons, because Flash has so much power on its own! You will see:</p>
<ul class="learningpoints">
<li>How to use the basic shapes to create the ones you need,</li>
<li>How to use the great blending filters in Flash 8 pro,</li>
<li>How to combine multiple filters and objects stacked upon one another, and some more.</li>
</ul>
<p>You can see the example of the sleek buttons below.</p>

<object	type="application/x-shockwave-flash"
			data="http://www.flashexplained.com/img/menus/media/neon-glow-playback-controls.swf"
			width="460"
			height="170">
	<param name="movie" value="http://www.flashexplained.com/img/menus/media/neon-glow-playback-controls.swf" />
</object><br />
<span id="more-813"></span></p>
<h3>Preliminary steps — setting the background</h3>
<p><span class="step">1</span> Open a new Flash document. Choose <strong>Modify &gt; Document</strong> (shortcut: <strong>Ctrl+J</strong>). Select <strong>black</strong> as document background  color. Click <strong>OK</strong>.</p>
<p><span class="step">2</span> Select the Rectangle tool <strong>(R)</strong>. <strong>Turn off the stroke color</strong> by clicking on the little pencil icon and then the small red-striped square at the bottom of the Tools panel: <img src="http://www.flashexplained.com/img/menus/gn/gn_001.gif" alt="The outline (stroke) color has been blocked." width="38" height="18" />.</p>
<p><span class="step">3</span> Make sure that both the <strong>Object drawing</strong> and <strong>Snap to objects</strong> options are turned off: <img src="http://www.flashexplained.com/img/menus/gn/gn_002.gif" alt="The icons that manage the object drawing and snapping to objects." width="37" height="18" />.</p>
<p><span class="step">4</span> Click the <strong>Set Corner Radius</strong> icon (<img src="http://www.flashexplained.com/img/menus/gn/gn_003.gif" alt="Setting the corner radius for the rectangle tool." width="18" height="18" />) and enter <strong>6</strong> in the window that will show up, click <strong>OK</strong>. This is done in order to have rectangles with round corners.</p>
<p><span class="step">5</span> Draw a flat color (any color will do) <strong>410 by 120 pixel</strong> rectangle.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_004.gif" alt="An elongated rectangle with rounded corners." width="431" height="138" /></p>
<p><span class="step">6</span> Select the Paint Bucket tool <strong>(K)</strong>. Go to the <strong>Color Mixer</strong> panel (opened by default — you can always find it in the top right part of the Flash working space). Do the following (see numbers in the screenshot below):</p>
<ol>
<li>Click on the <strong>paint bucket</strong> icon to select the fill color.</li>
<li>In the <strong>Type</strong> menu, select <strong>Linear</strong>.</li>
<li>Click <strong>once</strong> on the small colored square found on the bottom right.</li>
<li>In the <strong>color code</strong> field, enter the hex code <strong>#2E70AA</strong> (that&#8217;s a zero, not the letter O).</li>
<li>Set the <strong>Alpha</strong> property for this color to <strong>34%</strong>.</li>
<li>Set the same color for the <strong>left square</strong>, but set its <strong>Alpha</strong> to <strong>100%</strong>.</li>
</ol>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_005.gif" alt="Creating a linear gradient." width="213" height="112" /></p>
<p><span class="step">7</span> Press and <strong>hold Shift</strong>, <strong>click</strong> near the rectangle&#8217;s top and drag your mouse down until the rectangle&#8217;s bottom. Release your mouse button, and there is your nice gradient!</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_006.gif" alt="Filling the rectangle with the linear gradient." width="431" height="138" /></p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_007.gif" alt="The rectangle is filled with the nice blue gradient." width="431" height="138" /></p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>Creating the glowing outer ring</h3>
<p><span class="step">8</span> Lock the current layer and call it <em>background</em>. Create a new layer and call it <em> buttons</em>.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_008.gif" alt="A new layer on the scene in Flash." width="216" height="64" /></p>
<p><span class="step">9</span> Select the Oval tool <strong>(O)</strong>. Go to the Property inspector and make the following selections: <strong>block</strong> the <strong>fill</strong> color, select any <strong> flat</strong> color for the <strong>stroke</strong> (outline) color, set the line type  to <strong>Solid</strong> and choose <strong>3</strong> for <strong>line thickness</strong>.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_009.gif" alt="Selecting the options of the Oval tool." width="296" height="57" /></p>
<p><span class="step">10</span> Somewhere over the rectangle, draw a ring (it is a circle, but because of the line thickness and lack of fill, it looks like a ring). Make it <strong>70 by 70 pixels</strong>.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_010.gif" alt="The ring-circle drawn on stage." width="88" height="88" /></p>
<p><span class="step">11</span> <strong>Select the ring</strong> by clicking on it with the Selection tool <strong>(V)</strong>, if it isn&#8217;t already selected. Go to the <strong>Color Mixel</strong> panel and click on the <strong>pencil icon</strong> to select the <strong>Stroke color</strong> (<img src="http://www.flashexplained.com/img/menus/gn/gn_011.gif" alt="The Stroke color icon." width="12" height="12" />). In the <strong>Type</strong> menu, choose <strong>Linear</strong> exactly like you did for the fill color previously. Add <strong>two more color squares</strong> to the gradient by simply clicking anywhere between the two existing ones. You should have <strong>four</strong> of them in total, with the following color values, positioned like this:</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_012.gif" alt="The linear gradient for the ring." width="200" height="62" /></p>
<p>Note: all the four squares should have their alpha set to 100% (complete opaqueness). The ring will now look like this:</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_013.gif" alt="The outline ring colored with a linear gradient." width="90" height="90" /></p>
<p>I have hidden the <em>background</em> layer to work more easily and so that you can more clearly see the various steps.</p>
<p><span class="step">12</span> Select the Gradient Transform tool <strong>(F)</strong>. Click on the ring to select it. <strong>Rotate</strong> the gradient by <strong>90°</strong>. To successfully do this, make sure that Snapping to Objects is turned on (<strong>View &gt; Snapping &gt; Snap to Objects</strong>). Then, press and hold <strong>Shift</strong>, click on the white circle handle and start moving your mouse clockwise.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_014.gif" alt="Rotating the outline gradient." width="226" height="108" /></p>
<p><span class="step">13</span> While the ring is selected, press <strong>F8</strong> (or select <strong>Modify &gt; Convert to Symbol</strong>)  to make a symbol out of it. Name it <em>outer ring</em>. Select <strong>Movie clip</strong> as type and be sure to select the <strong>registration</strong> point in the middle (see screenshot below):</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_015.gif" alt="Converting a drawn shape into a symbol." width="273" height="118" /></p>
<p>Click <strong>OK</strong>. This choice for the registration point will make it easier to align the elements inside the button later.</p>
<p><span class="step">14</span> Click on the <strong>Filters</strong> tab in the Properties panel (see no. <strong>1</strong> in screenshot below). Click on the plus icon <strong>(2)</strong> and select the <strong>Glow</strong> filter. Make the adjustements as follows:</p>
<ol>
<li><strong>Blur X and Y</strong>: 8</li>
<li><strong>Strength</strong>: 260%</li>
<li><strong>Quality</strong>: High.</li>
<li><strong>Color</strong>: #ADE2FC.</li>
</ol>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_016.gif" alt="The glow filter and its options in Flash." width="377" height="132" /></p>
<p>Leave the <strong>Knockout</strong> and <strong>Inner glow</strong> options unchecked. You will get a nice glow for your outer ring:</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_017.gif" alt="The glowing outer ring made in Flash." width="102" height="102" /></p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>Making the main button circle</h3>
<p><span class="step">15</span> Select the ring again and press <strong>F8</strong> again, while leaving the same registration point as previously and Movie clip as type of symbol. Call the new symbol <em>play button</em> and click OK.</p>
<p><span class="step">16</span> <strong>Double-click</strong> on the newly made <em>play button</em> symbol to enter inside it. Call the first layer <em>outer ring</em> and <strong>lock</strong> it. That&#8217;s where the ring that you have just created resides. Make <strong>a new layer</strong> above it and call it <em>circle</em>.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_018.gif" alt="A new layer inside the play button symbol." width="245" height="93" /></p>
<p><span class="step">17</span> Select the Oval tool <strong>(O)</strong> again. Go down to the Properties panel. Set <strong> #B0E2FD</strong> for the outline color and <strong>#3A5274</strong> for the fill color. Select <strong>Solid</strong> as line type and a thickness of <strong>2</strong>.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_019.gif" alt="The circle's properties defined in the Properties panel." width="298" height="50" /></p>
<p><span class="step">18</span> Draw a <strong>54 by 54 pixel</strong> circle on the stage, anywhere.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_020.gif" alt="The new circle made on the stage in Flash." width="70" height="70" /></p>
<p><span class="step">19</span> <strong>Select</strong> the circle (<strong>both</strong> the outline and the fill). Open the <strong>Align panel</strong> by selecting <strong>Window &gt; Align</strong>. Turn <strong>on</strong> the <strong>To stage</strong> button <strong>(1)</strong>. Click the align <strong>horizontal</strong> center <strong>(2)</strong> and align <strong>vertical</strong> center <strong>(3)</strong> buttons.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_021.gif" alt="Aligning the circle to the movie clip's middle center point." width="206" height="130" /></p>
<p>The circle will now be perfectly aligned with the <em>play button</em> movie clip&#8217;s registration point and also with the ring below it.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_022.gif" alt="The circle centered exactly on the center of the play button." width="90" height="90" /></p>
<p><span class="step">20</span> Choose the Selection tool <strong>(V)</strong> and click on the <strong>fill</strong> of the circle <strong>once</strong> to select it. Press <strong>Ctrl+C</strong> to copy it.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_023.gif" alt="Selecting a vector fill shape." width="90" height="90" /></p>
<p><span class="step">21</span> <strong>Lock</strong> the current layer and call it <em>circle</em>. Make a new layer above it and call it <em> circle overlay</em>.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_024.gif" alt="The third layer inside the movie clip." width="214" height="83" /></p>
<p><span class="step">22</span> Select <strong>Edit &gt; Paste in Place</strong> to paste the circle you copied two steps earlier  exactly on the same position, but inside this new layer.</p>
<p><span class="step">23</span> The copy of the circle fill will be selected by default after pasting. Go to the <strong>Color Mixer</strong> panel. Click on the <strong>paint bucket</strong> icon to select the fill color. In the <strong>Type</strong> menu, select <strong>Linear</strong>. Make the following gradient:</p>
<ul>
<li>You should have  <strong>three</strong> color squares, one in the middle and one on each end of the gradient.</li>
<li>Each square&#8217;s color should be <strong>white</strong>.</li>
<li>The <strong>alpha</strong> factor of squares on each end should be <strong>41%</strong>. The middle one&#8217;s should be set to <strong>3%</strong>.</li>
</ul>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_025.gif" alt="A new gradient for the circle overlay." width="201" height="62" /></p>
<p><span class="step">24</span> Use the Gradient Transform tool <strong>(F)</strong> to <strong>rotate the gradient by 90°</strong>, just like before. The final result should look like this:</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_026.gif" alt="The circle's overlay gives a nice shiny effect." width="90" height="90" /></p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>Creating the play icon</h3>
<p><span class="step">25</span> Lock the <em>circle overlay</em> layer, make a new layer above it and call it <em>icon</em>.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_027.gif" alt="The icon layer will be host to the play icon." width="219" height="103" /></p>
<p><span class="step">26</span> Select the Rectangle tool <strong>(R)</strong>. <strong>Block</strong> the stroke color. Set the fill color to <strong>#3A5274</strong>. Draw a <strong>33 by 33 pixel</strong>square anywhere on the stage.</p>
<p><span class="step">27</span> Turn on the <strong>Snap to Objects</strong> option and use the Selection tool <strong>(V)</strong> to create a triangle out of the rectangle. Do it like this (follow the image sequence below):</p>
<ol>
<li>Bring the cursor close to the square&#8217;s <strong>upper right</strong> corner.</li>
<li><strong>Click</strong> and start <strong>dragging down</strong>, until you reach the middle of square&#8217;s height. <strong>Release</strong> your mouse button.</li>
<li>Repeat the same thing for the <strong>lower right</strong> corner of the square, this time dragging the corner <strong>towards the point</strong> you just made in the previous move. Once near, the corner will snap into place. Release the mouse and there is your triangle.</li>
</ol>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_028.gif" alt="Making a triangle out of a square in Flash." width="251" height="46" /></p>
<p><span class="step">28</span> <strong>Click</strong> on the triangle to <strong>select</strong> it. Go to the Property inspector and type <strong>27</strong> in the <strong>W</strong> (width) field. There! You have a good-looking play button now. The screenshots below show the difference in size before and after the width of the triangle was modified.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_029.gif" alt="Reducing the width of a vector shape." width="254" height="51" /></p>
<p><span class="step">29</span> Center the triangle inside the button.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_030.gif" alt="The play icon is centered inside the button now." width="90" height="90" /></p>
<p><span class="step">30</span> Select the Ink bottle tool <strong>(S)</strong>. In the Properties panel, choose <strong>Solid</strong> as type and set the thickness to <strong>4</strong>. Click anywhere on the triangle to give it an outline.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_031.gif" alt="A border was added to the triangle." width="200" height="90" /></p>
<p><span class="step">31</span> Choose the Selection tool <strong>(V)</strong>. <strong>Double-click</strong> on the triangle&#8217;s border to select it.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_032.gif" alt="Selecting the outline of the triangle." width="90" height="90" /></p>
<p><span class="step">32</span> Press <strong>Ctrl+X</strong> to cut the outline.</p>
<p><span class="step">33</span> <strong>Lock</strong> the <em>icon</em> layer. Make a new layer <strong>below</strong> it and call it <em>icon outline</em>.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_033.gif" alt="The icon outline layer is inserted." width="219" height="123" /></p>
<p><span class="step">34</span> Select <strong>Edit &gt; Paste in Place</strong> to place the icon border here, right below the icon itself.</p>
<p><span class="step">35</span> <strong>Lock</strong> the <em>icon outline</em> layer and <strong>unlock</strong> the <em>icon</em> layer. <strong>Select</strong> the triangle inside it.</p>
<p><span class="step">36</span> Hit <strong>F8</strong> to convert it into a symbol. Call it <em>play icon</em> and click <strong>OK</strong>.</p>
<p><span class="step">37</span> The new <em>play icon</em> movie clip will be selected by default. Go to the Properties panel and click on the <strong>Filters</strong> tab to set the blending options for this symbol. Choose the <strong>Glow</strong> filter and tweak it like this:</p>
<ol>
<li><strong>Blur X and Y</strong>: 6</li>
<li><strong>Strength</strong>: 240%</li>
<li><strong>Quality</strong>: Medium</li>
<li><strong>Color</strong>: #ACE0FD</li>
<li><strong>Inner glow</strong> must be turned <strong>on</strong>.</li>
</ol>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_034.gif" alt="The glow for the play icon and its parameters." width="368" height="109" /></p>
<p>And — ta-daa — here&#8217;s the final result, with the background:</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_035.jpg" alt="The glowing neon blue play button is complete now." width="120" height="120" /></p>
<p>Now ain&#8217;t it cool? This blue neon glow looks soooo good :-)! Let me show you now how to easily duplicate theis button and create a stop button out of it.</p>
<p class="backtotop"><a href="#container">Top of page</a></p>
<h3>Creating the glowing stop button from the play button</h3>
<p><span class="step">38</span> Go back to the main scene by clicking on the <strong>Scene 1</strong> link.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_036.gif" alt="Back to the main scene in Flash." width="217" height="40" /></p>
<p><span class="step">39</span> Open the Library by selecting <strong>Window &gt; Library</strong>.</p>
<p><span class="step">40</span> <strong>Right-click</strong> on the <em>play button</em> in the Library and select <strong>Duplicate</strong> from the pop-up menu. The Duplicate Symbol window ill appear. Just change the symbol&#8217;s name to <em>stop button</em> and click <strong>OK</strong>.</p>
<p>Repeat the same thing with the <em>play icon</em> symbol: <strong>duplicate</strong> it and call the new symbol <em>stop icon</em>. You will have fice symbols (all of them movie clips) in the Library now: the <em>outer ring</em> which is present in both the <em>play button</em> and <em>stop button</em> symbols, as well as <em>play icon</em> and <em>stop icon</em> for each respective symbol. Let me show you now how to make the modifications.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_037.gif" alt="The Library in Flash with its symbols." width="192" height="119" /></p>
<p><span class="step">41</span> <strong>Double-click</strong> on the <em>stop button</em> symbol inside the Library to enter inside it. <strong>Unlock</strong> its <em>icon</em> layer.</p>
<p><span class="step">42</span> Click <strong>once</strong> on the <em>play icon</em> that is inside it, to select it.</p>
<p><span class="step">43</span> Go to the Properties panel  and click the <strong>Swap</strong> button.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_038.gif" alt="The button for swapping symbols in Flash." width="128" height="45" /></p>
<p><span class="step">44</span> The Swap Symbol window will show up. All the symbols that you made in your Flash document so far are displayed here — exactly as they appear in the Library. <strong>Select</strong> the <em>stop icon</em> symbol and click <strong>OK</strong>.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_039.gif" alt="Swapping symbols in Flash!" width="199" height="141" /></p>
<p>Although this movie clip symbol looks exactly the same as the <em>play icon</em>, you know that this is the <em>stop icon</em> in fact. Flash informs you of this by displaying the name of the currently selected symbol in the Properties panel:</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_040.gif" alt="The name of the symbol as seen in Flash." width="129" height="17" /></p>
<p><span class="step">45</span> Now, <strong>double-click</strong> the <em>stop icon</em> movie clip on the stage to enter inside it. <strong>Erase</strong> the triangle and draw a <strong>28 by 28 pixel</strong> borderless square in its place. I have made the square smaller, because if it had the dimensions of the triangle, it would come too close to the circle&#8217;s border and that wouldn&#8217;t look so good. Oh, yes: the color of the square should be the same as triangle&#8217;s: <strong>#3A5274</strong>.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_041.jpg" alt="The square inside the stop neon button." width="90" height="90" /></p>
<p><span class="step">46</span> Click on the <em>stop button</em> link to go back to the movie clip&#8217;s timeline.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_042.gif" alt="Back to the button's timeline." width="231" height="41" /></p>
<p><span class="step">47</span> Align the icon in relation to the movie clip&#8217;s center.</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_043.jpg" alt="The new stop icon aligned inside the movie clip symbol." width="90" height="90" /></p>
<p><span class="step">48</span> <strong>Lock</strong> the <em>icon</em> layer. <strong>Unlock</strong> the <em>icon outline</em> layer. <strong>Erase</strong> the outline triangle that is inside it.</p>
<p><span class="step">49</span> Draw a rectangle here, <strong>without a fill</strong>, and make it the same size as the icon above it: <strong>28 by 28 pixels</strong>. the line should have the same thickness as before (<strong>4</strong>) and the same color (<strong>#3A5274</strong>). <strong>Align</strong> it like you did with the icon. It should look like this:</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_044.jpg" alt="The modification is finished: here is the new stop icon." width="90" height="90" /></p>
<p>And finally, here are both the play and stop neon glow buttons, side by side:</p>
<p><img src="http://www.flashexplained.com/img/menus/gn/gn_045.jpg" alt="The glow neon buttons done entirely in Flash!" width="224" height="120" /></p>
<p>They look awesome! And there was no need at all to use Photoshop! The pause, fast forward and rewind buttons can be made easily now — you know now the easy principle of duplicating symbols. Just make smaller triangles for the rewind button and make two rectangles for the pause button. Nothing easier than that.</p>
<p>A single button that you just made has a file size of only <strong>439 bytes</strong>! The same button made in Photoshop would have a file size ten times bigger than the one made in Flash! Still, it is much easier to create a <a href="http://www.tutorialhero.com/tutorial-1-simple_neon_text_effect.php">neon effect in Photoshop</a> than it is in Flash.</p>
<p>Hope you liked this tutorial. Take a look at other <a href="/category/menus-interfaces/">Flash tutorials on menus, buttons and interfaces</a> that I made — you will find a lot to learn. Besides the design, these tutorials also explain how to make complete website navigation systems, so don&#8217;t miss them!</p>
<p><a href="http://www.flashexplained.com/img/menus/materials/neon-glow-playback-controls.zip">Download the source file for this lesson</a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashexplained.com/menus-interfaces/glowing-neon-playback-control-buttons/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
