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

<channel>
	<title>Activetuts+ &#187; S.E.O.</title>
	<atom:link href="http://active.tutsplus.com/category/tutorials/seo/feed/" rel="self" type="application/rss+xml" />
	<link>http://active.tutsplus.com</link>
	<description>Flash, Flex &#38; ActionScript Tutorials</description>
	<lastBuildDate>Fri, 12 Mar 2010 17:01:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Quick Tip: How to use Google Analytics for Tracking in Flash</title>
		<link>http://active.tutsplus.com/tutorials/seo/quick-tip-how-to-use-google-analytics-for-tracking-in-flash/</link>
		<comments>http://active.tutsplus.com/tutorials/seo/quick-tip-how-to-use-google-analytics-for-tracking-in-flash/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 12:00:47 +0000</pubDate>
		<dc:creator>Peter Eeckelaert</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[S.E.O.]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=3331</guid>
		<description><![CDATA[In this Quick Tip I&#8217;ll show you how to examine the way visitors are using your websites, widgets and games. Then we&#8217;ll look at how to improve them based on this info!


Introduction
Building nice looking websites is great; building websites that have a high Return Of Investment is priceless. 

Recently I joined the web team of [...]]]></description>
			<content:encoded><![CDATA[<p>In this Quick Tip I&#8217;ll show you how to examine the way visitors are using your websites, widgets and games. Then we&#8217;ll look at how to improve them based on this info!</p>
<p><span id="more-3331"></span></p>
<hr/>
<h2>Introduction</h2>
<p>Building nice looking websites is great; building websites that have a high Return Of Investment is priceless. </p>
<p>
Recently I joined the web team of a Brussels based communication agency, a team with expert knowledge in the fields of user experience design, content strategies, software development, and interaction design. We spend a lot of time on wireframes, storyboards, and prototypes, which guarantees that the functionality and the content of the websites are optimal before <em>any</em> graphical design takes place. This means our websites have a solid base to be built upon, which results in a higher ROI with less time spent on development.</p>
<p>A huge part of our work is under the hood: Google Analytics inside Flash.</p>
<p>This tool allows us to measure how well our sites are doing against our predefined goals: bounce rate, click paths and even custom measurements like how many people scrolled a certain page. Our specialists analyze all this information and use it to optimize the website. If you&#8217;re not measuring how people are using your site, you can only guess about its successes and failures.</p>
<p>The following setup is a stripped-down version of an image gallery; Google Analytics allowed the client to discover which images triggered the most interest. I&#8217;ve left out the actual gallery building as it is beyond the scope of this tutorial; there are plenty on Activetuts+ already though &#8211; <a href="http://active.tutsplus.com/?s=gallery">just search for &#8220;gallery&#8221;</a>.</p>
<p>We will focus on how to set up Google Analytics to put a smile on your clients&#8217; faces (and probably yours too&#8230;)</p>
<hr/>
<h2>Google Analytics in Action</h2>
<p>Here&#8217;s the simplified image gallery:</p>
<div class="tutorial_image">
<object width="550" height="400" data="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Preview/google_analytics_example.swf" type="application/x-shockwave-flash"><param name="src" value="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Preview/google_analytics_example.swf" /></object>
</div>
<p>As you can see, when an image is clicked, its identity gets sent over to my Google Analytics account. Later on, I can look at all the statistics of which images were clicked, at which times, in which countries, and so on.</p>
<p>(Of course, you&#8217;ll remove all that overlaid information when it&#8217;s live on your own site!)</p>
<hr/>
<h2><span>Step 1:</span> Understand the Benefits</h2>
<p>Imagine yourself working hours, weeks, even months on a website. You successfully deliver the files before the deadline, but a few months later it&#8217;s clear that &#8211; despite being beautiful &#8211; the site is not attracting as many customers as your client expected. Google Analytics helps you to review visitors&#8217; browsing habits and discover which parts of the site could be better highlighted. Beauty is great, but I believe that Return Of Investment should be your main priority.</p>
<p>In another scenario this same tool helps you to understand what area of your website has the most page views, how many times visitors wanted to contact you, or which elements of your portfolio visitors love the most. How many benefits can you think of for your site?</p>
<hr/>
<h2><span>Step 2:</span> Set Up a Google Analytics Account</h2>
<p>If you don&#8217;t have a Google account already, sign up for one <a href="https://www.google.com/accounts/NewAccount">here</a> &#8211; it only takes a few seconds.</p>
<p>Once that&#8217;s done, head to <a href="http://google.com/analytics">http://google.com/analytics</a> and sign up for an Analytics account. There you can give an account name for the websites you want to track.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/1.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<hr/>
<h2><span>Step 3:</span> Inside the Machine</h2>
<p>Head to <a href="https://google.com/accounts/ManageAccount" target="_blank">https://google.com/accounts/ManageAccount</a><br />
and use your mouse skills to click Analytics.</p>
<p>Great, we are now in the Overview page. You should see your Analytics account name; click it and you&#8217;ll find yourself at the website profiles.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/2.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<p>If you haven&#8217;t set up a website to track, simply click &#8216;Add Website Profile&#8217;. Enter your domain name and Country, then click Finish.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/3.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/4.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/5.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<hr/>
<h2><span>Step 4:</span> Retrieve your UA Code and Tracking Status</h2>
<p>The Tracking Status page will automatically appear:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/6.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<p>The most important part is your web property ID. This is a unique number Google Analytics will use to send and store your website&#8217;s traffic. (Copy this UA code for use later in Flash, or write it down.) For this introduction we&#8217;ll simply keep all the options at their defaults.</p>
<p>If you&#8217;re going to embed your SWF on your own webpage, the javascript code must be pasted right before the &lt;/body&gt; tag in the page&#8217;s HTML. This will allow you to keep statistics for the actual page itself, as well as for within the SWF. It&#8217;s worth inserting this code in every page on your site.</p>
<p>All this is great, but you still won&#8217;t be able to pinpoint your visitors&#8217; interaction in great detail, as the HTML is blind to your actual SWF / Flash content.</p>
<hr/>
<h2><span>Step 5:</span> Gathering Wood</h2>
<p>To make sure you can see which parts of your SWF are being used, head to <a href="http://code.google.com/p/gaforflash/" target="_blank">http://code.google.com/p/gaforflash/</a>.</p>
<p>This amazing open source AS3 API has a lot of great features for integrating GA into Flash, but even with our biggest and most complex websites, we&#8217;ve only ever used two functions. (More about these later on.) Make sure you download the latest installment on the right of the page. (Come back any time to read the wiki, issues etc, to learn more about this vast API.)</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/7.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<hr/>
<h2><span>Step 6:</span> Install the Components</h2>
<p>The zip contains a documentation folder with the entire API layout to help you along the way; a library folder (lib) where you&#8217;ll find the two components; and some text files you probably won&#8217;t ever read. At least I didn&#8217;t ;]</p>
<p>To install the components, make sure Flash is closed, then navigate to:</p>
<ul>
<li>Windows users: <em>C:\Program Files\Adobe\Adobe Flash CS X\language\Configuration\Components</em></li>
<li>Mac users: <em>Macintosh HD/Applications/Adobe Flash CS X/Configuration/Components</em></li>
</ul>
<p>At this point you need to create a directory named &#8216;Google&#8217; and copy the files from the \lib\ folder in the zip to it.</p>
<p>Basically the two components give you the same functionality but are developed for two different purposes. The Analytics component is for those who are unfamiliar with AS3. I assume most of you are already using AS3, so we&#8217;ll use the AnalyticsLibrary component.</p>
<hr/>
<h2><span>Step 7:</span> Feeding the Fire</h2>
<p>Inside Flash, open the FLA for the project you&#8217;re working on, click <em>Window > Components</em>, and drag the AnalyticsLibrary component to your library.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/8.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<hr/>
<h2><span>Step 8:</span> Action! (Script)</h2>
<p>Whether you&#8217;re coding on the timeline or using a document class, you&#8217;ll need to do some imports:</p>
<pre name="code" class="javascript">
//import the Analytics classes
import com.google.analytics.AnalyticsTracker;
import com.google.analytics.GATracker;
</pre>
<p>Also, in your code, create a new instance of the AnalyticsTracker:</p>
<pre name="code" class="javascript">
var tracker:AnalyticsTracker = new GATracker( this, "UA-XXXXXX", "AS3", true );
</pre>
<p>The parameters are: stage, UA code, actionscript 3 mode, visual debugger on/off. Leave them all as I&#8217;ve set them, apart from the UA code which you&#8217;ll need to swap for your own. Set the last parameter to <em>false</em> when you are done with your testing phases, as when <em>true</em> it will create an overlay on top of your SWF file like in the example above.</p>
<p>Test this out by adding a Click event listener and handler to one of your movie clips or buttons:</p>
<pre name="code" class="javascript">
myMc.addEventListener (MouseEvent.CLICK,onClick);
</pre>
<pre name="code" class="javascript">
function onClick (event:MouseEvent):void
{
	//make your clients happy.
    //use 'event.target.name' instead of 'event.target'
	//this will display 'myMc' instead of [object myMc], which is obviously a nicer output.
	var mySelection:String = event.target.name;
	tracker.trackPageview ("gallery = " + mySelection);
}
</pre>
<p>Here we&#8217;re using the <em>trackPageView()</em> function. Use this for navigation purposes. You can add a string so your client knows what part is being tracked. In this case we&#8217;re tracking which gallery has been triggered. So copy and paste this code everywhere you want to track your interactions and give an understandable String to the data.</p>
<p>For example, if you have a &#8220;call to action&#8221; button on stage to lure potential new clients, you could write:</p>
<pre name="code" class="javascript">
tracker.trackPageview("Hire me");
</pre>
<p>&#8230;in the Click event handler for that button. Or if you want to track how many times they have read your disclaimer:</p>
<pre name="code" class="javascript">
tracker.trackPageview("Disclaimer");
</pre>
<p>I&#8217;m sure you get the idea.</p>
<hr/>
<h2><span>Step 9:</span> Event Tracking</h2>
<p>Use event tracking if you want to track what video or MP3 event is being played, or when the user pauses it &#8211; things like that. It&#8217;s basically for any action that doesn&#8217;t represent opening a &#8220;page&#8221;.</p>
<p>The code looks like this:</p>
<pre name="code" class="javascript">
trackEvent(category, action, label);
</pre>
<p>For example:</p>
<pre name="code" class="javascript">
tracker.trackEvent("profile videos", "play", "first video: introduction");
</pre>
<p>Additionally you can add a fourth parameter. This can represent any value you like, but it must be an integer (whole number). For example, you might want to pinpoint the exact time when the video was paused.</p>
<p>This is great to see how well your streaming or downloading performs for your visitors (not everyone has top class Internet connections):</p>
<pre name="code" class="javascript">
var currentTime:Date = new Date().time;	//get the current time
//load the video here
var readyToRoll:Date = new Date().time - currentTime;	//get time taken to load the video
tracker.trackEvent("profile videos", "playing the video", "video 1/3: introduction", readyToRoll);
</pre>
<hr/>
<h2><span>Step 10:</span> See the Data in Google Analytics</h2>
<p>Go to <a href="http://google.com/analytics/settings/">http://google.com/analytics/settings/</a> and click your account name. Next to your domain name, click View Report.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/9.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<p>Here you will see a timeline. (Please note: depending on your server response time it can take a while before the data gets stored, but it shouldn&#8217;t take too long.) Select the dates for when you have been testing using the calendar in the top-right:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/10.jpg" alt="google-analytics-for-flash" width="600" height="253" /></div>
<p>Locate the Content Overview; here you can see which events or buttons were triggered:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/11.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<p>As you can see, as I explained a few steps back, <em>event.target.name</em> displays a &#8220;nice&#8221; name like &#8220;/gallery = gallery 1&#8243;, while <em>event.target</em> returns something like &#8220;[object picture1]&#8220;</p>
<p> Clicking on one of these links &#8211; for example, &#8220;/gallery = gallery2&#8243; &#8211; you will be able to see in-depth information, like what screen resolution your users have, when you choose an option in the drop-down menu.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/12.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<p>There&#8217;s a deep and rich information source in nearly every single branch of the Google Analytics module. It&#8217;s nearly impossible to list all of them. Don&#8217;t be afraid; look around and see what data you can provide to your clients and yourself.</p>
<hr/>
<h2><span>Step 11:</span> Eliminate Yourself from the Stats using Filters</h2>
<p>It&#8217;s a good idea to filter out your own behaviour; otherwise, it will give you incorrect data since you will probably test this in great detail.</p>
<p>You can do this by filtering all activity coming from your IP address &#8211; though please note, this will only work if you have a static IP address. There is a lot of documentation in the help files; I can&#8217;t cover it all here. Check out <a href="http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&#038;answer=55481">http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&#038;answer=55481</a></p>
<p>Filters can also be useful for other reasons. Here is some more information: <a href="http://www.google.com/support/googleanalytics/bin/topic.py?hl=en&#038;topic=11091">http://www.google.com/support/googleanalytics/bin/topic.py?hl=en&#038;topic=11091</a></p>
<hr/>
<h2><span>Step 12:</span> The End is the Beginning&#8230;</h2>
<p>In this Quick Tip I&#8217;ve only covered a snowflake on the tip of the iceberg of what you can do with this amazing API. It&#8217;s a quick overview on the two most beneficial functions that we deal with to improve our websites and match our clients&#8217; wishes.</p>
<p>You can also set predefined goals, group users that (for example) use widescreen monitors, base your Analytics on search engine keywords and so on. For your clients, you can send an email with daily, weekly or monthly reports (as xml, PDF, or other formats), or even give them access to your Analytics page. If you&#8217;d like more information, please ask in the comments!</p>
<hr/>
<h2>My Opinions on Search Engine Friendly Flash Websites</h2>
<p>Although it is beneficial to read and trace your visitors&#8217; interactions, this is a long way from using Flash in an SEO-friendly world. I&#8217;ve warmed you up for optimal website design and focusing on Return of Investment, but we&#8217;re not there yet.</p>
<p>A good next step would be to look into the <a href="http://www.gaiaflashframework.com/">Gaia framework</a>, and use its mighty setup to work with swfaddress and deeplinking. This will allow you to track individual pages of your website project and in combination with your newly learned Google Analytics magic, I am sure not only your clients will smile.</p>
<p><strong>Editor&#8217;s Note:</strong> We have some Gaia tutorials lined up, don&#8217;t worry <img src='http://active.tutsplus.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I&#8217;ve been working for over 10 years in the graphic design world, and never had so much power to know exactly what my clients and visitors want. I often like to call it &#8220;free marketing and research from your desktop&#8221;. (If you are wondering why my own site isn&#8217;t using this technology, well honestly&#8230; I hope to re-launch by mid 2010 *sips coffee*)</p>
<p>I hope this opens new doors for you and boosts your skill set. Good luck and have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/seo/quick-tip-how-to-use-google-analytics-for-tracking-in-flash/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Build a Simple Website Template Using SWFAddress</title>
		<link>http://active.tutsplus.com/tutorials/seo/build-a-simple-website-template-using-swfaddress/</link>
		<comments>http://active.tutsplus.com/tutorials/seo/build-a-simple-website-template-using-swfaddress/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 12:00:20 +0000</pubDate>
		<dc:creator>George Kendros</dc:creator>
				<category><![CDATA[S.E.O.]]></category>

		<guid isPermaLink="false">http://flash.tutsplus.com/?p=791</guid>
		<description><![CDATA[<img src="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/preview.jpg" alt="">]]></description>
			<content:encoded><![CDATA[
<p>SWFAddress is a Javascript/ActionScript library which gives you the power to change the browser&#8217;s URL, add entries to its history list and fire off ActionScript events when the URL changes. It also allows search engines to find specific content in your site. This is all functionality which, according to its creators, is missing in today&#8217;s rich web technologies.</p>
<p>Let&#8217;s take a look..</p>
<p><span id="more-791"></span></p>
<div class="tutorial_image">
<a href="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/source_files.zip" target="_blank"><br />
<img src="http://flashtuts.s3.cdn.plus.org/source.jpg" alt="" style="border:none"></a><br />
<a href="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/preview/preview_html/index.html" target="_blank"><br />
<img src="http://flashtuts.s3.cdn.plus.org/demo.jpg" alt="" style="border:none"></a>
</div>
<h2>Background</h2>
<p>Before we jump right into the code, we&#8217;ll explore what SWFAddress is and how we need to adjust our work flow to use it. Essentially, SWFAddress is a javascript/ActionScript library which gives you the ability the change the browser&#8217;s URL, add entries to it&#8217;s history list and fire off ActionScript events when the browser changes its URL. SWFAddress will listen for specific browser events (URL changes) and signal its ActionScript counterpart to trigger certain events. The ActionScript class also gives us an easy to use API for controlling various browser actions (ie. changing the URL, changing the page title).</p>
<p>SWFAddress sites differ from some traditional sites because the navigation logic must be string based and it must have a central junction. It&#8217;s common for many flash based sites to have a unique function attached to every navigation element. For example, the first button may trigger a function showPage1() and the second could trigger a function showPage2() etc. In a SWFAddress page every navigation element will trigger the same function, namely the one that instructs SWFAddress to change the URL.</p>
<p>SWFAddress will also simultaneously trigger its change event at which point you will need to evaluate the current URL and decide what action to take. Once you get comfortable with this difference you&#8217;ll find that SWFAddress creates little resistance to your regular workflow. In fact, many developers already use a similar navigation architecture on their non-SWFAddress sites.</p>
<p>This tutorial will begin by building a basic page with 4 navigation elements. We&#8217;ll then introduce SWFAddress into the mix to give us some deeplinking support. Finally, for the advanced users, we&#8217;ll swap out our static menu/text and use an external XML file to supply the content.</p>
<h2>Step 1: Setting Up the Workspace</h2>
<p>Our SWFAddress powered website will consist of a few key files. We&#8217;ll need our main FLA, the SWF it compiles, an HTML page, the SWFAddress .as libraries, the SWFAddress .js libraries and the SWFObject libraries (the javascript libraries are in the swfaddress and swfobject folders).</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/tutorial/-1.jpg" alt="" /></div>
<h2>Step 2: The HTML File</h2>
<p>Our HTML page is a basic SWFObject dynamic embed with a line for SWFAddress. We won&#8217;t go too in depth into it since the HTML and js are beyond the scope of this tutorial. Suffice to say, the only differences between a typical SWFObject HTML template and this is the HTML on line #7 (see the line highlighted in blue).</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/tutorial/-2.jpg" alt="" /></div>
<h2>Step 3: Basic FLA Setup</h2>
<p>Now that the source files are in place we&#8217;ll start making our FLA. Create a new AS3 document, set its dimensions to 600 x 400px then save it to the project directory as &quot;tutorial.fla&quot;. We&#8217;ll also set the background color to #999999 so it looks less boring.</p>
<h2>Step 4: Menu Items Array</h2>
<p>For this tutorial we&#8217;re going to make an array to hold our menu items. This will make it easier to incorporate an XML based menu at a later date if you want. We&#8217;ll start by making a new layer on the timeline which we&#8217;ll call &quot;actions&quot;. We&#8217;ll then pull up the actions panel (with that layer selected) and use the following code:</p>
<pre name="code" class="javascript">
var menuArray:Array = new Array("Home", "About Us", "Services", "Contact Us");
</pre>
<p>It should look something like this:</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/tutorial/-3.jpg" alt="" /></div>
<h2>Step 5: Drawing the Menu Holder</h2>
<p>Now we&#8217;re going to start making the menu. We&#8217;ll make a new layer (call it &quot;menu&quot;) and begin by drawing a simple 400 x 50px rectangle with a 2px corner radius on the new layer. The color isn&#8217;t important because we&#8217;ll tweak it later.</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/tutorial/-4.jpg" alt="" /></div>
<h2>Step 6: Converting the Menu to a Movie Clip</h2>
<p>Now we&#8217;ll select the menu and press F8 to convert it to a movie clip. We&#8217;ll give it a library identifier of &quot;menu&quot; and an instance name of &quot;menuHolder&quot;.</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/tutorial/-5.jpg" alt="" /></div>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/tutorial/-6.jpg" alt="" /></div>
<h2>Step 7: Making the Menu Background</h2>
<p>Double-click on the newly created menu movie clip to enter its edit mode. We&#8217;ll select the shape inside and again convert it to a movieclip (F8). This time however, we&#8217;ll be applying a 9 slice scaling grid to it. We do this so we can have a background for the menu that we can scale cleanly without having to scale the menu itself. We&#8217;ll give it a library and instance name of &quot;menubg&quot;.</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/tutorial/-7.jpg" alt="" /></div>
<p>I&#8217;ve also added a subtle blue glow to the menu using a glow filter with the blurx and blury set to 6, strength set to 50% and the color set to #32CCFF.</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/tutorial/-8.jpg" alt="" /></div>
<h2>Step 8: Drawing the Menu Items</h2>
<p>Now we&#8217;ll go back to the main document and begin creating the actual menu items (ie. the &quot;links&quot; that will populate the menu). Although we&#8217;re drawing these on the main document we could draw them anywhere as they&#8217;ll be dynamically added to the stage later. We&#8217;ll first create a textfield and set it to dynamic and give it an instance name of &quot;txt&quot;. We&#8217;ll set the font to Arial, the size at 22pts and the color to white #ffffff. Make sure the textfield is not selectable (the first button below the anti-alias drop down menu). Finally, we&#8217;ll embed the font. You can use any font you like, but you&#8217;ll need to remember to adjust the font size so that it fits the menu height wise.</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/tutorial/-9.jpg" alt="" /></div>
<h2>Step 9: Exporting Menu Items for ActionScript</h2>
<p>We&#8217;ll now convert the menu items to movie clips, but we&#8217;ll need to take an extra step since we&#8217;ll be re-using this movie clip in our ActionScript. Select the textfield and press F8 to bring up the movieclip dialog, input &quot;menuItem&quot; into the name field then select the &quot;Export for ActionScript&quot; check box. Once done click OK, then click OK again on the following confirmation dialog (it may not appear depending on your settings).</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/tutorial/-10.jpg" alt="" /></div>
<h2>Step 10: Creating the Menu Items (ActionScript)</h2>
<p>We&#8217;ll use the following code to populate the menu with the appropriate menu items:</p>
<pre name="code" class="javascript">
var xval = 20;

for (var i:int = 0; i&lt;menuArray.length; i++){
var clip = new menuItem
clip.txt.autoSize = 'left'
clip.txt.text = menuArray[i]
clip.x = xval
clip.y = (menuHolder.height/2) - (clip.height/2)
xval += clip.width + 30
menuHolder.addChild(clip);
}

menuHolder.menubg.width = menuHolder.width + 20;
menuHolder.x = (stage.stageWidth/2) - (menuHolder.width/2)
</pre>
<p>
Basically we&#8217;re looping through the elements of our array and for each element creating a new instance of menuItem. Then we&#8217;re setting the textfield inside menu item to &quot;autoSize = left&quot; so that it expands to fit the text that&#8217;s placed inside it. The next line sets the text inside the textfield according to the array element which corresponds with the current iteration of the loop. xval is a variable we use that stores the position of the menu item so we can place them beside each other. Then we center the menu Item within the menu and finally add the menu Item&#8217;s width and the padding value to xval. Next we add the menu item to the menuHolder. The last 2 lines of code make the menuHolder&#8217;s background stretch to fill the menu holder (we add 20px for padding) and center the menu on the stage.</p>
<h2>Step 11: Creating the Content Area</h2>
<p>Before we move on to assigning actions to the menu items and setting up SWFAddress, we&#8217;ll need to create some content to display. For the sake of simplicity we&#8217;ll use the default flash tweening engine. Create a new layer called content. On this layer create a rectangle measuring 500 x 250px and convert it to a movie clip with an instance name of &quot;content&quot;.</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/tutorial/-11.jpg" alt="" /></div>
<h2>Step 12: Adding Textfield to Content Area</h2>
<p>Now that we&#8217;ve created the content area we&#8217;ll double click it to enter edit mode and place a dynamic textfield on it. This textfield should be the almost as large as the &quot;content&quot; movie clip. We&#8217;ll use the same text settings as the menu (arial 22pt, white) with fonts embeded. We&#8217;ll give it an instance name of txt and change the behavior (under paragraph settings) to multi line.</p>
<div class="tutorial_image"><img src="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/tutorial/-12.jpg" alt="" /></div>
<h2>Step 13: Creating the content</h2>
<p>Now let&#8217;s create some content that we can populate the content area with when menu items are selected. For the sake of simplicity we&#8217;ll just create 4 different string variables, but in a more advanced site you would likely be replacing this with some external data source. Add the following 4 variables to our ActionScript code:</p>
<pre name="code" class="javascript">
var text1:String = "This is the text for the Home page"
var text2:String = "Here is the text that you would see on the About Us page"
var text3:String = "This page would feature the various services we provide"
var text4:String = "These are the various methods you can get in contact with us. You will also find a map here"
</pre>
<p>You can place these near the top of the code.</p>
<h2>Step 14: Making the Textfield&#8217;s Change Function</h2>
<p>We&#8217;ll now create a simple function that changes the textfield&#8217;s content and animates the transition. Paste in the following code then we&#8217;ll explore it line by line:</p>
<pre name="code" class="javascript">
import fl.transitions.Tween;
import fl.transitions.easing.*;
var cTween:Tween = new Tween(content, "x", Regular.easeOut, 50, 50, .1,true);
var mainText:String

function textChange(){
cTween.continueTo(-800, .4);
cTween.addEventListener("motionFinish", setText)
}

function setText(e:Event){
content.txt.text = mainText
cTween.continueTo(50,.4)
}
</pre>
<p>
The first 2 lines simply import the tween class and easing functions. The next line initializes the tween so we can more easily manipulate it with the continueTo function. The 4th line creates a variable which holds the current string, this variable will be set by SWFAddress and the content area will load this variable into its textfield whenever it&#8217;s tweening back into position. The textChange function tweens the content area off to the side and sets an event listener to trigger the setText function when it&#8217;s done. The setText function tweens the content area back on stage and sets its textfield to whatever mainText has been set to by SWFAddress.</p>
<h2>Step 15: Initializing SWFAddress</h2>
<p>To initialize SWFAddress we simply need to add its CHANGE event and create that event&#8217;s handler. These few lines of code will do it;</p>
<pre name="code" class="javascript">
SWFAddress.addEventListener(SWFAddressEvent.CHANGE, addressChange)

function addressChange(e:Event){
//stuff to do when address changes
}
</pre>
<p>The &quot;addressChange&quot; function will run every time the browser changes the URL (via back/forward buttons, re-writing the address bar URL or any other method) or you change the URL (via the SWFAddress.setValue function).</p>
<h2>Step 16: Adding Actions to the Menu Items</h2>
<p>Our next step is to add some behavior to the menu buttons we created earlier. We&#8217;ll be doing this by revisiting the menu creation loop we built earlier.</p>
<pre name="code" class="javascript">
var xval = 20

for (var i:int = 0; i&lt;menuArray.length; i++){
var clip = new menuItem
clip.txt.autoSize = 'left'
clip.txt.text = menuArray[i]
clip.x = xval
clip.y = (menuHolder.height/2) - (clip.height/2)
xval += clip.width + 30
menuHolder.addChild(clip);
clip.addEventListener('click', menuClicked)
}
</pre>
<p>The last line before the closing brace is the one we need to add. It creates an event on the menu items that fires when a menu item is clicked. We&#8217;ll now need to add the corresponding event handler.</p>
<pre name="code" class="javascript">
var xval = 20;

for (var i:int = 0; i&lt;menuArray.length; i++){
var clip = new menuItem
clip.txt.autoSize = 'left'
clip.txt.text = menuArray[i]
clip.x = xval
clip.y = (menuHolder.height/2) - (clip.height/2)
xval += clip.width + 30
menuHolder.addChild(clip);
clip.addEventListener('click', menuClicked)
}

function menuClicked(e:Event){
SWFAddress.setValue(e.currentTarget.txt.text)
}
</pre>
<p>The last three lines of code we added are executed every time a menu item is clicked. It instructs SWFAddress to execute its setValue function which changes the page and fires its CHANGE event handler. The parameter we&#8217;re passing to the setValue function is the text of the menu item that the user has clicked.</p>
<p>At this point, if we uploaded the files to our web server and tested the HTML file, we would have the address URL changing as we clicked the buttons but the file wouldn&#8217;t do anything as we haven&#8217;t told SWFAddress what to do when the address changes.</p>
<h2>Step 17: SWFAddress Actions</h2>
<p>We now have the menu set up and the menu buttons are properly triggering SWFAddress. The last part of the equation is to tell SWFAddress what to do when it&#8217;s triggered. Earlier in the tutorial (Step 15) we created the SWFAddress event listener and handler. We&#8217;ll revisit that block of code and add the following:</p>
<pre name="code" class="javascript">
SWFAddress.addEventListener(SWFAddressEvent.CHANGE, addressChange)

function addressChange(e:Event){

if(SWFAddress.getValue() == "/Home"){
mainText = text1
textChange()
}

if(SWFAddress.getValue() == "/About Us"){
mainText = text2
textChange()
}

if(SWFAddress.getValue() == "/Services"){
mainText = text3
textChange()
}

if(SWFAddress.getValue() == "/Contact Us"){
mainText = text4
textChange()
}

SWFAddress.setTitle(SWFAddress.getValue());
}
</pre>
<p>The key difference is all the code inside the &quot;addressChange&quot; function. We created several conditional statements that check what the current page is, set &quot;mainText&quot; to the appropriate text then launch the &quot;textChange&quot; function which is responsible for animating the transition and setting the text of the content area. The last line sets the page&#8217;s HTML title to the current page. This function could be cleaned up with a switch case, but for the sake of simplicity we&#8217;ll leave it as is.</p>
<h2>Step 18: All Done</h2>
<p>Your files should now match the ones in the <a href="http://flashtuts.s3.cdn.plus.org/034_SWFAddress/source_files.zip">source files</a>. Publish the FLA, upload the files to your server and you&#8217;ll now have a fully functional page.</p>
<h2>Conclusion</h2>
<p>We&#8217;ve now completed our simple SWFAddress powered page. This file should serve as a suitable base for any SWFAddress site and can easily be extended with dynamic content with minimal extra code. I hope you enjoyed following along!</p>
]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/seo/build-a-simple-website-template-using-swfaddress/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.200 seconds -->
